/* ==========================================================================
   LearningByDesign — Production Styles
   Design system: dark surface, teal accent (LR brand color), TBD typography.
   ========================================================================== */

:root {
  /* Brand */
  --brand-primary: #14B8A6;       /* Teal — LR icon color */
  --brand-primary-hover: #0D9488;
  --brand-primary-light: #2DD4BF;
  --brand-accent: #00F0FF;        /* TBD ecosystem cyan */
  --brand-warning: #F59E0B;
  --brand-danger: #EF4444;
  --brand-success: #10B981;

  /* Surfaces */
  --bg: #09090B;
  --surface-1: #111113;
  --surface-2: #18181B;
  --surface-3: #27272A;
  --surface-elevated: #1F1F23;

  /* Borders */
  --border-subtle: #27272A;
  --border-default: #3F3F46;
  --border-strong: #52525B;
  --border-focus: var(--brand-primary);

  /* Text */
  --text-primary: #FAFAFA;
  --text-secondary: #D4D4D8;
  --text-tertiary: #A1A1AA;
  --text-muted: #71717A;
  --text-disabled: #52525B;
  --text-on-brand: #042F2A;

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

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 8px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  --shadow-glow: 0 0 0 3px rgba(20,184,166,0.18);

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --content-max: 1280px;

  /* Typography */
  --font-display: 'Orbitron', system-ui, sans-serif;
  --font-body: 'Instrument Sans', system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Motion */
  --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
}

body { min-height: 100vh; min-height: 100dvh; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* Focus rings */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-default); }

/* ==========================================================================
   HIDDEN ATTRIBUTE — must beat .app-shell/.auth-gate display rules below
   ========================================================================== */
[hidden] { display: none !important; }

/* ==========================================================================
   AUTH GATE
   ========================================================================== */
.auth-gate {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(at 20% 30%, rgba(20,184,166,0.06), transparent 50%),
    radial-gradient(at 80% 70%, rgba(0,240,255,0.04), transparent 50%),
    var(--bg);
}
.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-10);
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--brand-primary);
  margin-bottom: var(--space-2);
}
.auth-logo .accent { color: var(--brand-accent); font-weight: 500; }
.auth-tagline {
  color: var(--text-tertiary);
  font-size: 14px;
  margin-bottom: var(--space-8);
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh; min-height: 100dvh;
}

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  padding: var(--space-5) var(--space-3);
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}
.brand-mark {
  width: 36px; height: 36px;
  background: rgba(20,184,166,0.12);
  border: 1px solid rgba(20,184,166,0.3);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 900; font-size: 13px;
  color: var(--brand-primary);
  letter-spacing: 0.5px;
}
.brand-text {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-text .accent { color: var(--brand-primary); font-weight: 500; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 14px; font-weight: 500;
  transition: background var(--transition-fast), color var(--transition-fast);
  cursor: pointer; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active {
  background: rgba(20,184,166,0.1);
  color: var(--brand-primary);
}
.nav-item-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: var(--space-4) var(--space-3) var(--space-1);
  text-transform: uppercase;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}
.user-menu-btn {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  transition: background var(--transition-fast);
}
.user-menu-btn:hover { background: var(--surface-2); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand-primary);
  color: var(--text-on-brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}

/* Topbar */
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 var(--space-6);
  background: rgba(9,9,11,0.7);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 50;
}
.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: var(--space-3);
}
.view-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px;
  background: var(--brand-danger);
  color: white;
  font-size: 10px; font-weight: 700;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

.view-container {
  padding: var(--space-6);
  max-width: var(--content-max);
}
.loading {
  padding: var(--space-12);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* ==========================================================================
   COMMON COMPONENTS
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand-primary); color: var(--text-on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-primary-hover); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }
.btn-danger { background: var(--brand-danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-icon-left svg { margin-right: 2px; }

/* Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
}
.card-header h2, .card-header h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}
.card-body { padding: var(--space-6); }
.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
}

/* Forms */
.form-group { margin-bottom: var(--space-5); }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-1);
}
.form-error {
  font-size: 12px;
  color: var(--brand-danger);
  margin-top: var(--space-1);
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: 14px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-glow);
}
.form-input:disabled, .form-textarea:disabled, .form-select:disabled {
  opacity: 0.5; cursor: not-allowed;
}
.form-textarea { min-height: 100px; resize: vertical; }
.form-checkbox {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: 14px;
  cursor: pointer;
}
.form-checkbox input { width: 16px; height: 16px; cursor: pointer; }

.form-row {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-2);
}
.data-table td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Status pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pill-default { background: var(--surface-3); color: var(--text-secondary); }
.pill-success { background: rgba(16,185,129,0.15); color: #34D399; }
.pill-warning { background: rgba(245,158,11,0.15); color: #FCD34D; }
.pill-danger { background: rgba(239,68,68,0.15); color: #F87171; }
.pill-info { background: rgba(20,184,166,0.15); color: var(--brand-primary-light); }
.pill-draft { background: var(--surface-3); color: var(--text-tertiary); }
.pill-published { background: rgba(20,184,166,0.15); color: var(--brand-primary-light); }
.pill-archived { background: rgba(148,148,148,0.1); color: var(--text-muted); }

/* Empty states */
.empty-state {
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.empty-state-icon {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-4);
  background: var(--surface-2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.empty-state-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}
.empty-state-message {
  color: var(--text-tertiary);
  margin-bottom: var(--space-5);
  font-size: 14px;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 1000;
  display: flex; flex-direction: column; gap: var(--space-3);
  max-width: 380px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast-success { border-color: rgba(16,185,129,0.4); }
.toast-error { border-color: rgba(239,68,68,0.4); }
.toast-warning { border-color: rgba(245,158,11,0.4); }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 2px; }
.toast-success .toast-icon { color: var(--brand-success); }
.toast-error .toast-icon { color: var(--brand-danger); }
.toast-warning .toast-icon { color: var(--brand-warning); }
.toast-info .toast-icon { color: var(--brand-primary); }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-body { color: var(--text-tertiary); font-size: 13px; }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal-container {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  animation: modal-fade 0.2s ease-out forwards;
}
.modal-dialog {
  position: relative;
  margin: 5vh auto;
  max-width: 560px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-pop 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  max-height: 85vh;
  display: flex; flex-direction: column;
}
.modal-dialog.modal-lg { max-width: 800px; }
.modal-dialog.modal-xl { max-width: 1100px; }
.modal-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
}
.modal-header h2, .modal-header h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}
.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: flex-end;
  gap: var(--space-3);
  background: var(--surface-2);
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Layout helpers */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-tight { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-loose { display: flex; flex-direction: column; gap: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-tertiary { color: var(--text-tertiary); }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--text-primary); }
.text-brand { color: var(--brand-primary); }
.text-success { color: var(--brand-success); }
.text-warning { color: var(--brand-warning); }
.text-danger { color: var(--brand-danger); }
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 22px; }
.text-3xl { font-size: 28px; }
.font-display { font-family: var(--font-display); }
.font-mono { font-family: var(--font-mono); }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-900 { font-weight: 900; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* Mobile */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 0 var(--space-4); }
  .view-container { padding: var(--space-4); }
}
