/* ================================================================
   THESISMS — MASTERCLASS DESIGN SYSTEM v3.0
   Responsive · Light/Dark Theming · All Screen Sizes
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

/* ================================================================
   DARK TOKENS (default)
   ================================================================ */
:root {
  --bg:        #030712;
  --surface:   #0d1117;
  --surface2:  #161b22;
  --surface3:  #1c2128;
  --surface4:  #21262d;
  --border:    #21262d;
  --border2:   #30363d;
  --border3:   #484f58;
  --text:      #e6edf3;
  --text2:     #8b949e;
  --text3:     #6e7681;
  --text4:     #484f58;
  --indigo:    #4f46e5;
  --indigo2:   #6366f1;
  --indigo3:   #818cf8;
  --violet:    #7c3aed;
  --violet2:   #8b5cf6;
  --emerald:   #059669;
  --emerald2:  #34d399;
  --amber:     #d97706;
  --amber2:    #fbbf24;
  --rose:      #e11d48;
  --rose2:     #fb7185;
  --blue:      #0ea5e9;
  --blue2:     #38bdf8;
  --shadow:    0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.6);
  --glow:      0 0 0 2px rgba(79,70,229,.35);
  --trans:     all .18s cubic-bezier(.4,0,.2,1);
  --primary:   #4f46e5;
  --secondary: #7c3aed;
  --success:   #059669;
  --warning:   #d97706;
  --danger:    #e11d48;
  --info:      #0ea5e9;
  --serif:  'Instrument Serif', Georgia, serif;
  --sans:   'Plus Jakarta Sans', system-ui, sans-serif;
  --rad-sm: 6px; --rad: 8px; --rad-md: 10px;
  --rad-lg: 14px; --rad-xl: 20px; --pill: 999px;
  --sidebar-width: 240px;
  --navbar-height: 60px;
  --grain-opacity: .04;
}

/* ================================================================
   LIGHT TOKENS
   ================================================================ */
[data-theme="light"] {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --surface3:  #f1f5f9;
  --surface4:  #e2e8f0;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --border3:   #94a3b8;
  --text:      #0f172a;
  --text2:     #475569;
  --text3:     #64748b;
  --text4:     #94a3b8;
  --indigo3:   #4f46e5;
  --violet2:   #7c3aed;
  --emerald2:  #059669;
  --amber2:    #b45309;
  --rose2:     #be123c;
  --blue2:     #0284c7;
  --shadow:    0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --glow:      0 0 0 2px rgba(79,70,229,.25);
  --grain-opacity: .012;
}

/* ================================================================
   RESET
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--sans); line-height: 1.6;
  overflow-x: hidden;
  transition: background .25s ease, color .25s ease;
}
a { color: var(--indigo3); text-decoration: none; transition: var(--trans); }
a:hover { color: var(--indigo2); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: var(--sans); }
ul, ol { list-style: none; }

/* ================================================================
   GRAIN
   ================================================================ */
body::before {
  content: ''; position: fixed; inset: 0;
  pointer-events: none; z-index: 0; opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ================================================================
   APP SHELL — FIXED LAYOUT
   Sidebar is position:fixed. The page-wrapper fills the remaining
   space using margin-left. No grid on body needed.
   ================================================================ */
.app-container {
  /* Keep class for compatibility but don't use grid — it fights fixed sidebar */
  display: block;
  min-height: 100vh;
}

/* The wrapper div that holds topbar + main */
.page-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left .3s ease;
}

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed; top: 0; left: 0;
  height: 100vh; width: 240px;
  display: flex; flex-direction: column;
  z-index: 1000; overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
  transition: transform .3s ease, background .25s, border-color .25s;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.55); z-index: 999;
  backdrop-filter: blur(2px);
}
.sidebar-logo {
  padding: 1.1rem 1.1rem .85rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.logo-lockup { display: flex; align-items: center; gap: .6rem; margin-bottom: .2rem; }
.logo-mark {
  width: 30px; height: 30px; border-radius: var(--rad);
  background: linear-gradient(135deg, var(--indigo), var(--violet));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.35); flex-shrink: 0;
}
.logo-name { font-family: var(--serif); font-size: 1.05rem; color: var(--text); }
.logo-tag  { font-size: 9px; color: var(--text4); letter-spacing: .1em; text-transform: uppercase; margin-left: 2.6rem; }
.sidebar-nav { padding: .45rem 0; flex: 1; }
.nav-label {
  font-size: 9px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text4);
  padding: .65rem 1rem .2rem;
}
.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .48rem 1rem; font-size: 13px; color: var(--text2);
  border-left: 2px solid transparent;
  transition: var(--trans); cursor: pointer; white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--indigo); background: rgba(79,70,229,.08); border-left-color: var(--indigo); }
