/* ==========================================================================
   StockMon — Professional Light Design System
   A restrained, institutional look: neutral surfaces, one accent colour,
   hairline borders, soft shadows, tabular figures for all financial data.
   ========================================================================== */

:root {
  /* --- Surfaces ------------------------------------------------------- */
  --bg:             #f6f7f9;   /* page canvas — a touch off-white */
  --bg-surface:     #ffffff;
  --bg-card:        #ffffff;
  --bg-subtle:      #f8fafc;   /* table headers, inset panels */
  --bg-hover:       #f1f5f9;
  --bg-input:       #ffffff;

  /* --- Type ----------------------------------------------------------- */
  --text:           #111827;
  --text-muted:     #4b5563;
  --text-dim:       #6b7280;

  /* --- Accent (single, restrained) ------------------------------------ */
  --primary:        #1d4ed8;
  --primary-hover:  #1e40af;
  --primary-soft:   #eff4ff;
  --primary-border: #c7d7fe;
  --primary-ring:   rgba(29, 78, 216, 0.14);

  /* --- Semantics ------------------------------------------------------ */
  --success:        #047857;
  --success-text:   #065f46;
  --success-bg:     #ecfdf5;
  --success-border: #a7f3d0;

  --danger:         #b91c1c;
  --danger-text:    #991b1b;
  --danger-bg:      #fef2f2;
  --danger-border:  #fecaca;

  --warning:        #b45309;
  --warning-text:   #92400e;
  --warning-bg:     #fffbeb;
  --warning-border: #fde68a;

  /* --- Market direction (matches the heatmap scale) ------------------- */
  --up:             #0f9d76;
  --down:           #e0474c;

  /* --- Lines & depth --------------------------------------------------- */
  --border:         #e5e7eb;
  --border-strong:  #d1d5db;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow:    0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, 0.08), 0 2px 6px -2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 28px -6px rgba(16, 24, 40, 0.12), 0 4px 10px -4px rgba(16, 24, 40, 0.06);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius:    10px;
  --radius-lg: 14px;

  --font: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
          'Noto Sans TC', 'Noto Sans SC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
  --header-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  color-scheme: light;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
  letter-spacing: -0.005em;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: calc(60px + var(--safe-bottom));
}

