/* TH LifeOS design system — modern minimalist, light + dark, mobile / tablet / desktop */
:root {
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --brand-ink: #312e81;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f7;
  --border: #e4e6ef;
  --text: #16181f;
  --muted: #6b7280;
  --pos: #059669;
  --neg: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --sidebar-w: 244px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

html[data-theme="dark"] {
  --brand: #818cf8;
  --brand-soft: #232544;
  --brand-ink: #c7d2fe;
  --bg: #0c0e14;
  --surface: #14161f;
  --surface-2: #1b1e2a;
  --border: #262a38;
  --text: #e8eaf0;
  --muted: #98a1b3;
  --pos: #34d399;
  --neg: #f87171;
  --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -16px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0 0 .35em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.16rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

/* ---------- boot ---------- */
.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; color: var(--muted); }
.boot-mark, .brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #22d3ee); color: #fff; font-weight: 700; letter-spacing: -.02em;
}

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 15% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 1.35rem; margin: 0; }
.auth-brand p { margin: 0; font-size: .85rem; }
.auth-tabs { margin-bottom: 16px; }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 16px 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-note { font-size: .78rem; margin-top: 14px; margin-bottom: 0; }
.form-error { color: var(--neg); font-size: .85rem; min-height: 18px; margin: 4px 0 10px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-head { display: flex; gap: 10px; align-items: center; padding: 4px 6px 16px; }
.sidebar-head strong { display: block; font-size: .95rem; }
.sidebar-head span { display: block; }
.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); padding: 14px 10px 6px; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text); font-size: .9rem; font-weight: 500; border: 0; background: none; cursor: pointer; width: 100%; text-align: left;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; }
.nav-link .ico { width: 20px; text-align: center; font-size: 1rem; }
.nav-link .badge { margin-left: auto; font-size: .72rem; background: var(--surface-2); border-radius: 999px; padding: 1px 7px; color: var(--muted); }
.sidebar-foot { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.search-wrap { flex: 1; max-width: 520px; }
.search-wrap input {
  width: 100%; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .9rem; font-family: inherit;
}
.search-wrap input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.view { padding: 22px 20px 96px; max-width: 1280px; width: 100%; }
.only-mobile { display: none; }

.bottom-nav { display: none; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .88rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--brand); }
.btn-danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: .8rem; }
.btn-block { width: 100%; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; }

.input, .select, .textarea, select, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="search"], input[type="url"], input[type="tel"] {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .9rem; font-family: inherit;
}
textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
.select-sm { width: auto; padding: 6px 8px; font-size: .8rem; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.check input { width: 16px; height: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 1.32rem; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat .sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.subtitle { color: var(--muted); font-size: .88rem; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar .grow { flex: 1; min-width: 160px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 12px; border: 0; background: none; color: var(--muted); font-family: inherit; font-size: .87rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650; background: var(--surface-2); color: var(--muted); }
.pill.pos { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.pill.neg { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.brand { background: var(--brand-soft); color: var(--brand-ink); }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 1.6rem; margin-bottom: 6px; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 8px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { font-size: .78rem; color: var(--muted); }

.progress { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress.over > span { background: var(--neg); }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- modal ---------- */
#modal-root:empty { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(9, 11, 18, .55); display: grid; place-items: center; padding: 18px; z-index: 90; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .45); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; flex: 1; font-size: 1.02rem; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }

/* ---------- toast ---------- */
.toast-root { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: .85rem; font-weight: 600; box-shadow: var(--shadow); animation: pop .18s ease; }
.toast.err { background: var(--neg); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- misc widgets ---------- */
.cards-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.note-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.note-card:hover { border-color: var(--brand); }
.note-card .t { font-weight: 650; }
.note-card .b { font-size: .82rem; color: var(--muted); flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.swatch-indigo { border-left: 4px solid #6366f1; }
.swatch-emerald { border-left: 4px solid #10b981; }
.swatch-amber { border-left: 4px solid #f59e0b; }
.swatch-rose { border-left: 4px solid #f43f5e; }
.swatch-sky { border-left: 4px solid #0ea5e9; }
.swatch-slate { border-left: 4px solid #64748b; }

.kanban { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(220px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
.kanban-col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 160px; }
.kanban-col h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 8px; cursor: grab; font-size: .85rem; }
.kanban-card .t { font-weight: 600; margin-bottom: 4px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { font-size: .72rem; text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0; font-weight: 700; }
.cal-cell { min-height: 78px; border: 1px solid var(--border); border-radius: 10px; padding: 5px 6px; background: var(--surface); font-size: .78rem; display: flex; flex-direction: column; gap: 2px; }
.cal-cell.out { opacity: .45; }
.cal-cell.today { outline: 2px solid var(--brand); }
.cal-cell .d { font-weight: 700; font-size: .76rem; color: var(--muted); }
.cal-ev { background: var(--brand-soft); color: var(--brand-ink); border-radius: 5px; padding: 1px 4px; font-size: .7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.vault-row { display: flex; align-items: center; gap: 10px; }
.vault-pw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
.strength { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }

.bar-row { display: grid; grid-template-columns: 110px 1fr 92px; gap: 10px; align-items: center; font-size: .84rem; padding: 6px 0; }

.hint { background: var(--brand-soft); color: var(--brand-ink); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .82rem; margin-bottom: 14px; }
.warnbox { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .82rem; margin-bottom: 14px; }

/* ---------- responsive ---------- */
@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 80; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .view { padding: 16px 14px 110px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kanban { grid-template-columns: repeat(4, minmax(200px, 1fr)); }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav button {
    flex: 1; border: 0; background: none; color: var(--muted); font-family: inherit; font-size: .68rem;
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; font-weight: 600;
  }
  .bottom-nav button .ico { font-size: 1.15rem; }
  .bottom-nav button.active { color: var(--brand); }
}

@media (max-width: 639px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.25rem; }
  .topbar-actions .btn span { display: none; }
  .cal-cell { min-height: 56px; padding: 3px; }
  .cal-ev { display: none; }
  .cal-cell.has-ev::after { content: "•"; color: var(--brand); font-weight: 700; }
  .bar-row { grid-template-columns: 84px 1fr 76px; }
  .modal { max-width: 100%; border-radius: 16px; }
}

@media (min-width: 1280px) {
  .view { padding: 26px 30px 60px; }
}
