/* Stored-Cloud Design System — full token set + component styles */
@import url('https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* Teal ramp */
  --teal-50:  #ECFDFE;
  --teal-100: #CFF8FB;
  --teal-200: #A2EEF4;
  --teal-300: #67DEE9;
  --teal-400: #2CC4D6;
  --teal-500: #0EA5B7;
  --teal-600: #0A8497;
  --teal-700: #0E6A7A;
  --teal-800: #135665;
  --teal-900: #134756;
  --teal-950: #062E3A;

  /* Slate ramp */
  --slate-50:  #F8FAFC;
  --slate-100: #F1F5F9;
  --slate-200: #E6EBF1;
  --slate-300: #CDD6E0;
  --slate-400: #94A3B8;
  --slate-500: #64748B;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1E293B;
  --slate-900: #0F1B2D;
  --slate-950: #060D18;
  --white: #FFFFFF;

  /* Semantic status */
  --success-500: #16A34A; --success-50: #DCFCE7; --success-700: #15803D;
  --warning-500: #D97706; --warning-50: #FEF3C7; --warning-700: #B45309;
  --danger-500:  #DC2626; --danger-50:  #FEE2E2; --danger-700:  #B91C1C;
  --info-500:    #2563EB; --info-50:    #DBEAFE; --info-700:    #1D4ED8;

  /* Semantic surfaces */
  --bg:              var(--slate-50);
  --surface:         var(--white);
  --surface-2:       var(--slate-100);
  --surface-sunken:  var(--slate-100);
  --border:          var(--slate-200);
  --border-strong:   var(--slate-300);
  --fg1:             var(--slate-900);
  --fg2:             var(--slate-600);
  --fg3:             var(--slate-500);
  --fg-onaccent:     var(--white);
  --accent:          var(--teal-500);
  --accent-hover:    var(--teal-600);
  --accent-quiet:    var(--teal-50);
  --link:            var(--teal-700);

  /* Type families */
  --font-display: 'Spectral', Georgia, 'Times New Roman', serif;
  --font-sans:    'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Radii */
  --radius-xs: 3px; --radius-sm: 4px; --radius-md: 6px;
  --radius-lg: 8px; --radius-xl: 12px; --radius-full: 9999px;

  /* Spacing */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 32px;
  --space-10: 40px; --space-12: 48px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(6,13,24,0.05);
  --shadow-sm: 0 1px 3px rgba(6,13,24,0.07), 0 1px 2px rgba(6,13,24,0.04);
  --shadow-md: 0 4px 12px rgba(6,13,24,0.08), 0 2px 4px rgba(6,13,24,0.04);
  --shadow-lg: 0 12px 32px rgba(6,13,24,0.12), 0 4px 8px rgba(6,13,24,0.05);
  --focus-ring: 0 0 0 3px rgba(14,165,183,0.28);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 120ms;
  --dur: 180ms;

  /* Backward-compat aliases used throughout existing templates */
  --color-bg:           var(--bg);
  --color-surface:      var(--surface);
  --color-surface-2:    var(--surface-2);
  --color-text:         var(--fg1);
  --color-text-muted:   var(--fg2);
  --color-accent:       var(--accent);
  --color-accent-hover: var(--accent-hover);
  --color-accent-soft:  var(--accent-quiet);
  --color-border:       var(--border);
  --color-success:      var(--success-500);
  --color-warning:      var(--warning-500);
  --color-danger:       var(--danger-500);
  --color-primary:      var(--accent);
  --color-muted:        var(--fg2);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg1);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono { font-family: var(--font-mono); }

.container { max-width: 1100px; margin: 0 auto; padding: var(--space-6); }

