:root {
  --bg: #0b1020;
  --bg2: #0e1530;
  --panel: #141b38;
  --panel2: #1a2244;
  --border: #283157;
  --text: #e7ecff;
  --muted: #93a0c8;
  --accent: #6d8cff;
  --accent2: #9b6dff;
  --danger: #ff6b6b;
  --overdue: #ff5d6c;
  --today: #ffb443;
  --soon: #5fd0c5;
  --upcoming: #6d8cff;
  --shadow: 0 18px 50px rgba(0,0,0,0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #182250 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; transition: filter .15s, background .15s; }
.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: none; padding: 10px 16px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); padding: 9px 14px; }
.ghost:hover { background: #20294e; }
.danger { background: rgba(255,107,107,.12); color: var(--danger); border: 1px solid rgba(255,107,107,.35); padding: 9px 14px; }
.danger:hover { background: rgba(255,107,107,.2); }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 20px; padding: 4px 8px; }
.icon-btn:hover { color: var(--text); }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; font-size: 13px; }
.full { width: 100%; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px 26px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.auth-brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; color: #fff; font-weight: 800; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.auth-card input { width: 100%; }
.auth-actions { margin-top: 22px; }
.auth-actions .primary { width: 100%; padding: 12px; font-size: 15px; }
.auth-switch { margin-top: 16px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-err { background: rgba(255,107,107,.12); border: 1px solid rgba(255,107,107,.35); color: #ffb3b3; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 14px; }
.auth-ok { background: rgba(95,208,197,.12); border: 1px solid rgba(95,208,197,.35); color: #bff3ec; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 14px; }

input, textarea, select {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,140,255,.18); }
textarea { resize: vertical; }

/* ---------- app shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; background: rgba(11,16,32,.8); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.stats { display: flex; gap: 16px; color: var(--muted); font-size: 13px; }
.stats b { color: var(--text); }
.acct { position: relative; }
.acct-menu { position: absolute; right: 0; top: 38px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; min-width: 180px; box-shadow: var(--shadow); }
.acct-menu .who { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 6px; word-break: break-all; }
.acct-menu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 9px 10px; border-radius: 8px; }
.acct-menu button:hover { background: var(--panel2); }

main { max-width: 880px; margin: 0 auto; padding: 18px; }

.tabs { display: flex; align-items: center; gap: 8px; max-width: 880px; margin: 16px auto 0; padding: 0 18px; }
.tab { background: var(--panel); border: 1px solid var(--border); color: var(--muted); padding: 8px 16px; border-radius: 999px; }
.tab.active { background: linear-gradient(135deg, rgba(109,140,255,.25), rgba(155,109,255,.25)); color: var(--text); border-color: var(--accent); }
.tab .badge { background: var(--overdue); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; margin-left: 6px; font-weight: 700; }
.spacer { flex: 1; }

.banner { max-width: 880px; margin: 14px auto 0; padding: 10px 18px; }
.banner-inner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); }
.banner-inner.warn { border-color: rgba(255,180,67,.4); background: rgba(255,180,67,.08); }

.searchbar { margin-bottom: 14px; }
.cards { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: border-color .15s, transform .05s; }
.card:hover { border-color: var(--accent); }
.card:active { transform: scale(.998); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-name { font-weight: 700; font-size: 16px; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-meta { color: var(--muted); font-size: 12px; margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px 14px; }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--panel2); border: 1px solid var(--border); color: var(--muted); font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; font-weight: 600; }
.pill.overdue { background: rgba(255,93,108,.16); color: var(--overdue); }
.pill.today { background: rgba(255,180,67,.16); color: var(--today); }
.pill.soon { background: rgba(95,208,197,.16); color: var(--soon); }
.pill.upcoming { background: rgba(109,140,255,.16); color: var(--upcoming); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }
.section-title.overdue { color: var(--overdue); }
.section-title.today { color: var(--today); }
.section-title.soon { color: var(--soon); }
.section-title.upcoming { color: var(--upcoming); }

/* ---------- detail ---------- */
.back-link { background: none; border: none; color: var(--muted); padding: 0; margin-bottom: 14px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.detail-name { font-size: 26px; margin: 0; }
.detail-sub { color: var(--muted); margin-top: 4px; }
.detail-actions { display: flex; gap: 8px; flex-shrink: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 18px 0; }
.field .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.field .v { margin-top: 3px; }
.notes-block { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; white-space: pre-wrap; }

.log-form { display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-top: 12px; }
.log-form .row { display: flex; gap: 10px; flex-wrap: wrap; }
.log-form .row select, .log-form .row input { flex: 1; min-width: 120px; }
.timeline { margin-top: 16px; display: grid; gap: 2px; }
.interaction { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.interaction .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 5px; flex-shrink: 0; }
.interaction .when { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.interaction .what { margin-top: 3px; white-space: pre-wrap; }
.del { background: none; border: none; color: var(--muted); font-size: 11px; text-decoration: underline; padding: 0; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 28px 14px; z-index: 50; overflow-y: auto; backdrop-filter: blur(3px);
}
/* The hidden attribute must win over display:flex (equal-specificity guard). */
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 640px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
.form { padding: 18px 20px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.grid label.col-full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: var(--panel2); border: 1px solid var(--border); color: var(--text); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; transition: all .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 620px) {
  .stats { display: none; }
  .detail-name { font-size: 22px; }
  .grid { grid-template-columns: 1fr; }
  .tabs { flex-wrap: wrap; }
  main { padding: 14px; }
}
