/* =============================================================================
   Learning Portal — Base CSS (self-contained, no external dependencies)
   Clean, modern, mobile-first. System fonts only.
   ============================================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
*::-webkit-tap-highlight-color: transparent;

:root {
  --bg: #f0f4ff;
  --bg-elev: #ffffff;
  --bg-subtle: #e8eef7;
  --fg: #1a2238;
  --fg-muted: #6b7a99;
  --fg-soft: #9ba8c4;
  --border: #dde5f0;
  --border-strong: #c4d0e3;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-fg: #ffffff;
  --primary-soft: #e0e7ff;
  --accent: #f59e0b;
  --success: #10b981;
  --success-bg: #d1fae5;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --shadow-sm: 0 1px 3px rgba(99,102,241,0.08);
  --shadow: 0 4px 6px -1px rgba(99,102,241,0.12), 0 2px 4px -1px rgba(99,102,241,0.06);
  --shadow-lg: 0 10px 25px -5px rgba(99,102,241,0.18), 0 8px 10px -6px rgba(99,102,241,0.10);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 28px;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  --font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --bg-elev: #1e293b;
    --bg-subtle: #334155;
    --fg: #f1f5f9;
    --fg-muted: #94a3b8;
    --fg-soft: #64748b;
    --border: #334155;
    --border-strong: #475569;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: #312e81;
    --success-bg: #064e3b;
    --error-bg: #7f1d1d;
    --warning-bg: #78350f;
    --info-bg: #1e3a8a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --bg-elev: #1e293b; --bg-subtle: #334155;
  --fg: #f1f5f9; --fg-muted: #94a3b8; --fg-soft: #64748b;
  --border: #334155; --border-strong: #475569;
  --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #312e81;
  --success-bg: #064e3b; --error-bg: #7f1d1d; --warning-bg: #78350f; --info-bg: #1e3a8a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -1px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.5), 0 8px 10px -6px rgba(0,0,0,0.3);
}

html { font-size: var(--font-size); -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 1rem; line-height: 1.6;
  background: var(--bg); color: var(--fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}
h1, h2, h3 { font-weight: 700; line-height: 1.2; }
h1 { font-size: 1.75rem; margin: 1rem 0 0.5rem; }
h2 { font-size: 1.375rem; margin: 1.5rem 0 0.5rem; }
p { margin: 0.5rem 0; }
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }
code, pre { font-family: var(--font-mono); font-size: 0.875em; background: var(--bg-subtle); border-radius: var(--radius-sm); padding: 0.125em 0.375em; }
pre { padding: 0.75rem; overflow-x: auto; }
.hint { color: var(--fg-muted); font-size: 0.875rem; margin-bottom: 1rem; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; min-height: 44px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: inherit; font-size: 0.9375rem; font-weight: 700;
  cursor: pointer; text-decoration: none; text-align: center;
  transition: all var(--transition); user-select: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--bg-elev); color: var(--fg); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--primary); }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-link { background: transparent; color: var(--primary); padding: 0.375rem 0.75rem; min-height: 0; border: none; }
.btn-link:hover { color: var(--primary-hover); text-decoration: underline; }

/* Header */
.portal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.625rem 1rem; background: var(--bg-elev);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 100;
}
.header-left, .header-right { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.0625rem; color: var(--fg); }
.back-link { color: var(--fg-muted); font-size: 0.875rem; font-weight: 600; }
.version-badge { background: var(--primary-soft); color: var(--primary); padding: 0.125rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.6875rem; font-weight: 700; }
.user-name { color: var(--fg); font-weight: 700; font-size: 0.9375rem; }

/* Theme toggle (in-header) */
.theme-toggle-wrapper { display: flex; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; height: 36px; }
.theme-toggle { background: transparent; border: none; color: var(--fg-muted); padding: 0 0.625rem; min-height: 0; cursor: pointer; display: flex; align-items: center; gap: 0.25rem; font-size: 0.8125rem; font-weight: 700; font-family: inherit; transition: all var(--transition); border-radius: 0; }
.theme-toggle:hover { background: var(--bg-elev); color: var(--fg); }
.theme-toggle.active { background: var(--primary); color: var(--primary-fg); }
@media (max-width: 480px) { .theme-toggle span:not(.icon) { display: none; } }

/* Admin nav */
.admin-nav { display: flex; gap: 0.25rem; background: var(--bg-elev); padding: 0.5rem 1rem; border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 56px; z-index: 90; }
.admin-nav a { padding: 0.5rem 0.875rem; border-radius: var(--radius); color: var(--fg-muted); font-size: 0.875rem; font-weight: 700; text-decoration: none; white-space: nowrap; transition: all var(--transition); }
.admin-nav a:hover { background: var(--bg-subtle); color: var(--fg); }
.admin-nav a.active { background: var(--primary); color: var(--primary-fg); }

