/* ===========================================================================
   HomeBase design system
   Mobile-first PWA. Dark by default, light via prefers-color-scheme + toggle.
   =========================================================================== */

:root {
  --brand: #5b8def;
  --brand-2: #7a6cf0;
  --brand-grad: linear-gradient(135deg, #5b8def, #7a6cf0);

  --p1: #e0a33e; /* low */
  --p2: #e5893e; /* medium */
  --p3: #e5687a; /* high */
  --ok: #39b58a;
  --warn: #e0a33e;
  --danger: #e5687a;

  --radius: 16px;
  --radius-sm: 11px;
  --tap: 44px;
  --header-h: 56px;
  --nav-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- dark (default) ---- */
:root {
  --bg: #0f1117;
  --bg-2: #161923;
  --surface: #1b1f2b;
  --surface-2: #222736;
  --surface-hi: #2a3040;
  --border: #2a3040;
  --border-soft: #232838;
  --text: #eef1f7;
  --text-2: #a4adc0;
  --text-3: #6f7890;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* ---- light ---- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f6f7fb;
    --bg-2: #eef0f6;
    --surface: #ffffff;
    --surface-2: #f4f6fa;
    --surface-hi: #eaeef5;
    --border: #e3e7ef;
    --border-soft: #edf0f5;
    --text: #1a1d26;
    --text-2: #5a6172;
    --text-3: #9299aa;
    --shadow: 0 8px 30px rgba(30, 40, 70, 0.12);
    --shadow-sm: 0 2px 10px rgba(30, 40, 70, 0.07);
    color-scheme: light;
  }
}
:root[data-theme='light'] {
  --bg: #f6f7fb; --bg-2: #eef0f6; --surface: #ffffff; --surface-2: #f4f6fa;
  --surface-hi: #eaeef5; --border: #e3e7ef; --border-soft: #edf0f5;
  --text: #1a1d26; --text-2: #5a6172; --text-3: #9299aa;
  --shadow: 0 8px 30px rgba(30, 40, 70, 0.12); --shadow-sm: 0 2px 10px rgba(30, 40, 70, 0.07);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0f1117; --bg-2: #161923; --surface: #1b1f2b; --surface-2: #222736;
  --surface-hi: #2a3040; --border: #2a3040; --border-soft: #232838;
  --text: #eef1f7; --text-2: #a4adc0; --text-3: #6f7890;
  --shadow: 0 8px 30px rgba(0,0,0,.45); --shadow-sm: 0 2px 10px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  font-size: 16px;
  line-height: 1.4;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand); text-decoration: none; }
::selection { background: rgba(91, 141, 239, .3); }

/* scrollbars */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ---- boot splash ---- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.boot-logo {
  width: 72px; height: 72px; border-radius: 18px; background: #fff;
  box-shadow: var(--shadow); animation: pulse 1.4s ease-in-out infinite;
  display: grid; place-items: center; padding: 8px;
}
.boot-logo img { width: 100%; height: 100%; object-fit: contain; }
@keyframes pulse { 0%,100% { transform: scale(.94); opacity: .7; } 50% { transform: scale(1); opacity: 1; } }

/* ===========================================================================
   App layout
   =========================================================================== */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { color: var(--text-2); }

.icon-btn {
  width: var(--tap); height: var(--tap); min-width: var(--tap);
  display: grid; place-items: center; border-radius: 12px; color: var(--text-2);
  transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; }

.content { flex: 1; padding: 12px 16px calc(var(--nav-h) + var(--safe-bottom) + 90px); max-width: 820px; margin: 0 auto; width: 100%; }

/* ---- bottom nav (mobile) ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--border-soft);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-3); font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
  transition: color .15s;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--brand); }
.tabbar button.active svg { transform: translateY(-1px); }

/* ===========================================================================
   Common bits
   =========================================================================== */
.section-title { font-size: 13px; font-weight: 700; color: var(--text-3); text-transform: uppercase;
  letter-spacing: .06em; margin: 20px 4px 10px; }
.section-title:first-child { margin-top: 6px; }

.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); }

.empty { text-align: center; color: var(--text-3); padding: 64px 20px; }
.empty svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 12px; }
.empty p { font-size: 15px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; }

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text-2); font-size: 13.5px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ===========================================================================
   Task rows
   =========================================================================== */
.task-group + .task-group { margin-top: 8px; }
.task-list { display: flex; flex-direction: column; }

