:root {
  color-scheme: light;
  --ink: #152033;
  --muted: #657187;
  --line: #dce2ea;
  --paper: #f5f7fa;
  --surface: #ffffff;
  --navy: #111b2b;
  --navy-2: #1a2a41;
  --teal: #117c7b;
  --teal-soft: #dff4f1;
  --amber: #d9912b;
  --amber-soft: #fff1dc;
  --danger: #b33c49;
  --shadow: 0 18px 48px rgba(17, 27, 43, .12);
  font-family: "Tahoma", "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-size: 16px; }
button, input, textarea, select { font: inherit; }
button, .button-link { cursor: pointer; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 80% 10%, #244560 0, transparent 38%), linear-gradient(145deg, #0d1726, #17263a 60%, #0c5b5e); }
.login-card { width: min(440px, 100%); background: rgba(255,255,255,.98); border: 1px solid rgba(255,255,255,.4); border-radius: 28px; padding: 38px; box-shadow: 0 30px 90px rgba(0,0,0,.28); }
.login-card h1 { font-size: 2.4rem; margin: 8px 0; letter-spacing: -.04em; }
.login-copy { color: var(--muted); line-height: 1.8; margin: 0 0 24px; }
.brand-mark { width: 62px; height: 62px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--teal), #0d5a67); border-radius: 18px 18px 6px 18px; box-shadow: 0 10px 30px rgba(17,124,123,.28); font: 700 1.8rem/1 Georgia, serif; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px 13px 4px 13px; font-size: 1.25rem; box-shadow: none; flex: none; }
.eyebrow { margin: 0; color: var(--teal); font-size: .78rem; font-weight: 800; letter-spacing: .04em; }

label { display: grid; gap: 8px; color: #344158; font-weight: 700; font-size: .9rem; }
input, textarea, select { width: 100%; border: 1px solid #cad2dd; border-radius: 11px; background: #fff; color: var(--ink); padding: 12px 13px; outline: none; transition: border .18s, box-shadow .18s; }
input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(17,124,123,.13); }
textarea { resize: vertical; line-height: 1.75; }
.login-card form { display: grid; gap: 16px; }
.primary, .secondary, .quiet, .icon-button { border: 0; border-radius: 10px; min-height: 42px; padding: 10px 16px; font-weight: 800; }
.primary { color: #fff; background: var(--teal); box-shadow: 0 6px 16px rgba(17,124,123,.18); }
.primary:hover { background: #0c6a69; }
.secondary { color: var(--ink); background: #fff; border: 1px solid var(--line); }
.secondary:hover { border-color: #aab5c2; background: #f9fafb; }
.quiet { color: var(--muted); background: transparent; }
.quiet:hover { color: var(--ink); background: rgba(17,27,43,.05); }
.wide { width: 100%; margin-top: 4px; }
.form-error { min-height: 20px; color: var(--danger); margin: 0; font-size: .85rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--navy); color: #eaf0f7; padding: 24px 16px; display: flex; flex-direction: column; z-index: 20; }
.brand-row { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }
.brand-row strong { display: block; font-size: 1.05rem; }
.brand-row small { display: block; color: #91a0b6; margin-top: 4px; font-size: .72rem; }
nav { display: grid; gap: 6px; }
.nav-item { border: 0; background: transparent; color: #aeb8c8; min-height: 47px; padding: 0 13px; border-radius: 10px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; text-align: right; font-weight: 700; }
.nav-item span { color: #6e829b; font-size: 1.1rem; }
.nav-item kbd { font-family: inherit; font-size: .72rem; color: #8391a6; background: rgba(255,255,255,.07); border-radius: 20px; padding: 3px 7px; }
.nav-item:hover, .nav-item.active { color: #fff; background: var(--navy-2); }
.nav-item.active span { color: #63d1c9; }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.09); padding-top: 16px; display: grid; gap: 5px; }
.sidebar .quiet { color: #94a2b5; text-align: right; }
.sync-state { display: flex; align-items: center; gap: 8px; color: #aeb8c8; padding: 8px 12px; font-size: .82rem; }
.sync-state i { width: 8px; height: 8px; border-radius: 50%; background: #57c7a8; box-shadow: 0 0 0 4px rgba(87,199,168,.1); }
.sync-state.pending i { background: var(--amber); }
.sync-state.offline i { background: var(--danger); }

main { min-width: 0; }
.topbar { min-height: 92px; display: grid; grid-template-columns: auto minmax(240px, 480px) auto; align-items: center; gap: 18px; padding: 18px clamp(20px,4vw,52px); background: rgba(245,247,250,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(14px); }
.page-heading { margin-left: auto; }
.page-heading p { margin: 0 0 4px; color: var(--muted); font-size: .76rem; }
.page-heading h1 { margin: 0; font-size: 1.6rem; letter-spacing: -.02em; }
.search { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; font-weight: 400; }
.search input { border: 0; box-shadow: none; padding-inline: 2px; }
.search span { font-size: 1.35rem; color: var(--muted); transform: rotate(-18deg); }
.topbar .primary { display: flex; align-items: center; gap: 6px; }
.menu-button { display: none; }

.content { padding: 28px clamp(20px,4vw,52px) 64px; max-width: 1500px; margin: 0 auto; }
.toolbar, .section-intro { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); color: var(--muted); background: #fff; border-radius: 999px; padding: 7px 13px; font-weight: 700; font-size: .82rem; }
.chip.active { color: #075f5e; border-color: #91d8d1; background: var(--teal-soft); }
.selection-bar { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; padding: 11px 15px; border: 1px solid #f0c98e; background: var(--amber-soft); border-radius: 12px; color: #75490b; }
.selection-bar .quiet { margin-right: auto; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.snippet-card { position: relative; min-height: 240px; display: flex; flex-direction: column; gap: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; transition: transform .18s, box-shadow .18s, border-color .18s; }
.snippet-card:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(17,27,43,.08); border-color: #c4ceda; }
.snippet-card.selected { border-color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); }
.snippet-card header { display: flex; gap: 12px; align-items: start; }
.snippet-card h3 { margin: 0; line-height: 1.45; font-size: 1rem; flex: 1; }
.select-check { appearance: none; width: 20px; height: 20px; border: 1px solid #b6c0cd; border-radius: 6px; padding: 0; flex: none; }
.select-check:checked { background: var(--teal); border-color: var(--teal); box-shadow: inset 0 0 0 4px #fff; }
.quote { margin: 0; color: #3d485b; line-height: 1.75; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.snippet-card footer { margin-top: auto; display: grid; gap: 10px; }
.meta-row { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .74rem; }
.source-badge, .space-badge { border-radius: 999px; padding: 4px 8px; font-size: .7rem; font-weight: 800; }
.source-badge { background: #edf1f6; color: #4d5c70; }
.source-badge.chatgpt { background: #e5f3ee; color: #14674f; }
.space-badge { background: var(--amber-soft); color: #7c510f; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { color: #5c687a; background: #f1f4f7; border-radius: 7px; padding: 4px 7px; font-size: .7rem; }
.card-open { position: absolute; inset: 0; border: 0; background: transparent; border-radius: inherit; }
.snippet-card header, .snippet-card footer, .select-check { position: relative; z-index: 2; }
.empty-state { text-align: center; display: grid; justify-items: center; padding: 80px 20px; }
.empty-glyph { width: 74px; height: 74px; border-radius: 24px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal); font: 700 3.3rem/1 Georgia, serif; }
.empty-state h2 { margin: 18px 0 7px; }
.empty-state p { max-width: 460px; color: var(--muted); line-height: 1.7; margin: 0 0 20px; }
.section-intro h2 { margin: 0 0 5px; }
.section-intro p { margin: 0; color: var(--muted); }
.list-stack { display: grid; gap: 12px; }
.list-row { background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 17px 19px; display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 20px; }
.list-row h3, .article-card h3 { margin: 0 0 6px; }
.list-row p, .article-card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.6; }
.stat-pair { display: flex; gap: 16px; color: var(--muted); font-size: .78rem; }
.article-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }
.article-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: grid; gap: 16px; }
.article-card footer { display: flex; align-items: center; justify-content: space-between; }
.status-pill { background: #edf1f6; color: #506074; border-radius: 999px; padding: 5px 9px; font-size: .72rem; font-weight: 800; }

.usage-layout { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 16px; }
.budget-card, .metric-card, .settings-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.budget-number { display: flex; align-items: baseline; gap: 10px; margin: 14px 0 20px; }
.budget-number strong { font: 700 2.4rem/1 "Segoe UI", sans-serif; }
.budget-number span { color: var(--muted); }
.progress { height: 10px; border-radius: 999px; background: #e9eef3; overflow: hidden; direction: ltr; }
.progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--teal), var(--amber)); border-radius: inherit; }
.thresholds { display: flex; justify-content: space-between; color: var(--muted); font-size: .68rem; margin-top: 8px; }
.metric-card { display: flex; flex-direction: column; gap: 10px; }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { font-size: 2rem; }
.principle-note { margin-top: 18px; background: var(--navy); color: #dfe8f3; border-radius: 14px; padding: 16px 20px; display: flex; gap: 10px; line-height: 1.7; }
.principle-note strong { color: #6ad1ca; white-space: nowrap; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.settings-card { display: flex; flex-direction: column; gap: 18px; align-items: start; }
.settings-card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.settings-card p { margin: 0; color: var(--muted); line-height: 1.7; }
.settings-card pre { max-width: 100%; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; background: var(--navy); color: #9be2d9; padding: 12px; border-radius: 10px; }
.button-link { display: inline-flex; align-items: center; text-decoration: none; }
.muted { color: var(--muted); font-size: .83rem; }

dialog { border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(10,18,30,.58); backdrop-filter: blur(4px); }
.modal { width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 28px); }
.modal-card { background: #fff; border-radius: 22px; padding: 24px; box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 28px); }
.modal-card > header { display: flex; align-items: start; justify-content: space-between; margin-bottom: 22px; }
.modal-card h2 { margin: 5px 0 0; }
.icon-button { min-width: 42px; padding: 7px; color: var(--muted); background: #eef2f6; font-size: 1.25rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.organized-field { border: 1px solid #c8e6e2; background: #f2fbf9; padding: 14px; border-radius: 13px; }
.modal-actions { display: flex; align-items: center; gap: 9px; margin-top: 20px; }
.spacer { flex: 1; }
.workspace-modal { width: min(1180px, calc(100vw - 24px)); height: min(820px, calc(100vh - 24px)); background: #fff; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.workspace-shell { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.workspace-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.workspace-head input { border: 0; font-weight: 800; font-size: 1.2rem; padding: 8px; }
.workspace-head .icon-button { margin-right: auto; }
.workspace-body { min-height: 0; display: grid; grid-template-columns: minmax(250px, .75fr) minmax(360px, 1.25fr); }
.source-pane { border-left: 1px solid var(--line); padding: 20px; overflow: auto; background: #f8fafc; }
.source-pane h3, .work-pane h3 { margin: 0 0 14px; font-size: .92rem; }
.source-mini { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 12px; margin-bottom: 9px; }
.source-mini strong { display: block; margin-bottom: 6px; font-size: .85rem; }
.source-mini p { margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.work-pane { padding: 20px; overflow: auto; display: grid; align-content: start; gap: 18px; }
.workspace-section { border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.workspace-section:last-child { border: 0; }
.message-list { display: grid; gap: 9px; max-height: 280px; overflow: auto; }
.message { border-radius: 12px; padding: 11px 13px; line-height: 1.65; white-space: pre-wrap; }
.message.user { background: var(--teal-soft); margin-left: 12%; }
.message.assistant { background: #eef2f6; margin-right: 12%; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input, .inline-form select { flex: 1; }
.toast-region { position: fixed; left: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { color: #fff; background: var(--navy); border-right: 4px solid #5ad0c6; border-radius: 10px; padding: 12px 15px; box-shadow: var(--shadow); max-width: 360px; line-height: 1.5; }
.toast.error { border-color: #e55d6c; }

@media (max-width: 1100px) {
  .usage-layout { grid-template-columns: 1fr 1fr; }
  .budget-card { grid-column: 1 / -1; }
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; right: 0; transform: translateX(105%); width: min(280px, 86vw); transition: transform .22s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .topbar { min-height: auto; grid-template-columns: auto 1fr auto; padding: 12px 14px; gap: 10px; }
  .menu-button { display: inline-grid; place-items: center; }
  .page-heading { margin-left: 0; }
  .page-heading p { display: none; }
  .page-heading h1 { font-size: 1.2rem; }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .topbar .primary span:last-child { display: none; }
  .content { padding: 20px 14px 50px; }
  .toolbar, .section-intro { align-items: start; }
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; max-width: 70vw; padding-bottom: 5px; }
  .card-grid { grid-template-columns: 1fr; }
  .snippet-card { min-height: 210px; }
  .list-row { grid-template-columns: 1fr auto; }
  .stat-pair { grid-column: 1 / -1; grid-row: 2; }
  .workspace-modal { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
  .workspace-body { grid-template-columns: 1fr; }
  .source-pane { border-left: 0; border-bottom: 1px solid var(--line); max-height: 32vh; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .quiet { width: 100%; }
}
@media (max-width: 520px) {
  .login-card { padding: 28px 22px; border-radius: 22px; }
  .usage-layout { grid-template-columns: 1fr; }
  .budget-card { grid-column: auto; }
  .thresholds { font-size: .6rem; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filter-chips { max-width: 100%; }
  .principle-note { align-items: start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
