/* ── StoryTrackr App ── Dark-first design system ── */
:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface-2: #263347;
  --border:    #334155;
  --border-2:  #475569;
  --text:      #f1f5f9;
  --text-2:    #cbd5e1;
  --muted:     #94a3b8;
  --primary:   #6366f1;
  --primary-d: #4f46e5;
  --primary-l: #818cf8;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --cyan:      #06b6d4;
  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.35);
  --nav-h:     60px;
  --bottom-h:  64px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
a  { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
input, textarea, select, button { font-family: inherit; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p  { color: var(--text-2); }

/* ── Splash ── */
.splash { display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; gap:1.5rem; }
.splash-logo { font-size:2rem; font-weight:800; background:linear-gradient(135deg,#8b5cf6,#6366f1); -webkit-background-clip:text; -webkit-text-fill-color:transparent; }
.spinner { width:28px; height:28px; border:3px solid var(--border); border-top-color:var(--primary); border-radius:50%; animation:spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout ── */
#root { height: 100%; }
.app-layout { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Top Header */
.app-header {
  height: var(--nav-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem; flex-shrink: 0; position: relative; z-index: 50;
}
.app-header-logo { font-weight: 800; font-size: 1.1rem; background: linear-gradient(135deg,#8b5cf6,#6366f1); -webkit-background-clip:text; -webkit-text-fill-color:transparent; }
.app-header-nav { display: flex; align-items: center; gap: .25rem; }
.header-nav-btn {
  background: none; border: none; color: var(--muted); font-size: .85rem; font-weight: 500;
  padding: .4rem .75rem; border-radius: var(--radius-xs); cursor: pointer; transition: all .15s;
}
.header-nav-btn:hover, .header-nav-btn.active { background: var(--surface-2); color: var(--text); }
.header-nav-btn.active { color: var(--primary); }
.header-actions { display: flex; align-items: center; gap: .5rem; }
.avatar-btn {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); border: none;
  cursor: pointer; font-weight: 700; font-size: .8rem; color: white; display: flex; align-items: center; justify-content: center;
}

/* Main content */
.app-main { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: var(--bottom-h); }
@media (min-width: 768px) { .app-main { padding-bottom: 0; } }

/* Bottom nav (mobile) */
.bottom-nav {
  height: var(--bottom-h); background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: stretch; flex-shrink: 0;
}
@media (min-width: 768px) { .bottom-nav { display: none; } }
.bottom-nav-btn {
  flex: 1; background: none; border: none; color: var(--muted); font-size: .65rem; font-weight: 500;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; transition: color .15s;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-btn.active { color: var(--primary); }
.bottom-nav-btn svg { width: 20px; height: 20px; }

/* Demo banner */
.demo-banner {
  background: linear-gradient(90deg, #7c3aed, #6366f1);
  color: white; text-align: center; font-size: .85rem; font-weight: 600;
  padding: .5rem 1rem; display: flex; align-items: center; justify-content: center; gap: .75rem;
}
.demo-banner a { color: white; text-decoration: underline; font-weight: 700; }

/* ── Containers ── */
.page { padding: 1.5rem; max-width: 1000px; margin: 0 auto; }
.page-sm { padding: 1.5rem; max-width: 480px; margin: 0 auto; }

/* ── Cards ── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.card-body { padding: 1.25rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1.25rem; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: all .2s; white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-d); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: #7f1d1d; color: white; border-color: #991b1b; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .4rem .9rem; font-size: .8rem; border-radius: var(--radius-xs); }
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-label { font-size: .875rem; font-weight: 500; color: var(--text-2); }
.form-input {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .625rem .875rem; font-size: .95rem; color: var(--text); width: 100%;
  transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-input::placeholder { color: var(--muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { background: var(--bg); }
.form-error { font-size: .8rem; color: var(--red); }
.form-hint  { font-size: .8rem; color: var(--muted); }
.form-stack { display: flex; flex-direction: column; gap: 1rem; }

/* ── Auth pages ── */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { font-size: 1.8rem; font-weight: 800; background: linear-gradient(135deg,#8b5cf6,#6366f1); -webkit-background-clip:text; -webkit-text-fill-color:transparent; margin-bottom: 2rem; text-align: center; }
.auth-title { font-size: 1.4rem; font-weight: 700; margin-bottom: .25rem; }
.auth-sub   { color: var(--muted); font-size: .9rem; margin-bottom: 1.75rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: .875rem; color: var(--muted); }
.auth-footer a { color: var(--primary-l); }
.auth-divider { text-align: center; color: var(--muted); font-size: .8rem; margin: 1rem 0; position: relative; }
.auth-divider::before { content:''; position:absolute; left:0; top:50%; width:100%; height:1px; background:var(--border); }
.auth-divider span { background: var(--surface); padding: 0 .75rem; position: relative; }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: .75rem 1rem; font-size: .9rem; font-weight: 500; color: var(--muted);
  cursor: pointer; white-space: nowrap; transition: all .15s; margin-bottom: -1px;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover { color: var(--text-2); }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center; padding: .15rem .55rem;
  border-radius: 999px; font-size: .75rem; font-weight: 600;
}
.badge-green  { background: #14532d; color: #86efac; }
.badge-blue   { background: #1e3a5f; color: #93c5fd; }
.badge-purple { background: #3b0764; color: #d8b4fe; }
.badge-gray   { background: var(--surface-2); color: var(--muted); }
.badge-red    { background: #450a0a; color: #fca5a5; }
.badge-yellow { background: #451a03; color: #fcd34d; }

/* ── Student cards ── */
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 1rem; }
.student-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: .875rem;
}
.student-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.student-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--primary);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; overflow: hidden; color: white;
}
.student-avatar img { width:100%; height:100%; object-fit:cover; }
.student-info { flex: 1; min-width: 0; }
.student-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.student-meta { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.student-status { flex-shrink: 0; }

/* ── Interaction list ── */
.interaction-item {
  display: flex; gap: .875rem; padding: 1rem 0; border-bottom: 1px solid var(--border);
}
.interaction-item:last-child { border-bottom: none; }
.interaction-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: .4rem; }
.interaction-body { flex: 1; }
.interaction-meta { font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
.interaction-summary { font-size: .9rem; color: var(--text-2); line-height: 1.5; }
.interaction-actions { display: flex; gap: .5rem; margin-top: .5rem; }

/* ── Dashboard stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: .85rem; color: var(--muted); margin-top: .25rem; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: calc(var(--bottom-h) + 1rem); left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
@media (min-width: 768px) { .toast-container { bottom: 1.5rem; } }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  padding: .75rem 1.25rem; font-size: .9rem; font-weight: 500; max-width: 320px;
  animation: slideUp .2s ease; pointer-events: auto; box-shadow: var(--shadow);
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--primary); }
@keyframes slideUp { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 1rem;
}
@media (min-width: 480px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
.modal-header { padding: 1.25rem 1.25rem 0; display: flex; justify-content: space-between; align-items: flex-start; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.25rem; cursor: pointer; line-height: 1; padding: .25rem; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0 1.25rem 1.25rem; display: flex; gap: .75rem; justify-content: flex-end; }

/* ── Loading / Empty ── */
.loading-state { display: flex; align-items: center; justify-content: center; padding: 4rem; flex-direction: column; gap: 1rem; }
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-title { font-size: 1.1rem; font-weight: 600; margin-bottom: .5rem; }
.empty-desc { color: var(--muted); font-size: .9rem; max-width: 320px; margin: 0 auto; }

/* ── Onboarding ── */
.onboarding-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 2rem 1rem; }
.onboarding-header { width: 100%; max-width: 560px; margin-bottom: 2rem; }
.steps-indicator { display: flex; align-items: center; gap: .5rem; }
.step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.step-dot.active { background: var(--primary); transform: scale(1.3); }
.step-dot.done { background: var(--green); }
.onboarding-card { width: 100%; max-width: 560px; }

/* ── Student detail ── */
.student-detail-header { display: flex; align-items: flex-start; gap: 1.25rem; padding: 1.5rem; border-bottom: 1px solid var(--border); }
.student-detail-avatar { width: 80px; height: 80px; border-radius: 50%; flex-shrink: 0; overflow: hidden; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; color: white; }
.student-detail-avatar img { width:100%; height:100%; object-fit:cover; }
.student-detail-info h1 { font-size: 1.4rem; }
.student-detail-meta { color: var(--muted); font-size: .875rem; margin-top: .25rem; }

/* ── Settings ── */
.settings-section { margin-bottom: 2rem; }
.settings-title { font-size: 1rem; font-weight: 700; color: var(--primary); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .05em; font-size: .75rem; }

/* ── CSV import ── */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2.5rem; text-align: center; cursor: pointer; transition: all .15s;
}
.dropzone:hover, .dropzone.active { border-color: var(--primary); background: rgba(99,102,241,.05); }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { padding: .75rem 1rem; text-align: left; font-weight: 600; background: var(--surface-2); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
td { padding: .875rem 1rem; border-bottom: 1px solid var(--border); color: var(--text-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ── Select Org ── */
.org-picker { display: flex; flex-direction: column; gap: .75rem; }
.org-option {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 1rem;
}
.org-option:hover { border-color: var(--primary); }
.org-icon { width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; color: white; }

/* ── Utility ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .75rem; }
.gap-3 { gap: 1.25rem; }
.text-muted { color: var(--muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .78rem; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .75rem; }
.mt-3 { margin-top: 1.25rem; }
.mt-4 { margin-top: 2rem; }
.mb-2 { margin-bottom: .75rem; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.rounded { border-radius: var(--radius); }
.p-3 { padding: 1.25rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.tag { display: inline-flex; align-items: center; background: var(--surface-2); border: 1px solid var(--border); padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; color: var(--text-2); gap: .3rem; }
.tag-remove { background:none; border:none; cursor:pointer; color:var(--muted); font-size:.9rem; line-height:1; padding:0; }
.goal-item { display: flex; align-items: center; gap: .75rem; padding: .6rem; background: var(--surface-2); border-radius: var(--radius-xs); }
.goal-check { width: 18px; height: 18px; border-radius: 4px; border: 2px solid var(--border); cursor: pointer; flex-shrink: 0; background: none; display: flex; align-items: center; justify-content: center; }
.goal-check.done { background: var(--green); border-color: var(--green); color: white; }
.goal-text { flex: 1; font-size: .875rem; }
.goal-text.done { text-decoration: line-through; color: var(--muted); }

/* ── Responsive ── */
@media (max-width: 767px) {
  .app-header-nav { display: none; }
  .page { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .bottom-nav { display: none; }
}
