/* ============ Personal OS — Design System ============ */
:root {
  --bg: #0c0e14;
  --bg-soft: #11141d;
  --panel: #161a26;
  --panel-2: #1c2130;
  --border: #262c3f;
  --border-soft: #1f2434;
  --text: #e6e8f0;
  --text-dim: #9aa1b5;
  --text-faint: #646b80;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, .14);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, .14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, .13);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, .14);
  --cyan: #06b6d4;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --font: 'Segoe UI', system-ui, -apple-system, 'Inter', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); }
a { color: var(--accent); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3045; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Auth screens ============ */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(800px 500px at 15% 10%, rgba(99, 102, 241, .18), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(6, 182, 212, .12), transparent 60%),
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 38px 34px;
  box-shadow: var(--shadow);
}
.auth-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
}
.auth-logo .mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center;
  font-weight: 800; font-size: 22px; color: #fff;
}
.auth-logo h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.auth-sub { color: var(--text-dim); margin-bottom: 26px; font-size: 13.5px; }
.auth-card .field { margin-bottom: 16px; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--text-dim); font-size: 13px; }
.auth-switch a { cursor: pointer; font-weight: 600; }
.auth-error {
  background: var(--red-soft); border: 1px solid rgba(239, 68, 68, .3);
  color: #fca5a5; border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; margin-bottom: 16px;
}

/* ============ Layout ============ */
.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  overflow-y: auto;
}
.side-logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.side-logo .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 17px;
}
.side-logo span { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.nav-group { margin-bottom: 14px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-faint); padding: 0 10px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-size: 13.5px;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #c7c9ff; font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.side-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.side-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--accent));
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: white;
}
.side-user .who { flex: 1; min-width: 0; }
.side-user .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-size: 11.5px; color: var(--text-faint); }
.icon-btn {
  background: none; border: none; color: var(--text-faint); cursor: pointer;
  padding: 6px; border-radius: 6px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.main { flex: 1; overflow-y: auto; padding: 28px 34px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.page-head p { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.page-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ============ Components ============ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: filter .12s, transform .05s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 15px; height: 15px; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--red-soft); color: #f87171; border: 1px solid rgba(239,68,68,.3); }
.btn.success { background: var(--green); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }

.card {
  background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 20px;
}
.card h3 { font-size: 14.5px; font-weight: 650; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card h3 svg { width: 16px; height: 16px; color: var(--text-dim); }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.stat-card { display: flex; flex-direction: column; gap: 4px; }
.stat-card .label { color: var(--text-dim); font-size: 12.5px; display: flex; align-items: center; gap: 7px; }
.stat-card .label svg { width: 15px; height: 15px; }
.stat-card .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat-card .hint { color: var(--text-faint); font-size: 12px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13.5px; font-family: inherit; outline: none;
  transition: border-color .12s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--panel-2); color: var(--text-dim);
}
.badge.green { background: var(--green-soft); color: #34d399; }
.badge.red { background: var(--red-soft); color: #f87171; }
.badge.amber { background: var(--amber-soft); color: #fbbf24; }
.badge.accent { background: var(--accent-soft); color: #a5b4fc; }
.badge.purple { background: rgba(139,92,246,.15); color: #c4b5fd; }
.badge.cyan { background: rgba(6,182,212,.14); color: #67e8f9; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--border-soft);
  transition: border-color .12s;
}
.list-row:hover { border-color: var(--border); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; font-size: 13.5px; }
.list-row .sub { color: var(--text-faint); font-size: 12px; margin-top: 1px; }
.list-row.done .title { text-decoration: line-through; color: var(--text-faint); }
.stack { display: flex; flex-direction: column; gap: 8px; }

.check {
  width: 20px; height: 20px; border-radius: 6px; flex-shrink: 0;
  border: 2px solid var(--border); background: none; cursor: pointer;
  display: grid; place-items: center; color: transparent; transition: all .12s;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--green); border-color: var(--green); color: white; }
.check svg { width: 12px; height: 12px; }

.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; border-radius: 99px; background: var(--accent); transition: width .3s; }

.empty {
  text-align: center; padding: 44px 20px; color: var(--text-faint);
  border: 1.5px dashed var(--border); border-radius: var(--radius);
}
.empty .big { font-size: 32px; margin-bottom: 8px; }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 7, 12, .72);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  animation: fadeIn .14s ease;
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 480px;
  max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow); animation: popIn .16s ease;
}
.modal.wide { max-width: 660px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0;
}
.modal-head h3 { font-size: 16.5px; font-weight: 700; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(8px); } }

/* ============ Toast ============ */
#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  font-size: 13.5px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
  animation: slideUp .2s ease; max-width: 380px;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } }

/* ============ Tables ============ */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-faint); padding: 8px 12px; border-bottom: 1px solid var(--border);
}
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
table.data tr:hover td { background: rgba(255,255,255,.015); }

/* ============ Calendar ============ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; padding: 4px; }
.cal-cell {
  min-height: 92px; background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 6px 7px; cursor: pointer;
  transition: border-color .12s; overflow: hidden;
}
.cal-cell:hover { border-color: var(--accent); }
.cal-cell.other { opacity: .35; }
.cal-cell.today { border-color: var(--accent); background: var(--accent-soft); }
.cal-cell .d { font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
.cal-ev {
  font-size: 10.5px; padding: 2px 6px; border-radius: 4px; margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--accent-soft); color: #b5bafd;
}
.cal-ev.google { background: rgba(6,182,212,.15); color: #7dd3fc; }

/* ============ Habit grid ============ */
.habit-grid { display: grid; gap: 4px; grid-auto-flow: column; }
.habit-dot {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--bg-soft); cursor: pointer; display: grid; place-items: center;
  font-size: 10px; color: var(--text-faint); transition: all .1s;
}
.habit-dot:hover { border-color: var(--accent); }
.habit-dot.on { background: var(--green); border-color: var(--green); color: white; }
.habit-dot.future { opacity: .25; pointer-events: none; }

/* ============ AI Chat ============ */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 170px); min-height: 420px; }
.chat-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 8px 4px 18px; }
.msg { display: flex; gap: 12px; max-width: 85%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .bubble {
  background: var(--panel); border: 1px solid var(--border-soft);
  padding: 11px 15px; border-radius: 14px; font-size: 13.8px; white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--accent); border-color: var(--accent); color: white; border-bottom-right-radius: 4px; }
.msg.ai .bubble { border-bottom-left-radius: 4px; }
.msg .who {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: linear-gradient(135deg, var(--purple), var(--accent)); color: white;
}
.msg.user .who { background: var(--panel-2); color: var(--text-dim); }
.chat-input {
  display: flex; gap: 10px; padding: 14px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; align-items: flex-end;
}
.chat-input textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  color: var(--text); font-family: inherit; font-size: 14px; max-height: 140px;
}
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ============ Charts ============ */
.chart-svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--text-dim); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }

/* ============ Misc ============ */
.tabs { display: flex; gap: 4px; background: var(--bg-soft); padding: 4px; border-radius: 10px; border: 1px solid var(--border-soft); width: fit-content; }
.tab {
  padding: 6px 16px; border-radius: 7px; cursor: pointer; border: none; background: none;
  color: var(--text-dim); font-size: 13px; font-weight: 600; font-family: inherit;
}
.tab.active { background: var(--accent); color: white; }
.divider { height: 1px; background: var(--border-soft); margin: 6px 0; }
.muted { color: var(--text-faint); font-size: 12.5px; }
.row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.list-row:hover .row-actions, tr:hover .row-actions { opacity: 1; }
.searchbar {
  display: flex; align-items: center; gap: 8px; background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 12px; min-width: 220px;
}
.searchbar input { background: none; border: none; outline: none; color: var(--text); font-family: inherit; font-size: 13px; flex: 1; }
.searchbar svg { width: 15px; height: 15px; color: var(--text-faint); }

.mood-row { display: flex; gap: 6px; }
.mood-row button { font-size: 20px; background: none; border: 2px solid transparent; border-radius: 8px; padding: 4px 6px; cursor: pointer; opacity: .45; }
.mood-row button.sel { opacity: 1; border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 900px) {
  .sidebar { width: 64px; padding: 14px 8px; }
  .sidebar .nav-item span, .side-logo span, .nav-label, .side-user .who { display: none; }
  .nav-item { justify-content: center; }
  .main { padding: 20px 16px 50px; }
  .field-row { grid-template-columns: 1fr; }
}