.task {
  display: flex; align-items: flex-start; gap: 13px; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  margin-bottom: 8px; transition: transform .1s, box-shadow .15s, opacity .25s;
  position: relative; overflow: hidden;
}
.task:active { transform: scale(.992); }
.task.completed { opacity: .55; }
.task.completed .task-title { text-decoration: line-through; color: var(--text-3); }
.task .accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; }

.check {
  width: 23px; height: 23px; min-width: 23px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--text-3); display: grid; place-items: center;
  transition: all .18s; color: transparent;
}
.check svg { width: 14px; height: 14px; }
.check.p1 { border-color: var(--p1); } .check.p2 { border-color: var(--p2); } .check.p3 { border-color: var(--p3); }
.check.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.done.p3 { background: var(--p3); border-color: var(--p3); }

.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 15.5px; font-weight: 550; word-break: break-word; }
.task-notes { font-size: 13px; color: var(--text-3); margin-top: 2px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 7px; }
.task-meta .due { font-size: 12.5px; font-weight: 600; color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }
.task-meta .due.overdue { color: var(--danger); }
.task-meta .due.today { color: var(--brand); }
.task-meta svg { width: 13px; height: 13px; }
.tag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.subtask-count { font-size: 12px; color: var(--text-3); display: inline-flex; align-items: center; gap: 3px; }

/* ===========================================================================
   Floating action button
   =========================================================================== */
.fab {
  position: fixed; right: 18px; z-index: 25;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
  width: 58px; height: 58px; border-radius: 20px; background: var(--brand-grad);
  color: #fff; display: grid; place-items: center; box-shadow: 0 10px 30px rgba(91,141,239,.45);
  transition: transform .12s;
}
.fab:active { transform: scale(.9); }
.fab svg { width: 28px; height: 28px; }

/* ===========================================================================
   Sheet / modal
   =========================================================================== */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5);
  opacity: 0; transition: opacity .22s; }
.scrim.show { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-width: 620px; margin: 0 auto;
}
.sheet.show { transform: translateY(0); }
.sheet .grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 6px auto 14px; }
.sheet h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }

/* ---- form controls ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.input, .textarea, select.input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 13px; font-size: 15.5px; color: var(--text);
  transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none;
}
.input:focus, .textarea:focus, select.input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91,141,239,.18);
}
.textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
.title-input {
  width: 100%; background: transparent; border: none; font-size: 20px; font-weight: 650;
  padding: 8px 2px; margin-bottom: 4px;
}
.title-input:focus { outline: none; }
.title-input::placeholder { color: var(--text-3); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--text-2); transition: all .15s; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.prio-opts { display: flex; gap: 8px; }
.prio-opts button { flex: 1; padding: 10px 4px; border-radius: 11px; border: 1.5px solid var(--border);
  background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--text-2); transition: all .15s; }
.prio-opts button[data-p='1'].sel { border-color: var(--p1); color: var(--p1); }
.prio-opts button[data-p='2'].sel { border-color: var(--p2); color: var(--p2); }
.prio-opts button[data-p='3'].sel { border-color: var(--p3); color: var(--p3); }
.prio-opts button[data-p='0'].sel { border-color: var(--text-2); color: var(--text); }

.color-opts { display: flex; gap: 10px; flex-wrap: wrap; }
.color-opts button { width: 34px; height: 34px; border-radius: 50%; border: 2.5px solid transparent; transition: transform .12s; }
.color-opts button.sel { border-color: var(--text); transform: scale(1.1); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 13px; font-size: 15.5px; font-weight: 650;
  background: var(--surface-2); color: var(--text); transition: transform .1s, background .15s; width: 100%;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: 0 6px 18px rgba(91,141,239,.35); }
.btn-danger { background: color-mix(in srgb, var(--danger) 16%, var(--surface-2)); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn.sm { padding: 9px 14px; font-size: 14px; width: auto; }

.weekday-picker { display: flex; gap: 6px; }
.weekday-picker button { flex: 1; height: 38px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.weekday-picker button.sel { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ===========================================================================
   Calendar
   =========================================================================== */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin: 6px 2px 14px; }