.nav-link i { width: 16px; text-align: center; font-size: 12.5px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--rose); color: #fff;
  font-size: 9px; font-weight: 700; padding: 1px 6px; border-radius: var(--pill);
}
.nav-badge.info { background: var(--indigo); }
.sidebar-user {
  padding: .85rem 1rem;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.user-row { display: flex; align-items: center; gap: .55rem; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), var(--violet));
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-name { font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-dept { font-size: 10px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-badge {
  margin-left: auto; font-size: 8.5px; font-weight: 700;
  padding: 2px 6px; border-radius: var(--pill);
  background: rgba(79,70,229,.12); color: var(--indigo3);
  letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; flex-shrink: 0;
}

/* ================================================================
   TOPBAR
   ================================================================ */
.topbar {
  height: var(--navbar-height);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; gap: .75rem;
  position: fixed; top: 0; right: 0;
  left: var(--sidebar-width); z-index: 900;
  transition: left .3s ease, background .25s, border-color .25s;
}
.topbar-left { min-width: 0; flex: 1; }
.topbar-title {
  font-family: var(--serif); font-size: 1rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-sub {
  font-size: 10.5px; color: var(--text3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: .45rem; flex-shrink: 0; }

/* Hamburger */
.hamburger {
  display: none; background: none; border: 1px solid var(--border2);
  border-radius: var(--rad-sm); width: 34px; height: 34px;
  align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2); flex-shrink: 0; transition: var(--trans);
}
.hamburger:hover { background: var(--surface2); color: var(--text); }

/* Theme toggle */
.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--rad-sm);
  background: var(--surface2); border: 1px solid var(--border2);
  cursor: pointer; color: var(--text2); font-size: 14px; flex-shrink: 0;
  transition: var(--trans);
}
.theme-toggle:hover { background: var(--surface3); color: var(--text); }
.icon-dark  { display: block; }
.icon-light { display: none; }
[data-theme="light"] .icon-dark  { display: none; }
[data-theme="light"] .icon-light { display: block; }

/* Auth page theme toggle */
.auth-theme-toggle {
  position: fixed; top: 1rem; right: 1rem; z-index: 100;
  width: 36px; height: 36px; border-radius: var(--rad-sm);
  background: var(--surface); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2); font-size: 14px; transition: var(--trans);
}
.auth-theme-toggle:hover { background: var(--surface2); }

/* ================================================================
   MAIN CONTENT
   ================================================================ */
main {
  margin-top: var(--navbar-height);
  padding: 1.5rem;
  flex: 1;
  background: var(--bg);
  min-width: 0; /* prevent overflow in flex child */
  transition: background .25s;
}

/* ================================================================
   FLASH MESSAGES
   ================================================================ */