/* Auth pages */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; background: linear-gradient(135deg, var(--primary-soft) 0%, var(--bg) 50%, var(--bg-subtle) 100%); }
.auth-card { background: var(--bg-elev); padding: 2rem 2.25rem; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); max-width: 420px; width: 100%; text-align: center; border: 1px solid var(--border); }
.auth-logo { font-size: 3.5rem; margin-bottom: 0.75rem; line-height: 1; }
.auth-card h1 { font-size: 1.75rem; }
.auth-card .subtitle { color: var(--fg-muted); margin-bottom: 1.5rem; font-size: 0.9375rem; }
.auth-card label { display: block; text-align: left; margin: 0.875rem 0 0.375rem; font-size: 0.8125rem; font-weight: 700; color: var(--fg); }
.auth-card input { width: 100%; padding: 0.75rem 1rem; background: var(--bg); color: var(--fg); border: 2px solid var(--border); border-radius: var(--radius); font-size: 1rem; font-family: inherit; transition: border var(--transition); }
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,0.15); }
.auth-card button { width: 100%; margin-top: 1.25rem; }
.auth-footer { margin-top: 1.5rem; font-size: 0.8125rem; color: var(--fg-soft); }
.setup-tips { margin-top: 1.5rem; padding: 1rem; background: var(--warning-bg); border-radius: var(--radius); font-size: 0.8125rem; text-align: left; border-left: 3px solid var(--warning); }

/* Containers */
.parent-container, .admin-container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

/* Kid grid */
.kid-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0; }
.kid-card { background: var(--bg-elev); border-radius: var(--radius-lg); padding: 1.5rem 1rem; text-align: center; text-decoration: none; color: var(--fg); cursor: pointer; transition: all var(--transition); box-shadow: var(--shadow-sm); border: 2px solid var(--border); display: block; }
.kid-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.kid-avatar { width: 72px; height: 72px; margin: 0 auto 0.75rem; border-radius: 50%; background: var(--bg-subtle); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.kid-avatar img { width: 60px; height: 60px; }
.kid-avatar-mini { width: 1.5rem; height: 1.5rem; vertical-align: middle; margin-right: 0.375rem; }
.kid-name { font-size: 1.125rem; font-weight: 700; margin-bottom: 0.125rem; }
.kid-meta { font-size: 0.75rem; color: var(--fg-muted); margin-bottom: 0.75rem; }
.kid-start-btn { width: 100%; pointer-events: none; }
.empty-state { text-align: center; padding: 3rem 1rem; background: var(--bg-elev); border-radius: var(--radius); color: var(--fg-muted); border: 2px dashed var(--border-strong); }
.parent-actions { margin: 1.5rem 0; text-align: center; }

/* Forms */
.kid-form, .user-form { background: var(--bg-elev); padding: 1.5rem; border-radius: var(--radius-lg); margin-bottom: 1.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; margin-bottom: 0.375rem; font-weight: 700; font-size: 0.8125rem; }
.form-row input, .form-row select { width: 100%; padding: 0.625rem 0.875rem; background: var(--bg); color: var(--fg); border: 2px solid var(--border); border-radius: var(--radius); font-size: 0.9375rem; font-family: inherit; transition: border var(--transition); }
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,0.15); }