.cal-header .month { font-size: 18px; font-weight: 700; }
.cal-nav { display: flex; gap: 6px; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 6px; }
.weekdays span { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 11px; background: var(--surface); border: 1px solid var(--border-soft);
  padding: 5px 0 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 13px; font-weight: 600; transition: background .12s; position: relative;
}
.cal-cell.dim { opacity: .38; }
.cal-cell.today { border-color: var(--brand); color: var(--brand); }
.cal-cell.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.cal-cell .dots { display: flex; gap: 2.5px; margin-top: auto; margin-bottom: 6px; }
.cal-cell .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--brand); }
.cal-cell.sel .dots i { background: #fff; }
.agenda { margin-top: 20px; }
.agenda-date { font-size: 15px; font-weight: 700; margin: 4px 2px 12px; }

/* ===========================================================================
   Maintenance
   =========================================================================== */
.maint {
  display: flex; align-items: center; gap: 13px; padding: 15px 14px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  position: relative; overflow: hidden;
}
.maint .ring {
  width: 46px; height: 46px; min-width: 46px; border-radius: 14px; display: grid; place-items: center;
  font-size: 20px; background: var(--surface-2);
}
.maint-main { flex: 1; min-width: 0; }
.maint-title { font-size: 15.5px; font-weight: 600; }
.maint-sub { font-size: 12.5px; color: var(--text-2); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.status-badge { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.status-badge.overdue { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.status-badge.soon { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.status-badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.maint .done-btn { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--text-2);
  display: grid; place-items: center; transition: all .15s; }
.maint .done-btn:hover { background: var(--ok); color: #fff; }
.maint .done-btn svg { width: 20px; height: 20px; }
.progress { height: 5px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.progress i { display: block; height: 100%; border-radius: 4px; }

/* ===========================================================================
   Settings / auth
   =========================================================================== */
.list-rows { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 13px; padding: 14px 15px; border-bottom: 1px solid var(--border-soft); }
.list-row:last-child { border-bottom: none; }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: 15px; font-weight: 550; }
.list-row .lr-sub { font-size: 12.5px; color: var(--text-3); }
.list-row .avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.list-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; }
.list-icon svg { width: 18px; height: 18px; }

.switch { width: 48px; height: 28px; border-radius: 999px; background: var(--border); position: relative; transition: background .18s; flex: 0 0 auto; }
.switch.on { background: var(--ok); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on::after { transform: translateX(20px); }

.auth-wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 22px calc(40px + var(--safe-bottom)); max-width: 420px; margin: 0 auto; }
.auth-logo { width: 92px; height: 92px; border-radius: 22px; background: #fff; margin: 0 auto 18px;
  display: grid; place-items: center; box-shadow: var(--shadow); padding: 10px; }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-wrap h1 { text-align: center; font-size: 25px; font-weight: 750; letter-spacing: -.02em; }
.auth-wrap .sub { text-align: center; color: var(--text-2); margin: 6px 0 26px; font-size: 15px; }
.auth-wrap .field { margin-bottom: 13px; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--text-2); font-size: 14.5px; }
.error-banner { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); border-radius: 12px;
  padding: 11px 14px; font-size: 14px; font-weight: 550; margin-bottom: 14px; }

/* toast */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-bottom) + 84px);
  z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--surface-hi); color: var(--text); padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px; animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
  max-width: 90vw; }
.toast svg { width: 17px; height: 17px; color: var(--ok); }
.toast .undo { color: var(--brand); font-weight: 700; pointer-events: auto; padding-left: 6px; }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } }

/* Entrance animation animates transform only — never opacity — so content is
   always readable even if the animation is frozen (backgrounded tab, reduced
   motion). Resting state is fully visible. */
.fade-in { animation: fadeIn .24s ease both; }
@keyframes fadeIn { from { transform: translateY(7px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .fade-in, .boot-logo, .toast { animation: none !important; }
  * { scroll-behavior: auto !important; }
}

/* ===========================================================================
   Wide screens: sidebar instead of bottom tabs
   =========================================================================== */
@media (min-width: 860px) {
  .app-shell { flex-direction: row; }
  .tabbar {
    position: sticky; top: 0; bottom: auto; left: auto; right: auto;
    flex-direction: column; width: 88px; height: 100dvh; padding: 20px 0;
    border-top: none; border-right: 1px solid var(--border-soft); gap: 6px;
  }
  .tabbar button { flex: 0 0 auto; height: 66px; }
  .fab { bottom: 28px; right: calc(50% - 410px); }
  .content { padding-bottom: 120px; }
  .topbar { border-radius: 0; }
}
@media (min-width: 860px) and (max-width: 940px) {
  .fab { right: 24px; }
}