.flash-wrap { margin-bottom: .85rem; display: flex; flex-direction: column; gap: .35rem; }
.flash {
  padding: .55rem .9rem; border-radius: var(--rad);
  font-size: 13px; border: 1px solid;
  display: flex; align-items: center; gap: .5rem;
  animation: fadeUp .25s ease both;
}
.flash-success { background: rgba(5,150,105,.1);  border-color: rgba(5,150,105,.3);  color: var(--emerald2); }
.flash-error   { background: rgba(225,29,72,.1);  border-color: rgba(225,29,72,.3);  color: var(--rose2); }
.flash-info    { background: rgba(79,70,229,.1);  border-color: rgba(79,70,229,.3);  color: var(--indigo3); }
[data-theme="light"] .flash-success { color: #065f46; }
[data-theme="light"] .flash-error   { color: #9f1239; }
[data-theme="light"] .flash-info    { color: #3730a3; }

/* ================================================================
   TYPOGRAPHY
   ================================================================ */
.page-title { font-family: var(--serif); font-size: clamp(1.2rem,3vw,1.6rem); color: var(--text); margin-bottom: .25rem; font-weight: 400; }
.page-sub   { font-size: 13px; color: var(--text3); }
h1,h2,h3,h4,h5 { font-family: var(--sans); color: var(--text); }

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  padding: .45rem .95rem; border-radius: var(--rad);
  cursor: pointer; transition: var(--trans); border: 1px solid transparent;
  line-height: 1; white-space: nowrap; text-decoration: none !important;
}
.btn-primary { background: var(--indigo); color: #fff !important; border-color: var(--indigo); }
.btn-primary:hover { background: var(--indigo2); }
.btn-ghost   { background: var(--surface2); color: var(--text2); border-color: var(--border2); }
.btn-ghost:hover { background: var(--surface3); color: var(--text); }
.btn-success { background: rgba(5,150,105,.12); color: var(--emerald2); border-color: rgba(5,150,105,.28); }
.btn-success:hover { background: rgba(5,150,105,.22); }
.btn-danger  { background: rgba(225,29,72,.12);  color: var(--rose2);   border-color: rgba(225,29,72,.28); }
.btn-danger:hover { background: rgba(225,29,72,.22); }
.btn-warning { background: rgba(217,119,6,.12);  color: var(--amber2);  border-color: rgba(217,119,6,.28); }
.btn-warning:hover { background: rgba(217,119,6,.22); }
.btn-sm   { font-size: 11px; padding: .3rem .65rem; }
.btn-icon { padding: .4rem; min-width: 30px; justify-content: center; }
.btn-full { width: 100%; justify-content: center; padding: .65rem; font-size: 14px; }
[data-theme="light"] .btn-ghost { background: #fff; color: var(--text2); }
[data-theme="light"] .btn-ghost:hover { background: var(--surface3); }
[data-theme="light"] .btn-success { color: #065f46; }
[data-theme="light"] .btn-danger  { color: #9f1239; }
[data-theme="light"] .btn-warning { color: #92400e; }

/* ================================================================
   CARDS
   ================================================================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rad-md); padding: 1.1rem;
  transition: border-color .2s, background .25s;
  position: relative; overflow: hidden;
}
.card:hover { border-color: var(--border2); }
.card-glow::after {
  content: ''; position: absolute; top: -40px; right: -30px;
  width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, rgba(79,70,229,.08) 0%, transparent 70%);
  pointer-events: none;
}
[data-theme="light"] .card-glow::after { background: radial-gradient(circle, rgba(79,70,229,.04) 0%, transparent 70%); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; flex-wrap: wrap; gap: .35rem; }
.card-title  { font-size: 13px; font-weight: 600; color: var(--text); }

/* ================================================================
   STAT CARDS
   ================================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rad-md); padding: .9rem 1rem;
  position: relative; overflow: hidden; transition: border-color .2s, background .25s;
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.stat-card.c-indigo::before  { background: linear-gradient(90deg, var(--indigo), var(--violet)); }
.stat-card.c-emerald::before { background: var(--emerald); }
.stat-card.c-amber::before   { background: var(--amber); }
.stat-card.c-rose::before    { background: var(--rose); }
.stat-card.c-blue::before    { background: var(--blue); }
.stat-label { font-size: 9.5px; color: var(--text3); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; margin-bottom: .3rem; }
.stat-value { font-family: var(--serif); font-size: clamp(1.4rem,3vw,2rem); color: var(--text); line-height: 1; margin-bottom: .2rem; }
.stat-value span { font-size: 1rem; color: var(--text3); }
.stat-delta { font-size: 11px; }
.stat-delta.up      { color: var(--emerald2); }
.stat-delta.down    { color: var(--rose2); }
.stat-delta.neutral { color: var(--text3); }

/* ================================================================
   BENTO GRID
   ================================================================ */
.bento { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: .65rem; margin-bottom: 1.25rem; }
.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-5  { grid-column: span 5; }
.col-6  { grid-column: span 6; }
.col-7  { grid-column: span 7; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-12 { grid-column: span 12; }

/* ================================================================
   BADGES
   ================================================================ */
.badge {
  display: inline-flex; align-items: center;
  font-size: 9.5px; font-weight: 700; padding: 2px 8px;
  border-radius: var(--pill); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
}
.badge-indigo  { background: rgba(79,70,229,.12);  color: var(--indigo3); }
.badge-emerald { background: rgba(5,150,105,.12);  color: var(--emerald2); }
.badge-amber   { background: rgba(217,119,6,.12);  color: var(--amber2); }
.badge-rose    { background: rgba(225,29,72,.12);   color: var(--rose2); }
.badge-blue    { background: rgba(14,165,233,.12); color: var(--blue2); }
.badge-gray    { background: var(--surface3);       color: var(--text3); }
[data-theme="light"] .badge-indigo  { background: rgba(79,70,229,.1);  color: #3730a3; }
[data-theme="light"] .badge-emerald { background: rgba(5,150,105,.1);  color: #065f46; }
[data-theme="light"] .badge-amber   { background: rgba(217,119,6,.1);  color: #92400e; }
[data-theme="light"] .badge-rose    { background: rgba(225,29,72,.1);  color: #9f1239; }
[data-theme="light"] .badge-blue    { background: rgba(14,165,233,.1); color: #0369a1; }

/* ================================================================
   FORMS
   ================================================================ */
.form-group { margin-bottom: .9rem; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: .35rem; }
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--rad); padding: .5rem .75rem;
  font-size: 13px; color: var(--text); outline: none;
  transition: border-color .15s, background .25s; font-family: var(--sans);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--indigo); box-shadow: var(--glow); }
.form-input::placeholder { color: var(--text4); }
.form-select { cursor: pointer; }
.form-select option { background: var(--surface2); color: var(--text); }
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-hint { font-size: 10.5px; color: var(--text3); margin-top: .3rem; }
[data-theme="light"] .form-input, [data-theme="light"] .form-select, [data-theme="light"] .form-textarea { background: #fff; }
[data-theme="light"] .form-select option { background: #fff; }

/* ================================================================
   TABLE
   ================================================================ */
.tms-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tms-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 400px; }
.tms-table th {
  font-size: 9.5px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text3);
  padding: .55rem .8rem; text-align: left;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tms-table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); color: var(--text2); }
.tms-table tr:last-child td { border-bottom: none; }
.tms-table tr:hover td { background: var(--surface2); }
.tms-table td:first-child { color: var(--text); font-weight: 500; }

/* ================================================================
   STEPPER
   ================================================================ */
.stepper-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: .4rem; }
.stepper { display: flex; min-width: 500px; }
.step-item { display: flex; flex-direction: column; align-items: center; flex: 1; position: relative; }
.step-item:not(:last-child)::after {
  content: ''; position: absolute; top: 13px; left: 50%; right: -50%;
  height: 2px; background: var(--border2); z-index: 0;
}
.step-item.done:not(:last-child)::after { background: var(--indigo); }
.step-circle {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; z-index: 1;
  border: 2px solid var(--border2); background: var(--surface);
  color: var(--text3); transition: var(--trans);
}
.step-item.done   .step-circle { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.step-item.active .step-circle { background: var(--surface); border-color: var(--amber2); color: var(--amber2); box-shadow: 0 0 0 3px rgba(251,191,36,.12); }
.step-label { font-size: 9px; color: var(--text3); text-align: center; margin-top: .35rem; line-height: 1.3; padding: 0 2px; }
.step-item.done .step-label   { color: var(--indigo3); }
.step-item.active .step-label { color: var(--amber2); }
[data-theme="light"] .step-item.active .step-label { color: var(--amber); }

/* ================================================================
   PROGRESS / GAUGE
   ================================================================ */
.progress-track { background: var(--surface3); border-radius: var(--pill); overflow: hidden; }
.progress-fill  { height: 100%; border-radius: var(--pill); transition: width .5s ease; }
.gauge-row { display: flex; align-items: center; gap: .6rem; padding: .28rem 0; }
.gauge-name  { font-size: 11.5px; color: var(--text2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gauge-track { flex: 2; height: 5px; background: var(--surface3); border-radius: var(--pill); overflow: hidden; min-width: 50px; }
.gauge-fill  { height: 100%; border-radius: var(--pill); transition: width .5s ease; }
.gauge-pct   { font-size: 10px; color: var(--text3); width: 28px; text-align: right; font-weight: 500; flex-shrink: 0; }

/* ================================================================
   CHAT
   ================================================================ */
.chat-layout {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--navbar-height) - 3rem);
  min-height: 360px; max-height: 90vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rad-md); overflow: hidden;
  transition: background .25s, border-color .25s;
}
.chat-header { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .7rem; background: var(--surface); flex-shrink: 0; flex-wrap: wrap; }
.chat-body   { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; background: var(--bg); scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
.chat-footer { padding: .85rem 1.1rem; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.chat-input-row { display: flex; gap: .4rem; }
.chat-input {
  flex: 1; min-width: 0; background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--rad); padding: .45rem .75rem;
  font-size: 13px; color: var(--text); outline: none;
  transition: border-color .15s, background .25s;
}
.chat-input:focus { border-color: var(--indigo); }
.chat-input::placeholder { color: var(--text4); }
[data-theme="light"] .chat-input { background: #fff; }
.msg { max-width: 74%; padding: .5rem .8rem; border-radius: 10px; font-size: 13px; line-height: 1.55; word-break: break-word; }
.msg.sent     { align-self: flex-end; background: rgba(79,70,229,.18); color: var(--text); border-bottom-right-radius: 3px; }
.msg.received { align-self: flex-start; background: var(--surface); color: var(--text2); border-bottom-left-radius: 3px; border: 1px solid var(--border); }
[data-theme="light"] .msg.sent     { background: rgba(79,70,229,.1); color: #312e81; }
[data-theme="light"] .msg.received { background: #fff; color: var(--text2); }
.msg-meta { font-size: 9.5px; opacity: .5; margin-bottom: 2px; }

/* ================================================================
   MODAL
   ================================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; transition: var(--trans);
  padding: 1rem;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--rad-xl); padding: 1.5rem; width: 100%;
  max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); transform: translateY(12px); transition: var(--trans);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-title  { font-family: var(--serif); font-size: 1.15rem; color: var(--text); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; }
.modal-close  { background: none; border: none; color: var(--text3); font-size: 1rem; cursor: pointer; padding: .2rem; transition: var(--trans); flex-shrink: 0; }
.modal-close:hover { color: var(--text); }

/* ================================================================
   INSIGHT STRIP
   ================================================================ */
.insight-strip {
  background: rgba(79,70,229,.07); border: 1px solid rgba(79,70,229,.18);
  border-radius: var(--rad); padding: .7rem 1rem;
  display: flex; align-items: center; gap: .7rem; margin-bottom: 1.1rem; flex-wrap: wrap;
}
[data-theme="light"] .insight-strip { background: rgba(79,70,229,.05); border-color: rgba(79,70,229,.15); }
.insight-icon {
  width: 30px; height: 30px; background: rgba(79,70,229,.18);
  border-radius: var(--rad); display: flex; align-items: center;
  justify-content: center; font-size: 13px; flex-shrink: 0; color: var(--indigo3);
}
.insight-text p    { font-size: 13px; color: var(--text); font-weight: 500; }
.insight-text span { font-size: 11px; color: var(--text3); }

/* ================================================================
   AUTH PAGES
   ================================================================ */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; background: var(--bg); }
.auth-glow {
  position: fixed; top: 35%; left: 50%; transform: translate(-50%,-50%);
  width: clamp(280px,60vw,600px); height: 500px; border-radius: 50%;
  background: radial-gradient(circle, rgba(79,70,229,.07) 0%, transparent 70%);
  pointer-events: none;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--rad-xl); padding: clamp(1.5rem,4vw,2.5rem);
  width: 100%; max-width: 440px; box-shadow: var(--shadow-lg);
  position: relative; z-index: 1;
}
.auth-heading { font-family: var(--serif); font-size: clamp(1.2rem,3vw,1.5rem); color: var(--text); margin-bottom: .3rem; }
.auth-sub  { font-size: 13px; color: var(--text3); margin-bottom: 1.5rem; }
.auth-foot { text-align: center; margin-top: 1.1rem; font-size: 12.5px; color: var(--text3); }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.auth-tab  {
  flex: 1; text-align: center; padding: .55rem; font-size: 13px;
  font-weight: 600; color: var(--text3); border-bottom: 2px solid transparent;
  cursor: pointer; transition: var(--trans);
  background: none; border-top: none; border-left: none; border-right: none;
}
.auth-tab.active { color: var(--indigo3); border-bottom-color: var(--indigo); }
[data-theme="light"] .auth-tab.active { color: var(--indigo); }

/* ================================================================
   UPLOAD ZONE
   ================================================================ */
.upload-zone {
  border: 1.5px dashed var(--border2); border-radius: var(--rad-md);
  padding: 1.25rem; text-align: center; cursor: pointer;
  transition: var(--trans); background: var(--surface2);
}
.upload-zone:hover { border-color: var(--indigo); background: rgba(79,70,229,.04); }
.upload-zone p { font-size: 13px; color: var(--text3); margin-top: .35rem; }

/* ================================================================
   DOC ROW
   ================================================================ */
.doc-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.doc-row:last-child { border-bottom: none; }
.doc-icon { width: 30px; height: 30px; border-radius: var(--rad); background: var(--surface2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.doc-name { font-size: 12.5px; font-weight: 500; color: var(--text); min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 10.5px; color: var(--text3); white-space: nowrap; }
.doc-actions { margin-left: auto; display: flex; gap: .3rem; }

/* ================================================================
   TIMELINE
   ================================================================ */
.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--border2); }
.tl-item { position: relative; padding-bottom: 1rem; }
.tl-dot { position: absolute; left: -1.4rem; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface3); border: 2px solid var(--border2); z-index: 1; transition: var(--trans); }
.tl-item.done .tl-dot   { background: var(--indigo); border-color: var(--indigo); }
.tl-item.active .tl-dot { background: var(--amber);  border-color: var(--amber2); box-shadow: 0 0 0 3px rgba(251,191,36,.12); }
.tl-label { font-size: 12.5px; font-weight: 500; color: var(--text2); }
.tl-item.done .tl-label   { color: var(--emerald2); }
.tl-item.active .tl-label { color: var(--text); }
[data-theme="light"] .tl-item.done .tl-label { color: var(--emerald); }

/* ================================================================
   SCROLLBAR
   ================================================================ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ================================================================
   ANIMATIONS
   ================================================================ */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse  { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
.fade-up    { animation: fadeUp .3s ease both; }
.fade-up-d1 { animation: fadeUp .3s .06s ease both; }
.fade-up-d2 { animation: fadeUp .3s .12s ease both; }
.fade-up-d3 { animation: fadeUp .3s .18s ease both; }
.online-dot { width: 7px; height: 7px; background: var(--emerald2); border-radius: 50%; display: inline-block; animation: pulse 2s infinite; }

/* ================================================================
   RESPONSIVE — TABLET ≤1024px
   ================================================================ */
@media (max-width: 1024px) {
  .page-wrapper { margin-left: 0; }
  .sidebar { transform: translateX(-240px); width: 240px; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.open { display: block; }
  .topbar { left: 0; }
  .hamburger { display: flex; }
  .sidebar-close-btn { display: flex !important; }

  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .col-3, .col-4, .col-5 { grid-column: span 1; }
  .col-6, .col-7, .col-8, .col-9 { grid-column: span 2; }
  .col-12 { grid-column: span 2; }
}

/* ================================================================
   RESPONSIVE — MOBILE ≤640px
   ================================================================ */
@media (max-width: 640px) {
  main { padding: .9rem; }
  .topbar { padding: 0 .9rem; }
  .topbar-right .btn:not(.theme-toggle):not(.hamburger) { display: none; }

  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .stat-value { font-size: 1.5rem; }
  .stat-card { padding: .75rem .8rem; }

  .bento { grid-template-columns: minmax(0, 1fr); }
  .col-3,.col-4,.col-5,.col-6,.col-7,.col-8,.col-9,.col-12 { grid-column: span 1; }

  .auth-card { padding: 1.35rem 1.1rem; }

  .chat-layout { height: calc(100vh - var(--navbar-height) - 1.8rem); min-height: 300px; }
  .msg { max-width: 88%; }

  .insight-strip .btn-sm { display: none; }
  .insight-strip { gap: .5rem; }

  .modal { padding: 1.1rem; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--rad-lg) var(--rad-lg) 0 0; max-width: 100%; }
  .modal-overlay.open .modal { transform: translateY(0); }
}

/* ================================================================
   RESPONSIVE — SMALL ≤380px
   ================================================================ */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
  main { padding: .65rem; }
  .topbar { padding: 0 .65rem; }
  .logo-name { display: none; }
  .topbar-title { font-size: .9rem; }
}

/* ================================================================
   PRINT
   ================================================================ */
@media print {
  .sidebar, .topbar, .btn, .flash-wrap, .modal-overlay { display: none !important; }
  main { margin: 0 !important; padding: 1rem !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { border: 1px solid #ddd !important; box-shadow: none !important; }
}

/* ================================================================
   LIGHT MODE — SURFACE & COMPONENT OVERRIDES
   ================================================================ */
[data-theme="light"] body            { background: var(--bg); }
[data-theme="light"] .sidebar        { background: #fff; border-right-color: var(--border); }
[data-theme="light"] .topbar         { background: #fff; border-bottom-color: var(--border); }
[data-theme="light"] .card           { background: #fff; }
[data-theme="light"] .stat-card      { background: #fff; }
[data-theme="light"] .modal          { background: #fff; }
[data-theme="light"] .chat-header    { background: #fff; }
[data-theme="light"] .chat-footer    { background: #fff; }
[data-theme="light"] .chat-body      { background: var(--bg); }
[data-theme="light"] main            { background: var(--bg); }
[data-theme="light"] .nav-link.active{ color: var(--indigo); background: rgba(79,70,229,.07); border-left-color: var(--indigo); }
[data-theme="light"] .nav-link:hover { color: var(--text); background: var(--surface2); }
[data-theme="light"] .user-badge     { background: rgba(79,70,229,.1); color: var(--indigo); }
[data-theme="light"] .logo-name      { color: #0f172a; }
[data-theme="light"] .insight-strip  { background: rgba(79,70,229,.05); border-color: rgba(79,70,229,.15); }
[data-theme="light"] .insight-icon   { background: rgba(79,70,229,.12); color: var(--indigo); }
[data-theme="light"] .upload-zone    { background: #f8fafc; }
[data-theme="light"] .doc-icon       { background: var(--surface2); }
[data-theme="light"] .tms-table tr:hover td { background: var(--surface2); }
[data-theme="light"] .step-circle    { background: #fff; color: var(--text3); }
[data-theme="light"] .step-item.done .step-circle { background: var(--indigo); color: #fff; }
[data-theme="light"] .sidebar-backdrop { background: rgba(0,0,0,.4); }
[data-theme="light"] .auth-theme-toggle { background: #fff; }
[data-theme="light"] .theme-toggle   { background: var(--surface2); }
[data-theme="light"] .progress-track { background: var(--surface3); }
[data-theme="light"] .gauge-track    { background: var(--surface3); }
[data-theme="light"] .tl-dot         { background: var(--surface3); }
[data-theme="light"] body::before    { opacity: .015; }

/* ================================================================
   UTILITY — hide-xs already in topbar partial, ensure global too
   ================================================================ */
@media (max-width: 480px) { .hide-xs { display: none !important; } }

/* ── NAV BADGE ─────────────────────────────────────────── */
.nav-badge {
  background: var(--rose);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: var(--pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  margin-left: auto;
}

/* ── TABS ──────────────────────────────────────────────── */
.tab {
  padding: .5rem 1rem;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  border-radius: 0;
  transition: var(--trans);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--indigo3); border-bottom-color: var(--indigo); }

/* ── GAUGE BARS (analytics) ────────────────────────────── */
.gauge-row { display: flex; align-items: center; gap: .65rem; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.gauge-name { font-size: 12px; color: var(--text2); width: 140px; flex-shrink: 0; }
.gauge-track { flex: 1; height: 6px; background: var(--surface3); border-radius: var(--pill); overflow: hidden; }
.gauge-fill { height: 100%; border-radius: var(--pill); transition: width .6s ease; }
.gauge-pct { font-size: 11px; color: var(--text3); width: 24px; text-align: right; }

/* ── CHAT INPUT ────────────────────────────────────────── */
.chat-input { flex: 1; }

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--rad-lg); padding: 1.5rem; width: 100%; max-width: 460px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-title { font-size: 14px; font-weight: 600; color: var(--text); }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text3); font-size: 14px; padding: .2rem; }
.modal-close:hover { color: var(--text); }

/* ── FORM HINT ─────────────────────────────────────────── */
.form-hint { font-size: 11px; color: var(--text3); margin-top: .25rem; }

/* ── NOTIF ROW ─────────────────────────────────────────── */
.notif-unread { background: rgba(79,70,229,.04); }
.notif-row:hover { background: var(--surface2); }

/* ── VIOLET VARS ────────────────────────────────────────── */
:root {
  --violet:  #7c3aed;
  --violet2: #8b5cf6;
  --violet3: #a78bfa;
  --blue:    #0ea5e9;
  --blue2:   #38bdf8;
  --rose:    #e11d48;
  --rose2:   #fb7185;
  --amber:   #d97706;
  --amber2:  #fbbf24;
  --emerald: #059669;
  --emerald2:#34d399;
}


/* ── MISSING STAT CARD COLOURS ─────────────────────────── */
.stat-card.c-violet {
  border-top: 3px solid var(--violet);
}
.stat-card.c-violet .stat-value { color: var(--violet2); }
.stat-card.c-violet .stat-delta.up   { color: var(--violet2); }
.stat-card.c-rose {
  border-top: 3px solid var(--rose);
}
.stat-card.c-rose .stat-value { color: var(--rose2); }

/* ── BADGE VARIANTS ────────────────────────────────────── */
.badge-violet {
  background: rgba(124,58,237,.12);
  color: var(--violet2);
  border: 1px solid rgba(124,58,237,.25);
}
.badge-rose {
  background: rgba(225,29,72,.10);
  color: var(--rose2);
  border: 1px solid rgba(225,29,72,.2);
}

/* ── STEPPER RESPONSIVE ────────────────────────────────── */
.stepper-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── FORM FULL-WIDTH BUTTON ────────────────────────────── */
.btn-full { width: 100%; justify-content: center; }