/* ---- Navbar ---- */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-6);
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.navbar .brand { display: flex; align-items: center; }
.navbar .brand img { height: 32px; width: auto; display: block; }
.navbar .brand:hover { opacity: .88; text-decoration: none; }
.navbar nav { display: flex; gap: var(--space-4); align-items: center; font-size: 14px; }
.navbar nav a { color: var(--fg2); font-weight: 500; }
.navbar nav a:hover { color: var(--accent); text-decoration: none; }

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-4); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg1);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary {
  background: var(--accent); color: var(--fg-onaccent);
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger-500); border-color: var(--danger-500); }
.btn.danger:hover { background: var(--danger-500); color: white; }

/* ---- Inputs ---- */
.input, select.input, textarea.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg1);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color var(--dur-fast);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

/* ---- Utility ---- */
.muted { color: var(--fg2); }
.danger { color: var(--danger-500); }
.success { color: var(--success-500); }

/* ---- Table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  color: var(--fg3);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.table tr:hover td { background: var(--surface-2); }

/* ---- Flash messages ---- */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: 14px;
}
.flash.success { background: var(--success-50); color: var(--success-700); border: 1px solid #a7f3d0; }
.flash.danger  { background: var(--danger-50);  color: var(--danger-700);  border: 1px solid #fecaca; }
.flash.warn    { background: var(--warning-50); color: var(--warning-700); border: 1px solid #fde68a; }

/* ================================================================
   TOP BAR (replaces old .navbar)
   ================================================================ */
.sc-topbar {
  position: sticky; top: 0; z-index: 30;
  height: 60px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.sc-topbar-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; flex: none;
}
.sc-topbar-logo:hover { opacity: .85; text-decoration: none; }
.sc-topbar-wordmark {
  font-size: 17px; font-weight: 700; letter-spacing: -0.015em; line-height: 1;
}
.sc-topbar-wordmark-s { color: var(--slate-900); }
.sc-topbar-wordmark-c { color: var(--teal-500); }
.sc-topbar-nav {
  display: flex; align-items: center; gap: 2px; margin-left: 12px;
}
.sc-topbar-link {
  font-size: 14px; font-weight: 500; color: var(--fg2);
  padding: 6px 10px; border-radius: var(--radius-md);
  text-decoration: none; transition: color var(--dur-fast), background var(--dur-fast);
}
.sc-topbar-link:hover  { color: var(--fg1); background: var(--surface-2); text-decoration: none; }
.sc-topbar-link.active { color: var(--teal-700); background: var(--teal-50); font-weight: 600; }
.sc-topbar-spacer { flex: 1; }
.sc-topbar-search {
  position: relative; width: 280px; max-width: 30vw;
}
.sc-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--slate-400); pointer-events: none;
}
.sc-topbar-search-input {
  width: 100%; box-sizing: border-box;
  font-family: var(--font-sans); font-size: 13.5px; color: var(--fg1);
  padding: 7px 12px 7px 33px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--slate-50); outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.sc-topbar-search-input:focus {
  border-color: var(--teal-500); box-shadow: var(--focus-ring); background: #fff;
}
.sc-topbar-search-input::placeholder { color: var(--slate-400); }
.sc-topbar-actions {
  display: flex; align-items: center; gap: 10px; margin-left: 8px;
}
.sc-topbar-action-link {
  font-size: 13.5px; font-weight: 500; color: var(--fg2); text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-md);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.sc-topbar-action-link:hover { color: var(--fg1); background: var(--surface-2); text-decoration: none; }
.sc-btn-primary {
  display: inline-flex; align-items: center; padding: 7px 14px;
  font-family: var(--font-sans); font-size: 13.5px; font-weight: 600;
  color: #fff; background: var(--teal-500); border: none; border-radius: var(--radius-md);
  cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast);
}
.sc-btn-primary:hover { background: var(--teal-600); text-decoration: none; }

