:root {
  color-scheme: dark;
  --bg: #07101d; --surface: rgba(14, 28, 48, .8); --surface-strong: #101f34;
  --border: rgba(151, 180, 214, .17); --text: #eef6ff; --muted: #93a8c2;
  --cyan: #58e6d9; --violet: #9c7cff; --danger: #ff7f9b; --success: #82edb3;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--text); background: radial-gradient(circle at 50% -20%, #19345a 0, var(--bg) 50%); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:disabled { cursor: not-allowed; opacity: .45; }
.aurora { position: fixed; inset: 0; z-index: -1; pointer-events: none; background: radial-gradient(circle at 12% 18%, rgba(88,230,217,.14), transparent 30%), radial-gradient(circle at 86% 6%, rgba(156,124,255,.16), transparent 32%); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(25px, 4vw, 34px); line-height: 1.15; }
h2 { margin-bottom: 0; font-size: 18px; }
.muted { color: var(--muted); line-height: 1.6; }
.eyebrow { margin: 0 0 7px; color: var(--cyan); font-size: 10px; font-weight: 800; letter-spacing: .16em; }

/* Authentication views */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 440px); padding: 38px; border: 1px solid var(--border); border-radius: 24px; background: rgba(11,24,42,.86); box-shadow: var(--shadow); backdrop-filter: blur(20px); }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; color: #061018; font-size: 25px; font-weight: 900; background: linear-gradient(135deg, var(--cyan), #9fffdc 45%, var(--violet)); box-shadow: 0 0 32px rgba(88,230,217,.24); }
.brand-mark-small { width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto; font-size: 18px; }
form label, .editor-meta label { display: block; margin: 15px 0 7px; color: #c8d6e7; font-size: 12px; font-weight: 700; }
input, textarea, select { width: 100%; padding: 12px 13px; color: var(--text); border: 1px solid var(--border); border-radius: 10px; outline: none; background: rgba(4,12,24,.68); transition: border-color 160ms, box-shadow 160ms; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(88,230,217,.11); }
.primary-button { width: 100%; margin-top: 25px; padding: 13px 18px; border: 0; border-radius: 11px; color: #061018; font-weight: 850; cursor: pointer; background: linear-gradient(100deg, var(--cyan), #9fffdc); }
.primary-button:hover { filter: brightness(1.06); }
.primary-button.compact { width: auto; margin-top: 0; padding: 10px 16px; }
.field-error { margin: 7px 0 0; color: var(--danger); font-size: 13px; }
.flash-stack, .toast-stack { position: fixed; top: 18px; right: 18px; z-index: 20; width: min(360px, calc(100% - 36px)); }
.flash, .toast { margin-bottom: 8px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-strong); box-shadow: var(--shadow); }
.flash-error, .toast-error { border-color: rgba(255,127,155,.5); }
.toast-success { border-color: rgba(130,237,179,.5); }

/* App frame */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; border-right: 1px solid var(--border); background: rgba(6,15,28,.76); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 24px; color: var(--text); text-decoration: none; }
.brand span:last-child { display: grid; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.side-nav { display: grid; gap: 6px; }
.nav-item { width: 100%; padding: 11px 13px; border: 1px solid transparent; border-radius: 10px; text-align: left; cursor: pointer; background: transparent; }
.nav-item:hover { background: rgba(255,255,255,.04); }
.nav-item.active { color: var(--cyan); border-color: rgba(88,230,217,.2); background: rgba(88,230,217,.09); }
.logout-form { margin-top: auto; }
.logout-form label { margin: 0; }
.nav-logout { color: var(--muted); }
.workspace { min-width: 0; padding: 26px clamp(20px, 4vw, 58px) 56px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 25px; }
.topbar h1 { margin-bottom: 0; }
.status-pill, .tag { padding: 6px 10px; border: 1px solid rgba(88,230,217,.2); border-radius: 999px; color: var(--cyan); background: rgba(88,230,217,.08); font-size: 11px; white-space: nowrap; }
.workspace-section { animation: reveal 180ms ease-out; }
.panel { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.panel-heading, .toolbar-row, .editor-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.text-button, .icon-button, .danger-button, .pagination button, .editor-actions button { padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; color: var(--muted); cursor: pointer; background: rgba(255,255,255,.03); }
.text-button { border: 0; color: var(--cyan); background: transparent; }
.danger-button, .danger-text { color: var(--danger) !important; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card { padding: 18px 20px; border: 1px solid var(--border); border-radius: 15px; background: linear-gradient(145deg, rgba(16,34,56,.9), rgba(10,23,40,.75)); }
.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 28px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.capture-panel, .memo-panel { grid-row: span 2; }
.stack-form { display: grid; }
.form-row { display: grid; grid-template-columns: 1fr 150px; gap: 12px; }
.data-list { display: grid; gap: 8px; margin-top: 16px; }
.data-row { width: 100%; min-width: 0; padding: 11px 12px; border: 1px solid var(--border); border-radius: 11px; color: var(--text); text-align: left; background: rgba(3,12,23,.4); }
button.data-row { cursor: pointer; }
button.data-row:hover { border-color: rgba(88,230,217,.35); background: rgba(88,230,217,.05); }
.row-title { min-width: 0; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.summary-row { display: flex; align-items: center; gap: 9px; }
.row-date { margin-left: auto; color: var(--muted); font-size: 11px; }
.priority-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--muted); }
.priority-1 { background: var(--cyan); } .priority-2 { background: #ffc96b; } .priority-3 { background: var(--danger); }
.empty-state { margin: 18px 0; color: var(--muted); font-size: 13px; text-align: center; }
.memo-panel textarea { min-height: 250px; margin-top: 16px; }
.save-status { color: var(--muted); font-size: 11px; }

/* Knowledge base */
.notes-toolbar { margin-bottom: 16px; }
.category-strip { display: flex; gap: 7px; margin-bottom: 15px; overflow-x: auto; scrollbar-width: thin; }
.category-chip { flex: 0 0 auto; padding: 8px 11px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); cursor: pointer; background: transparent; }
.category-chip.active { color: var(--cyan); border-color: rgba(88,230,217,.35); background: rgba(88,230,217,.08); }
.category-chip span { margin-left: 4px; opacity: .7; }
.toolbar-row input { max-width: 520px; }
.knowledge-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: stretch; }
.note-browser { min-height: 620px; }
.note-list { max-height: 550px; overflow-y: auto; }
.note-row { display: block; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 15px; color: var(--muted); font-size: 12px; }
.editor-panel, .empty-editor { min-height: 620px; }
.empty-editor { display: grid; place-items: center; color: var(--muted); }
.editor-header > input { max-width: 520px; padding: 8px 2px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; font-size: 22px; font-weight: 750; background: transparent; }
.editor-actions { display: flex; gap: 8px; }
.editor-actions .primary-button { color: #061018; }
.editor-meta { display: flex; align-items: flex-end; gap: 12px; margin: 10px 0 15px; }
.editor-meta label { width: 135px; margin: 0; }
.editor-meta select { margin-top: 5px; padding: 8px 10px; }
.path-label { min-width: 0; padding-bottom: 9px; overflow: hidden; color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; min-height: 480px; border: 1px solid var(--border); border-radius: 13px; overflow: hidden; }
.editor-split > textarea { min-height: 480px; border: 0; border-radius: 0; resize: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: rgba(3,10,20,.55); }
.markdown-preview { min-width: 0; padding: 20px; overflow: auto; border-left: 1px solid var(--border); color: #dce9f7; line-height: 1.7; }
.markdown-preview pre { padding: 12px; overflow-x: auto; border-radius: 8px; background: #050c16; }
.markdown-preview code { font-family: ui-monospace, monospace; }
.markdown-preview table { width: 100%; border-collapse: collapse; }
.markdown-preview th, .markdown-preview td { padding: 7px; border: 1px solid var(--border); }
.markdown-preview a { color: var(--cyan); }
.markdown-preview blockquote { margin-left: 0; padding-left: 14px; border-left: 3px solid var(--violet); color: var(--muted); }

/* Todo */
.todo-layout { display: grid; grid-template-columns: minmax(280px, .7fr) minmax(420px, 1.3fr); gap: 16px; align-items: start; }
.task-list { display: grid; gap: 9px; margin-top: 16px; }
.task-row { display: grid; grid-template-columns: auto minmax(100px,1fr) 92px auto auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: rgba(3,12,23,.4); }
.task-row > input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--cyan); }
.task-title-input { padding: 7px 8px; border-color: transparent; background: transparent; }
.task-row.completed .task-title-input { color: var(--muted); text-decoration: line-through; }
.task-priority-select { padding: 7px; }
.task-due { color: var(--muted); font-size: 11px; white-space: nowrap; }
.placeholder-panel { min-height: 260px; display: grid; place-content: center; text-align: center; }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .capture-panel, .memo-panel { grid-row: auto; }
  .knowledge-layout { grid-template-columns: 250px minmax(0, 1fr); }
  .editor-split { grid-template-columns: 1fr; }
  .markdown-preview { min-height: 320px; border-top: 1px solid var(--border); border-left: 0; }
  .todo-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .auth-card { padding: 28px 22px; }
  .app-shell { grid-template-columns: 1fr; padding-bottom: 70px; }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 10; width: 100%; height: auto; padding: 8px; border: 1px solid var(--border); background: rgba(7,16,29,.96); }
  .sidebar .brand, .logout-form { display: none; }
  .side-nav { grid-template-columns: repeat(5,1fr); gap: 3px; }
  .nav-item { padding: 10px 3px; overflow: hidden; font-size: 11px; text-align: center; white-space: nowrap; text-overflow: ellipsis; }
  .workspace { padding: 20px 14px 28px; }
  .topbar { align-items: flex-start; }
  .panel { padding: 16px; }
  .stats-grid { gap: 9px; }
  .stat-card { padding: 14px; }
  .stat-card strong { font-size: 23px; }
  .form-row { grid-template-columns: 1fr; }
  .knowledge-layout { grid-template-columns: 1fr; }
  .note-browser { min-height: auto; }
  .note-list { max-height: 330px; }
  .editor-header { align-items: stretch; flex-direction: column; }
  .editor-header > input { max-width: none; }
  .editor-actions { flex-wrap: wrap; }
  .editor-meta { align-items: stretch; flex-wrap: wrap; }
  .editor-meta label { flex: 1; }
  .path-label { width: 100%; }
  .task-row { grid-template-columns: auto minmax(0,1fr) 78px auto; }
  .task-due { display: none; }
  .toolbar-row { align-items: stretch; flex-direction: column; }
}