@media (min-width: 769px) {
  body { padding-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3, h4 { letter-spacing: -0.02em; line-height: 1.25; }

/* Tabular figures everywhere numbers matter */
.font-mono, .quote-price, .quote-symbol, .stat-value, .num-cell, .tabular {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.num-up   { color: var(--up); }
.num-down { color: var(--down); }

/* ==========================================================================
   Header / navigation
   ========================================================================== */

.top-header {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: var(--header-h);
  min-width: 0;   /* let the nav shrink rather than push the page wider */
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

/* The admin nav can run to eight items. Let it scroll inside the header
   instead of widening the document. */
.desktop-nav {
  display: none;
  gap: 0.15rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.desktop-nav::-webkit-scrollbar { display: none; }

/* The signed-out nav is only two links — it fits at any width, so it stays
   visible rather than hiding behind a hamburger that anonymous visitors
   never get shown. */
.desktop-nav.nav-compact { display: flex; }

.desktop-nav a {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.desktop-nav a:hover { color: var(--text); background: var(--bg-hover); }

.desktop-nav a.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.lang-switcher select {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  min-height: 36px;
}

.lang-switcher select:hover { border-color: var(--border-strong); }

/* --- User menu ------------------------------------------------------- */

.user-menu { position: relative; }

.user-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.75rem 0.22rem 0.22rem;
  cursor: pointer;
  font-family: inherit;
  min-height: 38px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.user-btn:hover { border-color: var(--border-strong); background: var(--bg-subtle); }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 190px;
  overflow: hidden;
  z-index: 150;
}

.dropdown.show { display: block; animation: dropIn 0.14s ease-out; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown a {
  display: flex;
  align-items: center;
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.12s;
}

.dropdown a:hover { background: var(--bg-hover); }

/* --- Mobile nav ------------------------------------------------------ */

.mobile-menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  width: var(--tap);
  height: var(--tap);
}

.mobile-menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.mobile-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-nav {
  display: none;
  flex-direction: column;
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.mobile-nav.open { display: flex; }

.mobile-nav a {
  padding: 0.75rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  border-radius: var(--radius-xs);
  min-height: var(--tap);
  display: flex;
  align-items: center;
}

.mobile-nav a:hover, .mobile-nav a:active { background: var(--bg-hover); }

/* Below 900px the full nav crowds the header, so the hamburger takes over. */
@media (min-width: 900px) {
  .desktop-nav { display: flex; }
  .mobile-menu-btn { display: none; }
  .mobile-nav { display: none !important; }
}

/* Small phones: brand word + full language name + sign-in button together
   exceed the width of a narrow handset and push the whole document sideways.
   Shrink the optional parts rather than letting the page scroll. */
@media (max-width: 430px) {
  .header-inner { gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .logo-text { display: none; }
  .header-right { gap: 0.35rem; }
  .lang-switcher select { max-width: 82px; padding: 0.35rem 0.3rem; font-size: 0.72rem; }
  .user-name { max-width: 60px; }
}

/* Sideways overflow is contained on `body` only.
   Putting overflow-x on <html> as well turns the root into its own scroll
   container, which stops wheel events propagating to the viewport — the page
   then refuses to scroll under the mouse over large children like the chart
   canvas or the heatmap board. Body alone clips horizontally and leaves
   vertical scrolling on the viewport where it belongs. */
body { overflow-x: hidden; }

/* ==========================================================================
   Layout
   ========================================================================== */

.main-content {
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(2.5rem + var(--safe-bottom));
}

@media (min-width: 640px) {
  .main-content { padding: 1.75rem 1.5rem 3rem; }
}

/* Page title block */
.page-head { margin-bottom: 1.25rem; }

.page-head h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.page-head p { color: var(--text-muted); font-size: 0.92rem; }

.eyebrow {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  padding: 1.15rem;
  margin-bottom: 1.15rem;
}

@media (min-width: 640px) {
  .card { padding: 1.4rem 1.5rem; margin-bottom: 1.4rem; }
}

.card-title {
  font-size: 1.02rem;
  font-weight: 700;
  margin-bottom: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.85rem;
  padding-bottom: 0.9rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.card-head .card-title { margin-bottom: 0.15rem; }

.card-link {
  display: block;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.card-link:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  letter-spacing: 0.02em;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: var(--tap);
}

.form-control::placeholder { color: #9ca3af; }

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-hint { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.3rem; }

/* ---------------------------------------------------- show/hide password ---
   SM_initPasswordToggles() in app-shared.js wraps every password input in
   .pw-wrap and appends the button. The wrapper is display:block so it occupies
   exactly the space the bare input did — several of these fields sit in
   width:100% form groups, and an inline-block wrapper would have collapsed
   them. */
.pw-wrap { position: relative; display: block; }

.pw-wrap > .form-control,
.pw-wrap > input {
  /* Room for the button so a long key does not run underneath it. */
  padding-right: 2.75rem;
}

.pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.pw-toggle:hover { color: var(--text); }

.pw-toggle:focus-visible {
  outline: none;
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.pw-toggle svg { width: 1.15rem; height: 1.15rem; display: block; }

/* Only one of the two icons is shown; which one depends on the state. */
.pw-toggle .pw-off { display: none; }
.pw-toggle[aria-pressed="true"] .pw-on  { display: none; }
.pw-toggle[aria-pressed="true"] .pw-off { display: block; }

/* Edge and IE render their own reveal control, which would sit on top of ours. */
.pw-wrap > input::-ms-reveal,
.pw-wrap > input::-ms-clear { display: none; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  min-height: var(--tap);
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover { background: var(--bg-subtle); border-color: #9ca3af; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; min-height: 34px; }
.btn-block { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================================
   Auth pages
   ========================================================================== */

.login-wrapper {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  text-align: center;
  margin-bottom: 0.25rem;
  font-size: 1.45rem;
  font-weight: 800;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
}

/* ==========================================================================
   Alerts
   ========================================================================== */

/* Block, not flex: alert bodies contain inline markup (<code>, <strong>,
   spinners) and a flex container would break each run of text into its own
   item, scrambling the sentence. */
.alert {
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid transparent;
  line-height: 1.55;
}

.alert code {
  font-family: var(--font-mono);
  font-size: 0.94em;
  background: rgba(17, 24, 39, 0.06);
  padding: 0.05em 0.3em;
  border-radius: 3px;
}

.alert .spinner { margin-right: 0.4rem; }

.alert-error   { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info    { background: var(--primary-soft); color: #1e3a8a; border-color: var(--primary-border); }

/* ==========================================================================
   Grids
   ========================================================================== */

.grid-2, .grid-3, .grid-4 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 960px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Quote display
   ========================================================================== */

.quote-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem 1.1rem;
  margin-bottom: 1.1rem;
}

.quote-symbol { font-size: 1.6rem; font-weight: 800; letter-spacing: 0; }
.quote-price  { font-size: 1.6rem; font-weight: 700; }

.quote-change {
  font-size: 0.98rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-xs);
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
}

.quote-change.up   { color: var(--success-text); background: var(--success-bg); border-color: var(--success-border); }
.quote-change.down { color: var(--danger-text);  background: var(--danger-bg);  border-color: var(--danger-border); }

/* --- Stat tiles ------------------------------------------------------ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 480px) {
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
}

.stat-item {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.7rem 0.8rem;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.stat-value { font-weight: 700; font-size: 1rem; color: var(--text); }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

th, td {
  padding: 0.7rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }

th {
  font-weight: 700;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-subtle);
  position: sticky;
  top: 0;
}

tbody tr:hover td { background: var(--bg-subtle); }

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-xs);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-master   { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-admin    { background: var(--primary-soft); color: #1e40af; border-color: var(--primary-border); }
.badge-user     { background: var(--bg-hover); color: var(--text-muted); border-color: var(--border); }
.badge-active   { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-inactive { background: var(--bg-hover); color: var(--text-dim); border-color: var(--border); }
.badge-pending  { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-approved { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-rejected { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }

/* ==========================================================================
   Tabs (shared: heatmap markets, auth, admin)
   ========================================================================== */

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}

.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.6rem 0.9rem;
  font-family: inherit;
  font-weight: 650;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-btn .tab-lock { font-size: 0.78rem; opacity: 0.65; }

/* ==========================================================================
   Segmented control
   ========================================================================== */

.seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  overflow: hidden;
  flex-shrink: 0;
}

.seg button {
  background: var(--bg-surface);
  border: none;
  padding: 0.4rem 0.7rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--bg-hover); color: var(--text); }
.seg button.on { background: var(--primary-soft); color: var(--primary); }

/* Inline checkbox + label, used in permission editors and settings forms */
.checkline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  padding: 0.25rem 0;
  cursor: pointer;
}

.checkline input { width: 16px; height: 16px; flex-shrink: 0; }

/* ==========================================================================
   Search bar
   ========================================================================== */

.search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-bar .form-control { flex: 1 1 200px; }
.search-bar .btn { flex-shrink: 0; }

/* ==========================================================================
   AI result panel
   ========================================================================== */

.ai-result {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-top: 1.15rem;
}

.ai-result h3 {
  margin-bottom: 0.75rem;
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.ai-result p { margin-bottom: 0.55rem; line-height: 1.6; }

.risk-low    { color: var(--success-text); font-weight: 700; }
.risk-medium { color: var(--warning-text); font-weight: 700; }
.risk-high   { color: var(--danger-text);  font-weight: 700; }

.risk-meter { display: inline-flex; align-items: center; gap: 3px; }

.risk-bar { width: 7px; height: 13px; border-radius: 2px; background: var(--border-strong); }

.risk-meter[data-score="1"] .risk-bar:nth-child(-n+1),
.risk-meter[data-score="2"] .risk-bar:nth-child(-n+2) { background: #059669; }
.risk-meter[data-score="3"] .risk-bar:nth-child(-n+3) { background: #d97706; }
.risk-meter[data-score="4"] .risk-bar:nth-child(-n+4) { background: #ea580c; }
.risk-meter[data-score="5"] .risk-bar:nth-child(-n+5) { background: #dc2626; }

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem calc(1.5rem + var(--safe-bottom));
  color: var(--text-dim);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.disclaimer {
  margin-bottom: 0.35rem;
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* ==========================================================================
   Loading & empty states
   ========================================================================== */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 3rem 1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  padding: 2.75rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.empty-state .empty-icon { font-size: 2rem; margin-bottom: 0.6rem; opacity: 0.75; }

.empty-state h3 { font-size: 1.05rem; font-weight: 700; color: var(--text); margin-bottom: 0.4rem; }

.skeleton {
  background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 37%, #eef1f5 63%);
  background-size: 400% 100%;
  animation: skeleton 1.4s ease infinite;
  border-radius: var(--radius-xs);
  height: 1.1em;
}

@keyframes skeleton {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ==========================================================================
   Notifications
   ========================================================================== */

.notif-bell { position: relative; }

.notif-bell .user-btn { padding: 0.3rem 0.7rem; }

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #dc2626;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  border: 2px solid #fff;
}

.notif-dropdown {
  min-width: 320px;
  max-width: 360px;
  max-height: 420px;
  overflow-y: auto;
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.875rem;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.notif-item {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.notif-item:hover  { background: var(--bg-hover); }
.notif-item.unread { background: var(--primary-soft); }

.notif-item .notif-title { font-weight: 700; font-size: 0.85rem; margin-bottom: 0.15rem; color: var(--text); }
.notif-item .notif-msg   { font-size: 0.8rem; color: var(--text-muted); }
.notif-item .notif-time  { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.25rem; }

@media (max-width: 480px) {
  .notif-dropdown { min-width: 280px; max-width: calc(100vw - 2rem); }
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 430px;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.4rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ==========================================================================
   Code block
   ========================================================================== */

.code-block {
  background: #0f172a;
  color: #e2e8f0;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.65rem 0;
}

/* ==========================================================================
   Mobile bottom bar
   ========================================================================== */

.mobile-bottom-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  z-index: 990;
  justify-content: space-around;
  align-items: center;
}

.mobile-bottom-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-weight: 600;
  gap: 1px;
  transition: color 0.2s;
}

.mobile-bottom-item .mob-icon { font-size: 1.15rem; line-height: 1; }

.mobile-bottom-item.active { color: var(--primary); font-weight: 700; }

@media (min-width: 769px) {
  .mobile-bottom-bar { display: none !important; }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.78rem; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
