/* 360EduSync — dashboard styles. Dark-first, indigo/teal palette, mobile-first. */

:root {
  color-scheme: dark;
  --bg: #0a0f1e;
  --surface: #121a2e;
  --surface-2: #182238;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e7ecf6;
  --muted: #93a0b8;
  --indigo: #7c88ff;
  --indigo-deep: #5b5ff0;
  --teal: #2fd6c0;
  --ok: #34d399;
  --fail: #fb7185;
  --idle: #64748b;
  --shadow: 0 14px 40px rgba(3, 7, 18, 0.45);
  --radius: 18px;
  --radius-sm: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef1f8;
    --surface: #ffffff;
    --surface-2: #f3f5fc;
    --border: rgba(30, 41, 59, 0.1);
    --text: #1a2338;
    --muted: #5c677e;
    --indigo: #5157e8;
    --indigo-deep: #4338ca;
    --teal: #0d9488;
    --ok: #059669;
    --fail: #e11d48;
    --idle: #94a3b8;
    --shadow: 0 12px 32px rgba(30, 41, 59, 0.1);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 85% -10%, color-mix(in srgb, var(--indigo) 15%, transparent), transparent 60%),
    radial-gradient(900px 520px at -10% 105%, color-mix(in srgb, var(--teal) 11%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h2, h3 { margin: 0; letter-spacing: -0.01em; }

.hidden { display: none !important; }

/* Class display rules must not defeat the hidden attribute */
[hidden] { display: none !important; }

/* ---------- Logo & badge ---------- */

.logo {
  margin: 0;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--muted);
  white-space: nowrap;
}

.logo b {
  background: linear-gradient(92deg, var(--indigo), var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-lg { font-size: 2.1rem; }

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--teal) 40%, transparent);
  background: color-mix(in srgb, var(--teal) 12%, transparent);
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ---------- Buttons & fields ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--indigo-deep), var(--indigo) 55%, var(--teal) 130%);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--indigo-deep) 35%, transparent);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
.btn.ghost:hover { color: var(--text); border-color: color-mix(in srgb, var(--text) 25%, transparent); }

.btn-block { width: 100%; }

:is(a, button, textarea, input):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.field { display: block; text-align: left; }

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease;
}

.field input:focus { border-color: var(--indigo); outline: none; }

/* ---------- Gate ---------- */

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: min(380px, 100%);
  display: grid;
  gap: 18px;
  padding: 40px 32px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}

.gate-subtitle {
  margin: -12px 0 4px;
  color: var(--muted);
  font-size: 0.95rem;
}

.gate-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--fail) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--fail) 35%, transparent);
  color: var(--fail);
  font-size: 0.88rem;
}

/* ---------- App shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 32px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px) 48px;
}

/* Nav: horizontal tabs on mobile, sidebar on desktop */
.nav {
  position: sticky;
  top: 61px;
  z-index: 20;
  display: flex;
  gap: 6px;
  padding: 10px 0;
  overflow-x: auto;
  scrollbar-width: none;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.nav::-webkit-scrollbar { display: none; }

.nav-link {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-link:hover { color: var(--text); }

.nav-link.active {
  color: var(--text);
  background: color-mix(in srgb, var(--indigo) 16%, transparent);
}

.content { display: grid; gap: 40px; padding-top: 20px; }

.section { scroll-margin-top: 130px; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 { font-size: 1.35rem; }

.kicker {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.footer {
  margin-top: 8px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

/* ---------- Status ---------- */

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.status-card {
  padding: 16px;
  display: grid;
  gap: 10px;
  transition: transform 0.15s ease;
}

.status-card:hover { transform: translateY(-2px); }

.status-top { display: flex; align-items: center; gap: 10px; }
.status-top h3 { font-size: 0.95rem; font-weight: 600; }

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--idle);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--idle) 16%, transparent);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.dot[data-state="ok"] {
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 18%, transparent);
}

.dot[data-state="fail"] {
  background: var(--fail);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--fail) 18%, transparent);
}

.dot[data-state="checking"] { animation: pulse 1.1s ease-in-out infinite; }

.status-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.status-meta .ms { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.status-meta .time { color: var(--muted); font-size: 0.74rem; white-space: nowrap; }

/* ---------- Chat ---------- */

.chat { padding: 16px; display: grid; gap: 12px; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 160px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 2px;
  overscroll-behavior: contain;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 82%;
  animation: rise 0.25s ease both;
}

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: linear-gradient(135deg, var(--indigo-deep), var(--indigo));
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.assistant .bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.msg.error .bubble {
  background: color-mix(in srgb, var(--fail) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--fail) 30%, transparent);
  color: var(--fail);
}

.msg-meta {
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.typing .dots { display: inline-flex; gap: 3px; }

.typing .dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s ease-in-out infinite;
}
.typing .dots i:nth-child(2) { animation-delay: 0.15s; }
.typing .dots i:nth-child(3) { animation-delay: 0.3s; }

.chat-composer { display: flex; gap: 10px; align-items: flex-end; }

.chat-composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  resize: none;
  transition: border-color 0.15s ease;
}

.chat-composer textarea:focus { border-color: var(--indigo); outline: none; }

.hint { margin: -4px 0 0; color: var(--muted); font-size: 0.72rem; }

/* ---------- Dictation ---------- */

.stt { padding: 20px; display: grid; gap: 16px; }

.stt-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

.btn.record {
  padding: 14px 26px;
  font-size: 1.02rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.btn.record .rec-icon { font-size: 1.2rem; }

.btn.record[data-state="recording"] {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #e11d48, #f43f5e);
  animation: ring 1.4s ease-out infinite;
}

.rec-timer {
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--fail);
}

.stt-status { margin: 0; color: var(--muted); font-size: 0.9rem; }
.stt-status.error { color: var(--fail); }

.stt-result {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  animation: rise 0.25s ease both;
}

.stt-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
}

.stt-result blockquote {
  margin: 0;
  padding-left: 12px;
  border-left: 3px solid var(--teal);
  line-height: 1.6;
}

/* ---------- Modules ---------- */

.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.module-card {
  padding: 18px;
  display: grid;
  gap: 10px;
  opacity: 0.62;
  cursor: not-allowed;
  user-select: none;
}

.module-top { display: flex; align-items: center; justify-content: space-between; }

.module-level {
  padding: 2px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--indigo) 16%, transparent);
  color: var(--indigo);
  font-size: 0.72rem;
  font-weight: 700;
}

.module-lock { font-size: 1rem; filter: grayscale(0.4); }

.module-card h3 { font-size: 1rem; font-weight: 600; }

.module-tag {
  justify-self: start;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

/* ---------- Desktop layout ---------- */

@media (min-width: 960px) {
  .layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 36px;
    align-items: start;
  }

  .nav {
    position: sticky;
    top: 85px;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    overflow: visible;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .nav-link { border-radius: var(--radius-sm); padding: 9px 14px; }

  .section { scroll-margin-top: 85px; }

  .section-head h2 { font-size: 1.5rem; }
}

/* ---------- Animations ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.45); }
  100% { box-shadow: 0 0 0 14px rgba(244, 63, 94, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