/* Tables */
.kid-table, .user-table, .audit-table { width: 100%; background: var(--bg-elev); border-collapse: collapse; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.kid-table th, .user-table th, .audit-table th { background: var(--bg-subtle); padding: 0.875rem 1rem; text-align: left; font-size: 0.6875rem; font-weight: 800; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kid-table td, .user-table td, .audit-table td { padding: 0.875rem 1rem; border-top: 1px solid var(--border); font-size: 0.875rem; }
.kid-table tr:hover, .user-table tr:hover, .audit-table tr:hover { background: var(--bg-subtle); }
.role-badge { padding: 0.125rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; }
.role-admin { background: var(--warning-bg); color: var(--warning); }
.role-parent { background: var(--info-bg); color: var(--info); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat-card { background: var(--bg-elev); padding: 1.5rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); text-align: center; border: 1px solid var(--border); transition: transform var(--transition); }
.stat-card:hover { transform: translateY(-2px); }
.stat-label { font-size: 0.6875rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; font-weight: 700; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); }
.admin-links { list-style: none; padding: 0; }
.admin-links li { padding: 0.875rem 1rem; background: var(--bg-elev); border-radius: var(--radius); margin-bottom: 0.5rem; border: 1px solid var(--border); }
.admin-links li:hover { border-color: var(--primary); }
.admin-links a { color: var(--primary); font-weight: 700; margin-right: 0.5rem; }

/* Theme picker */
.kid-selector { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.kid-tab { padding: 0.5rem 1rem; border-radius: var(--radius); background: var(--bg-elev); border: 2px solid var(--border); text-decoration: none; color: var(--fg); font-weight: 700; font-size: 0.9375rem; display: inline-flex; align-items: center; gap: 0.375rem; transition: all var(--transition); }
.kid-tab:hover { border-color: var(--primary); }
.kid-tab.active { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0; }
.theme-card { background: var(--bg-elev); border: 3px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; position: relative; transition: all var(--transition); }
.theme-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.theme-card.selected { border-color: var(--primary); }
.theme-swatch { height: 80px; display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.theme-circle { width: 48px; height: 48px; border-radius: 50%; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.theme-info { padding: 0.875rem 1rem; }
.theme-name { font-weight: 700; font-size: 1.0625rem; margin-bottom: 0.25rem; }
.theme-badge { display: inline-block; padding: 0.25rem 0.625rem; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-size: 0.75rem; font-weight: 800; }
.theme-select { padding: 0.375rem 0.5rem; border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font-family: inherit; font-size: 0.875rem; }

/* Kid page (themed) */
.kid-page { background: var(--kid-background, var(--bg)); color: var(--kid-text, var(--fg)); min-height: 100vh; }
.kid-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1.25rem; background: var(--kid-card, var(--bg-elev)); box-shadow: var(--shadow-sm); }
.kid-header .header-left { display: flex; align-items: center; gap: 0.625rem; font-weight: 700; font-size: 1.125rem; }
.kid-avatar-header { width: 2.5rem; height: 2.5rem; border-radius: 50%; }
.exit-btn { background: var(--kid-error, var(--error)); color: #fff; padding: 0.5rem 1rem; border-radius: var(--radius); text-decoration: none; font-weight: 700; font-size: 0.9375rem; min-height: 44px; display: inline-flex; align-items: center; }
.kid-container { max-width: 900px; margin: 0 auto; padding: 1.5rem; text-align: center; }
.kid-greeting { font-size: 2rem; color: var(--kid-accent, var(--primary)); margin-bottom: 1.5rem; font-weight: 800; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.module-card { background: var(--kid-card, var(--bg-elev)); padding: 1.5rem 1rem; border-radius: var(--radius-lg); text-decoration: none; color: var(--kid-text, var(--fg)); box-shadow: var(--shadow); transition: all var(--transition); display: block; border: 2px solid var(--kid-border, var(--border)); text-align: center; }
.module-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.module-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.module-name { font-weight: 700; font-size: 0.9375rem; }

/* Flash messages */
.flash-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 1000; max-width: 360px; display: flex; flex-direction: column; gap: 0.5rem; }
.flash { padding: 0.75rem 1rem; border-radius: var(--radius); color: #fff; font-size: 0.875rem; font-weight: 700; box-shadow: var(--shadow-lg); }
.flash-success { background: var(--success); }
.flash-error { background: var(--error); }
.flash-info { background: var(--info); }
.flash-warning { background: var(--warning); }

/* Auto-start prompt */
.autostart-prompt { margin-top: 1rem; padding: 1.5rem; background: var(--bg-subtle); border-radius: var(--radius); }
.autostart-prompt .btn-primary { width: 100%; }
.autostart-alt { margin-top: 1rem; font-size: 0.875rem; color: var(--fg-muted); }

/* Scanner terminal */
.scanner-terminal { background: #0f172a; color: #e2e8f0; font-family: var(--font-mono); font-size: 0.8125rem; padding: 1rem; border-radius: var(--radius); max-height: 400px; overflow-y: auto; border: 1px solid #334155; line-height: 1.5; }
.scanner-terminal .stage-pass { color: #10b981; }
.scanner-terminal .stage-fail { color: #ef4444; font-weight: 700; }
.scanner-terminal .stage-warn { color: #f59e0b; }
.scanner-terminal .stage-info { color: #60a5fa; }
.scanner-terminal .stage-detail { color: #94a3b8; padding-left: 1.5rem; }
.upload-drop-zone { border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 2rem; text-align: center; cursor: pointer; transition: all var(--transition); background: var(--bg-elev); }
.upload-drop-zone:hover { border-color: var(--primary); background: var(--bg-subtle); }
.module-status-badge { padding: 0.125rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; }
.status-enabled { background: var(--success-bg); color: var(--success); }
.status-disabled { background: var(--error-bg); color: var(--error); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { position: relative; background: var(--bg-elev); padding: 1.5rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); max-width: 420px; width: 100%; border: 1px solid var(--border); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Responsive */
@media (max-width: 768px) {
  .portal-header { padding: 0.5rem 0.875rem; }
  .parent-container, .admin-container { padding: 1rem; }
  .kid-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
  .auth-card { padding: 1.5rem 1.25rem; }
  .module-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .flash-container { left: 1rem; right: 1rem; max-width: none; }
}
@media (max-width: 480px) {
  .portal-header { flex-wrap: wrap; gap: 0.5rem; }
  .kid-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
