/* ═══════════════════════════════════════════════
   MyOpsisSync - Portal del Cliente Final
   Shared Styles
   ═══════════════════════════════════════════════ */

:root {
  --primary: #02735E;
  --primary-dark: #024d40;
  --primary-light: #e6f5f1;
  --accent: #0ea5e9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --info: #0ea5e9;
  --info-bg: #f0f9ff;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08);
  --topbar-h: 60px;
  --sidebar-w: 240px;
  --bottomnav-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── TOPBAR ─── */
.ms-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}

.ms-topbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-primary);
}

.ms-topbar-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 14px;
}

.ms-topbar-title {
  font-size: 16px; font-weight: 700; color: var(--text-primary);
}

.ms-topbar-title span { color: var(--primary); }

.ms-topbar-right {
  display: flex; align-items: center; gap: 12px;
}

.ms-topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
}

.ms-topbar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

.ms-topbar-notif {
  position: relative; background: none; border: none; padding: 6px;
  cursor: pointer; color: var(--text-tertiary); font-size: 18px;
}

.ms-topbar-notif .badge {
  position: absolute; top: 0; right: 0;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* ─── SIDEBAR (desktop) ─── */
.ms-sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w); background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 0; overflow-y: auto; z-index: 90;
}

.ms-sidebar-section {
  padding: 0 12px; margin-bottom: 8px;
}

.ms-sidebar-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-tertiary);
  padding: 8px 12px 4px;
}

.ms-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  text-decoration: none; transition: all .15s ease;
  cursor: pointer; border: none; background: none; width: 100%;
  text-align: left;
}

.ms-nav-item:hover { background: var(--border-light); color: var(--text-primary); }
.ms-nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.ms-nav-item i, .ms-nav-item svg { width: 18px; text-align: center; flex-shrink: 0; }

.ms-nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--danger); color: #fff; padding: 1px 7px;
  border-radius: 10px; min-width: 20px; text-align: center;
}

/* ─── MAIN CONTENT ─── */
.ms-main {
  margin-top: var(--topbar-h);
  margin-left: var(--sidebar-w);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-h));
}

/* ─── BOTTOM NAV (mobile) ─── */
.ms-bottomnav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottomnav-h);
  background: #fff; border-top: 1px solid var(--border);
  z-index: 100;
  justify-content: space-around; align-items: center;
  padding: 0 4px; padding-bottom: env(safe-area-inset-bottom, 0);
}

.ms-bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10px; font-weight: 500; color: var(--text-tertiary);
  text-decoration: none; padding: 6px 8px; border-radius: 8px;
  transition: color .15s;
  min-width: 52px;
}

.ms-bottomnav a.active { color: var(--primary); }
.ms-bottomnav a i { font-size: 18px; }

/* ─── PAGE HEADER ─── */
.ms-page-header {
  margin-bottom: 24px;
}

.ms-page-title {
  font-size: 22px; font-weight: 800; color: var(--text-primary);
  line-height: 1.2;
}

.ms-page-subtitle {
  font-size: 13px; color: var(--text-secondary); margin-top: 4px;
}

/* ─── CARDS ─── */
.ms-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.ms-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}

.ms-card-title {
  font-size: 14px; font-weight: 700; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}

.ms-card-title i { color: var(--primary); font-size: 16px; }

.ms-card-action {
  font-size: 12px; font-weight: 600; color: var(--primary);
  text-decoration: none; display: flex; align-items: center; gap: 4px;
  cursor: pointer; background: none; border: none; padding: 0;
}

.ms-card-action:hover { text-decoration: underline; }

/* ─── STAT CARDS ─── */
.ms-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 20px;
}

.ms-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.ms-stat-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--text-tertiary);
}

.ms-stat-value {
  font-size: 24px; font-weight: 800; color: var(--text-primary);
  margin-top: 4px; line-height: 1.1;
}

.ms-stat-sub {
  font-size: 11px; color: var(--text-secondary); margin-top: 4px;
}

/* ─── STATUS BADGES ─── */
.ms-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}