/* AI workbench */
.workbench-grid { display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(340px, .88fr); gap: 16px; align-items: start; }
.workbench-main { min-width: 0; display: grid; gap: 16px; }
.workbench-setup > label { margin-top: 16px; }
.skill-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.skill-card { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); text-align: left; cursor: pointer; background: rgba(3,12,23,.45); }
.skill-card:hover, .skill-card.selected { border-color: rgba(88,230,217,.5); background: rgba(88,230,217,.08); }
.skill-card strong, .skill-card span, .skill-card small { display: block; }
.skill-card span { min-height: 52px; margin: 8px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.skill-card small { color: var(--cyan); font-size: 10px; }
.workbench-conversation { min-height: 560px; }
.chat-messages { min-height: 300px; max-height: 520px; margin: 18px 0; padding: 12px; overflow-y: auto; border: 1px solid var(--border); border-radius: 13px; background: rgba(3,10,20,.42); }
.chat-message { width: min(88%, 680px); margin: 10px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,.035); }
.chat-user { margin-left: auto; border-color: rgba(88,230,217,.25); background: rgba(88,230,217,.08); }
.chat-assistant { margin-right: auto; border-color: rgba(156,124,255,.25); background: rgba(156,124,255,.07); }
.chat-message p { margin: 5px 0 0; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-role { color: var(--cyan); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.chat-composer label { margin-top: 0; }
.chat-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.session-list { display: grid; gap: 8px; margin-top: 15px; }
.session-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; padding: 7px; border: 1px solid var(--border); border-radius: 11px; }
.session-row.active { border-color: rgba(88,230,217,.42); }
.session-open { min-width: 0; padding: 5px; border: 0; text-align: left; cursor: pointer; background: transparent; }
.session-open strong, .session-open span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-open span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.workbench-preview-panel { position: sticky; top: 24px; min-height: 680px; }
.workbench-preview { min-height: 500px; max-height: calc(100vh - 290px); margin-top: 16px; border: 1px solid var(--border); border-radius: 13px; background: rgba(3,10,20,.42); }
.save-confirmation { padding-top: 16px; }
.save-confirmation .primary-button { margin-top: 6px; }
.save-confirmation .text-button { width: 100%; margin-top: 8px; }
.settings-grid { max-width: 760px; display: grid; gap: 16px; }
.settings-panel { width: 100%; }
.backup-panel .primary-button { margin-top: 4px; }

@media (max-width: 1180px) {
  .workbench-grid { grid-template-columns: 1fr; }
  .workbench-preview-panel { position: static; min-height: auto; }
  .workbench-preview { min-height: 420px; max-height: none; }
}
@media (max-width: 720px) {
  .skill-grid { grid-template-columns: 1fr; }
  .skill-card span { min-height: 0; }
  .workbench-conversation { min-height: auto; }
  .chat-messages { min-height: 260px; max-height: 430px; }
  .chat-message { width: 96%; }
  .workbench-preview { min-height: 320px; }
  .workbench-setup .panel-heading, .workbench-conversation .panel-heading { align-items: flex-start; flex-direction: column; }
}