/* Avatar + dropdown */
.sc-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--teal-700); color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; font-family: var(--font-sans);
  cursor: pointer; user-select: none; flex: none;
}
.sc-avatar-wrap { position: relative; }
.sc-avatar-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  min-width: 200px; padding: 8px; z-index: 50;
}
.sc-avatar-wrap:hover .sc-avatar-menu { display: block; }
.sc-avatar-email {
  display: block; padding: 6px 10px 10px;
  font-size: 12px; color: var(--fg3); font-family: var(--font-mono);
  border-bottom: 1px solid var(--border); margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sc-avatar-menu-item {
  display: block; padding: 7px 10px;
  font-size: 13.5px; font-weight: 500; text-decoration: none;
  color: var(--fg1); border-radius: var(--radius-sm);
  transition: background var(--dur-fast);
}
.sc-avatar-menu-item:hover { background: var(--surface-2); text-decoration: none; }
.sc-avatar-menu-item.danger { color: var(--danger-500); }
.sc-avatar-menu-item.danger:hover { background: var(--danger-50); }

/* Main content below topbar */
.sc-main { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }
.sc-flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); margin-bottom: var(--space-5); font-size: 14px; }
.sc-flash.success { background: var(--success-50); color: var(--success-700); border: 1px solid #a7f3d0; }
.sc-flash.danger  { background: var(--danger-50);  color: var(--danger-700);  border: 1px solid #fecaca; }
.sc-flash.warn    { background: var(--warning-50); color: var(--warning-700); border: 1px solid #fde68a; }

/* ================================================================
   ADMIN CONSOLE SHELL (dark sidebar)
   ================================================================ */
body.sc-console-body { background: var(--slate-950); }
body.sc-console-body .sc-topbar { display: none; } /* sidebar replaces topbar */
body.sc-console-body .sc-main { max-width: none; padding: 0; }

.sc-console-shell {
  display: flex; height: 100vh; overflow: hidden;
}
.sc-console-sidebar {
  width: 230px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
}
.sc-console-logo {
  padding: 18px 18px 14px;
  display: flex; align-items: center; gap: 9px;
}
.sc-console-wordmark {
  font-size: 17px; font-weight: 700; letter-spacing: -0.015em; line-height: 1;
  color: #EAF1F8;
}
.sc-console-org {
  margin: 0 14px 10px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}
.sc-console-org-badge {
  width: 22px; height: 22px; border-radius: 5px;
  background: var(--teal-500); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; flex: none;
}
.sc-console-org-name { font-size: 13.5px; font-weight: 600; color: var(--fg1); }
.sc-console-nav-label {
  padding: 6px 22px;
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--fg3);
}
.sc-console-nav { padding: 0 12px; display: flex; flex-direction: column; gap: 2px; }
.sc-console-nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; border-radius: 7px;
  font-family: var(--font-sans); font-size: 13.5px; font-weight: 450;
  color: var(--fg2); text-decoration: none;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.sc-console-nav-item svg { color: var(--fg3); flex: none; transition: color var(--dur-fast); }
.sc-console-nav-item:hover { background: var(--surface-2); color: var(--fg1); text-decoration: none; }
.sc-console-nav-item:hover svg { color: var(--fg2); }
.sc-console-nav-item.active { background: var(--accent-quiet); color: var(--teal-300); font-weight: 600; }
.sc-console-nav-item.active svg { color: var(--teal-300); }
.sc-console-footer {
  margin-top: auto; padding: 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sc-console-footer-info { flex: 1; min-width: 0; }
.sc-console-footer-name { font-size: 13px; font-weight: 600; color: var(--fg1); }
.sc-console-logout {
  color: var(--fg3); display: flex; align-items: center; flex: none;
  transition: color var(--dur-fast);
}
.sc-console-logout:hover { color: var(--danger-500); text-decoration: none; }
.sc-console-main {
  flex: 1; min-width: 0; overflow-y: auto;
  background: var(--bg);
}

/* ---- Powered-by credit ---- */
.sc-credit {
  text-align: center;
  padding: 22px 12px calc(14px + env(safe-area-inset-bottom));
}
.sc-credit a {
  font-size: 11.5px;
  color: var(--fg3);
  opacity: .72;
  text-decoration: none;
}
.sc-credit a:hover { opacity: 1; text-decoration: none; }
/* Console pages get the footer from _layout inside the scroll pane; hide the base one */
body.sc-console-body > main > .sc-credit { display: none; }

/* ---- Toasts ---- */
#sc-toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000; pointer-events: none;
}
.sc-toast {
  padding: 10px 16px; border-radius: var(--radius-lg);
  font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.sc-toast.show { opacity: 1; transform: none; }
.sc-toast.success { background: var(--slate-900); color: #fff; }
.sc-toast.danger  { background: var(--danger-500); color: #fff; }

/* ================================================================
   MOBILE (≤1024px — includes retina iPads, per cross-project rule)
   ================================================================ */
#sc-mobile-nav, #sc-more-drawer { display: none; }

@media (max-width: 1024px) {
  /* Hide desktop nav links; keep logo, search, avatar */
  .sc-topbar-nav { display: none; }
  .sc-topbar-actions .sc-topbar-action-link { display: none; }

  body.has-mobile-nav { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }

  /* Bottom tab bar — dark chrome, site teal accent */
  #sc-mobile-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    background: #0a0c14;
    border-top: 1px solid #1e2535;
    height: calc(60px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sc-mobile-tab {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    color: #718096; text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.58rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em;
  }
  .sc-mobile-tab svg { width: 1.15rem; height: 1.15rem; }
  .sc-mobile-tab:hover { color: var(--teal-300); text-decoration: none; }
  .sc-mobile-tab.active { color: var(--accent); }

  /* More drawer */
  #sc-more-drawer:not([hidden]) {
    display: block;
    position: fixed; left: 0; right: 0; z-index: 950;
    bottom: calc(60px + env(safe-area-inset-bottom));
    background: #0d0f18;
    border: 1px solid #1e2535; border-bottom: none;
    border-radius: 18px 18px 0 0;
    padding: 10px 14px 16px;
  }
  .sc-more-handle { width: 42px; height: 4px; border-radius: 2px; background: #2d3748; margin: 2px auto 12px; }
  .sc-more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .sc-more-tile {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    background: #141720; border: 1px solid #1e2535; border-radius: 12px;
    padding: 14px 8px; text-decoration: none;
  }
  .sc-more-tile:hover { text-decoration: none; }
  .sc-more-tile svg { width: 1.4rem; height: 1.4rem; color: var(--accent); }
  .sc-more-tile span {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: #a0aec0;
  }
  .sc-more-tile.active { background: rgba(14,165,183,0.12); border-color: rgba(14,165,183,0.35); }
  .sc-more-tile.active span { color: var(--accent); }
  .sc-more-tile.logout {
    grid-column: 1 / -1; flex-direction: row; justify-content: center;
    background: rgba(220,38,38,0.10); border-color: rgba(220,38,38,0.30);
  }
  .sc-more-tile.logout svg, .sc-more-tile.logout span { color: #f87171; }

  /* Admin console: sidebar becomes a top strip with horizontal nav */
  .sc-console-shell { flex-direction: column; height: auto; overflow: visible; }
  .sc-console-sidebar {
    width: 100%; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sc-console-nav {
    flex-direction: row; overflow-x: auto; padding: 0 12px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .sc-console-nav-item { flex: none; white-space: nowrap; }
  .sc-console-footer { display: none; }
  .sc-console-main { overflow: visible; }

  /* Tables scroll instead of crushing */
  .table { display: block; overflow-x: auto; }

  /* Share dialog near-full-screen */
  #share-dialog .card { max-width: none; width: calc(100vw - 24px); max-height: 82vh; overflow-y: auto; }

  .sc-main { padding: 20px 14px; }
  .sc-topbar { padding: 0 14px; }
  .sc-topbar-search { max-width: none; flex: 1; width: auto; }
}