.ms-badge-success { background: var(--success-bg); color: #059669; }
.ms-badge-warning { background: var(--warning-bg); color: #d97706; }
.ms-badge-danger { background: var(--danger-bg); color: #dc2626; }
.ms-badge-info { background: var(--info-bg); color: #0284c7; }
.ms-badge-neutral { background: var(--border-light); color: var(--text-secondary); }

/* ─── PROGRESS BAR ─── */
.ms-progress {
  height: 10px; background: #e5e7eb; border-radius: 5px; overflow: hidden;
}

.ms-progress-fill {
  height: 100%; border-radius: 5px; transition: width .6s ease;
  background: linear-gradient(90deg, var(--primary), #10b981);
}

/* ─── TABLES ─── */
.ms-table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}

.ms-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}

.ms-table th {
  text-align: left; padding: 10px 12px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ms-table td {
  padding: 12px; border-bottom: 1px solid var(--border-light);
  color: var(--text-primary); vertical-align: middle;
}

.ms-table tr:last-child td { border-bottom: none; }

.ms-table tr:hover td { background: var(--border-light); }

/* ─── TIMELINE ─── */
.ms-timeline { position: relative; padding-left: 28px; }

.ms-timeline::before {
  content: ''; position: absolute; left: 9px; top: 4px; bottom: 4px;
  width: 2px; background: var(--border);
}

.ms-timeline-item {
  position: relative; padding-bottom: 20px;
}

.ms-timeline-item:last-child { padding-bottom: 0; }

.ms-timeline-dot {
  position: absolute; left: -28px; top: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff; display: flex; align-items: center;
  justify-content: center;
}

.ms-timeline-dot.done { border-color: var(--success); background: var(--success); color: #fff; }
.ms-timeline-dot.active { border-color: var(--primary); background: var(--primary); color: #fff; }
.ms-timeline-dot.overdue { border-color: var(--danger); background: var(--danger); color: #fff; }

.ms-timeline-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.ms-timeline-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ─── EMPTY STATE ─── */
.ms-empty {
  text-align: center; padding: 40px 20px;
}

.ms-empty-icon {
  font-size: 36px; color: var(--text-tertiary); margin-bottom: 12px;
}

.ms-empty-text {
  font-size: 14px; font-weight: 600; color: var(--text-secondary);
}

.ms-empty-sub {
  font-size: 12px; color: var(--text-tertiary); margin-top: 4px;
}

/* ─── BUTTONS ─── */
.ms-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 20px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: all .15s;
  text-decoration: none; font-family: inherit;
}

.ms-btn-primary {
  background: var(--primary); color: #fff;
}
.ms-btn-primary:hover { background: var(--primary-dark); }

.ms-btn-white {
  background: #fff; color: var(--text-primary);
  border: 1px solid var(--border);
}
.ms-btn-white:hover { background: var(--border-light); }

.ms-btn-success {
  background: var(--success); color: #fff;
}

.ms-btn-sm { padding: 6px 14px; font-size: 12px; }

/* ─── PHOTO GRID ─── */
.ms-photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.ms-photo-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; cursor: pointer; border: 1px solid var(--border);
  transition: transform .15s;
}

.ms-photo-grid img:hover { transform: scale(1.03); }

/* ─── DOCUMENT LIST ─── */
.ms-doc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border-light);
}

.ms-doc-item:last-child { border-bottom: none; }

.ms-doc-icon {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}

.ms-doc-info { flex: 1; min-width: 0; }
.ms-doc-name { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-doc-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

.ms-doc-action {
  flex-shrink: 0; font-size: 12px; font-weight: 600;
  color: var(--primary); text-decoration: none;
  padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff;
  cursor: pointer;
}

.ms-doc-action:hover { background: var(--primary-light); }

/* ─── MESSAGE THREAD ─── */
.ms-msg-list { display: flex; flex-direction: column; gap: 12px; }

.ms-msg {
  max-width: 80%; padding: 12px 16px; border-radius: 12px;
  font-size: 13px; line-height: 1.5;
}

.ms-msg-in {
  background: var(--border-light); color: var(--text-primary);
  align-self: flex-start; border-bottom-left-radius: 4px;
}

.ms-msg-out {
  background: var(--primary); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}

.ms-msg-meta {
  font-size: 10px; margin-top: 4px; opacity: 0.6;
}

.ms-msg-input-bar {
  display: flex; gap: 8px; padding: 12px 0; margin-top: 12px;
  border-top: 1px solid var(--border);
}

.ms-msg-input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit;
  outline: none; resize: none;
}

.ms-msg-input:focus { border-color: var(--primary); }

/* ─── SIGNATURE PAD ─── */
.ms-sign-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  min-height: 140px; display: flex; align-items: center;
  justify-content: center; cursor: crosshair; position: relative;
  background: #fafbfc;
}

.ms-sign-area canvas {
  width: 100%; height: 140px; border-radius: var(--radius);
}

/* ─── LOADING ─── */
.ms-loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; gap: 12px;
}

.ms-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: ms-spin .7s linear infinite;
}

@keyframes ms-spin { to { transform: rotate(360deg); } }

@keyframes ms-fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── SLIDE PANEL (right drawer) ─── */
.ms-panel-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 900; opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.ms-panel-backdrop.open { opacity: 1; pointer-events: auto; }

.ms-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 480px; max-width: 92vw; z-index: 901;
  background: #fff; box-shadow: -8px 0 32px rgba(0,0,0,0.12);
  transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.ms-panel-backdrop.open .ms-panel { transform: translateX(0); }

.ms-panel-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; min-height: 56px;
}
.ms-panel-header-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary-light); display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.ms-panel-header-icon i { color: var(--primary); font-size: 14px; }
.ms-panel-header-info { flex: 1; min-width: 0; }
.ms-panel-title {
  font-size: 14px; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ms-panel-subtitle { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }
.ms-panel-close {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; transition: all .15s;
}
.ms-panel-close:hover { background: var(--bg-main); border-color: var(--primary); color: var(--primary); }

.ms-panel-body {
  flex: 1; overflow-y: auto; padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.ms-panel-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  flex-shrink: 0; display: flex; gap: 8px;
}
.ms-panel-footer button {
  flex: 1; padding: 10px 12px; border-radius: 10px; border: none;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}

@media (max-width: 480px) {
  .ms-panel { width: 100vw; max-width: 100vw; }
}

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .ms-sidebar { display: none; }
  .ms-bottomnav { display: flex; }
  .ms-main {
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom, 0));
  }
  .ms-topbar { padding: 0 14px; }
  .ms-page-title { font-size: 18px; }
  .ms-stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ms-stat-value { font-size: 20px; }
  .ms-card { padding: 16px; }
  .ms-msg { max-width: 90%; }
  .ms-table { font-size: 12px; }
  .ms-table th, .ms-table td { padding: 8px; }
  .ms-topbar-user span { display: none; }
}

@media (max-width: 380px) {
  .ms-stats-grid { grid-template-columns: 1fr; }
  .ms-photo-grid { grid-template-columns: repeat(2, 1fr); }
}
