/* ScholarMind AI — shared design system */
:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #f0f2f9; --border: #e1e5f0;
  --text: #0f172a; --muted: #566079; --primary: #4f46e5; --primary-hover: #4338ca; --primary-soft: #eef0ff;
  --on-primary: #ffffff; --blue: #2563eb; --violet: #7c3aed;
  --success: #15803d; --success-soft: #e7f6ec; --danger: #dc2626; --danger-soft: #fdecec; --warn: #b45309; --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --radius: 14px; --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0b1020; --surface: #121a30; --surface-2: #19233f; --border: #263252; --text: #e8ecf7; --muted: #9aa7c6; --primary: #6366f1; --primary-hover: #7a7df5; --primary-soft: #1d2447; --success: #4ade80; --success-soft: #12301f; --danger: #f87171; --danger-soft: #3a1b1f; --warn: #fbbf24; --warn-soft: #33270f; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0b1020; --surface: #121a30; --surface-2: #19233f; --border: #263252; --text: #e8ecf7; --muted: #9aa7c6; --primary: #6366f1; --primary-hover: #7a7df5; --primary-soft: #1d2447; --success: #4ade80; --success-soft: #12301f; --danger: #f87171; --danger-soft: #3a1b1f; --warn: #fbbf24; --warn-soft: #33270f; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25); color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.6 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
p { margin: 0 0 .8rem; }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
.icon { flex: none; vertical-align: middle; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; border-radius: 8px; z-index: 100; } .skip:focus { left: 8px; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; } .row.between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 1rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px; padding: .55rem 1.1rem; border: 1px solid transparent; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; transition: background .15s, border-color .15s, transform .05s; -webkit-tap-highlight-color: transparent; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); } .btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); } .btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); } .btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; } .btn-danger:hover { filter: brightness(1.08); }
.btn-sm { min-height: 36px; padding: .3rem .75rem; font-size: .875rem; }
.btn-lg { min-height: 52px; padding: .75rem 1.5rem; font-size: 1.05rem; }
.btn-icon { min-width: 44px; padding: .5rem; } .btn-sm.btn-icon { min-width: 36px; padding: .3rem; }
.btn-block { width: 100%; }
.btn[aria-busy="true"]::after { content: ""; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }

/* forms */
.field { display: block; margin-bottom: 1rem; } .field > span:first-child { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field .hint { display: block; font-size: .8rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }
input, select, textarea { width: 100%; min-height: 44px; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; min-height: 0; height: 1.15rem; accent-color: var(--primary); flex: none; }
input[type="range"] { padding: 0; accent-color: var(--primary); min-height: 32px; }
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; min-height: 44px; }
.pw-wrap { position: relative; } .pw-wrap input { padding-right: 3rem; }
.pw-wrap button { position: absolute; right: 2px; top: 2px; bottom: 2px; width: 44px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: .7rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.form-ok { background: var(--success-soft); color: var(--success); border-radius: var(--radius-sm); padding: .7rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.field-error { color: var(--danger); font-size: .82rem; margin-top: .25rem; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card-flat { box-shadow: none; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-sm { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; font-size: .78rem; font-weight: 600; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.badge-ok { background: var(--success-soft); color: var(--success); } .badge-warn { background: var(--warn-soft); color: var(--warn); } .badge-danger { background: var(--danger-soft); color: var(--danger); }
.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: .92rem; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; } .meter > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; } .meter.warn > i { background: var(--warn); } .meter.full > i { background: var(--danger); }
.table-wrap { overflow-x: auto; max-width: 100%; margin: .6rem 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; } th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; } th { background: var(--surface-2); font-weight: 600; white-space: nowrap; } tr:last-child td { border-bottom: 0; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; scrollbar-width: none; }
.tab { padding: .6rem 1rem; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; min-height: 44px; } .tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.spinner { width: 1.4rem; height: 1.4rem; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.loading { display: flex; justify-content: center; padding: 3rem 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* toasts and dialogs */
#toasts { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: .5rem; z-index: 200; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: .75rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .93rem; animation: rise .2s ease-out; }
.toast-error { background: var(--danger); color: #fff; } .toast-success { background: var(--success); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; background: var(--surface); color: var(--text); width: min(92vw, 440px); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.dialog::backdrop { background: rgba(8, 12, 28, .55); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* logo */
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none !important; letter-spacing: -.02em; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand b { color: var(--primary); font-weight: 800; }

/* rendered markdown (AI answers, notes) */
.md { overflow-wrap: anywhere; line-height: 1.65; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h2, .md h3, .md h4, .md h5 { margin: 1.1em 0 .4em; } .md h2 { font-size: 1.25rem; } .md h3 { font-size: 1.1rem; } .md h4, .md h5 { font-size: 1rem; }
.md ul, .md ol { padding-left: 1.4rem; margin: .4rem 0 .8rem; } .md li { margin: .2rem 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .12em .35em; border-radius: 5px; }
.md pre { position: relative; background: #0d1326; color: #e6eaf7; padding: .9rem 1rem; border-radius: var(--radius-sm); overflow-x: auto; margin: .7rem 0; font-size: .88rem; line-height: 1.5; }
.md pre code { background: none; padding: 0; color: inherit; }
.md blockquote { margin: .6rem 0; padding: .2rem 1rem; border-left: 3px solid var(--primary); color: var(--muted); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.code-copy { position: absolute; top: 6px; right: 6px; min-height: 28px; padding: .1rem .5rem; font-size: .75rem; background: #ffffff1f; color: #fff; border: 0; border-radius: 6px; cursor: pointer; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
