:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #f1effa;
  --border: #e4e1f0;
  --text: #1d1b2c;
  --muted: #6c6884;
  --accent: #5b4cdb;
  --accent-soft: #ebe8ff;
  --accent-text: #ffffff;
  --success: #17a36b;
  --success-soft: #dcf5ea;
  --danger: #d9434f;
  --danger-soft: #fde6e8;
  --warn: #c98a12;
  --warn-soft: #fff3d6;
  --shadow: 0 1px 2px rgba(30, 20, 80, .06), 0 4px 16px rgba(30, 20, 80, .06);
  --radius: 14px;
  --sidebar: 268px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121119;
    --surface: #1c1a26;
    --surface-2: #252232;
    --border: #322e43;
    --text: #eceaf6;
    --muted: #9b97b3;
    --accent: #8b7fff;
    --accent-soft: #2c2752;
    --accent-text: #120f2a;
    --success: #3fcf8e;
    --success-soft: #16352a;
    --danger: #ff6b76;
    --danger-soft: #3d1c21;
    --warn: #f0b440;
    --warn-soft: #3b2f14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.65rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 22px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; padding: 0 8px 18px; }
.brand img { width: 30px; height: 30px; }
.nav a, .nav button.navlink {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 500;
  background: none; border: 0; width: 100%; cursor: pointer; text-align: start;
}
.nav a:hover, .nav button.navlink:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav .badge { margin-inline-start: auto; }
.nav-section { margin: 20px 12px 6px; font-size: .75rem; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.nav-project { display: block !important; }
.nav-project .mini-bar { margin-top: 5px; }

.main { flex: 1; min-width: 0; padding: 28px clamp(16px, 4vw, 44px) 120px; max-width: 1080px; }
.topbar { display: none; }
.bottomnav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 16px 110px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  }
  .topbar .brand { padding: 0; font-size: 1.05rem; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: .72rem; color: var(--muted); padding: 6px 0; border-radius: 10px; font-weight: 500;
  }
  .bottomnav a.active { color: var(--accent); font-weight: 700; }
  .bottomnav svg { width: 23px; height: 23px; }
  h1 { font-size: 1.4rem; }
}

/* ---------- common ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.section { margin-top: 28px; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pad { padding: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 15px; border-radius: 10px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: transform .08s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn svg { width: 17px; height: 17px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: none; border: 0; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:disabled { opacity: .3; cursor: default; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- progress ---------- */
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #a78bfa); transition: width .5s ease; }
.bar.done > i { background: var(--success); }
.mini-bar { height: 4px; }
.bar-lg { height: 12px; }
.ring { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--surface-2); }
.ring .val { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring.done .val { stroke: var(--success); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: .95rem; }
.ring.lg { width: 92px; height: 92px; }
.ring.lg span { font-size: 1.25rem; }

/* ---------- tasks ---------- */
.task {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.task:last-child { border-bottom: 0; }
.task-list { border-radius: var(--radius); overflow: hidden; }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { font-weight: 500; overflow-wrap: anywhere; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; align-items: center; }
.task .path { font-size: .78rem; color: var(--muted); margin-bottom: 2px; }
.task .actions { display: flex; gap: 2px; opacity: .55; }
.task:hover .actions { opacity: 1; }
@media (max-width: 860px) { .task .actions { opacity: 1; } }

.check {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  width: 24px; height: 24px; margin: 1px 0 0; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; transition: all .15s;
}
.check:hover { border-color: var(--success); }
.check:checked { background: var(--success); border-color: var(--success); }
.check:checked::after {
  content: ''; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
.check.pop { animation: pop .35s ease; }
@keyframes pop { 50% { transform: scale(1.35); } }

.mother { margin-bottom: 14px; overflow: hidden; }
.mother-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.mother-head .info { flex: 1; min-width: 0; }
.mother-head .info .bar { margin-top: 8px; }
.mother .chev { transition: transform .2s; color: var(--muted); }
.mother.open .chev { transform: rotate(90deg); }
.mother-body { display: none; border-top: 1px solid var(--border); }
.mother.open .mother-body { display: block; }
.mother.done .mother-head h3 { color: var(--muted); }
.add-row { display: flex; gap: 8px; padding: 10px 14px; background: var(--surface-2); flex-wrap: wrap; }
.add-row input[type=text] { flex: 1; min-width: 160px; }
.add-row input[type=number] { width: 80px; }

/* ---------- schedule ---------- */
.day { margin-bottom: 16px; }
.day-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.day-head .date { font-weight: 700; }
.day.today .day-head { background: var(--accent-soft); }
.day.past .day-head { background: var(--danger-soft); }
.pips { display: flex; gap: 4px; margin-inline-start: auto; }
.pips i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); }
.pips i.used { background: var(--accent); border-color: var(--accent); }
.pips i.fin { background: var(--success); border-color: var(--success); }

/* ---------- project cards ---------- */
.pcard { padding: 18px; display: flex; flex-direction: column; gap: 14px; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.pcard:hover { transform: translateY(-2px); }
.pcard .top { display: flex; gap: 14px; align-items: center; }
.pcard .top .t { flex: 1; min-width: 0; }
.pcard .desc { color: var(--muted); font-size: .88rem; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.subp { display: flex; flex-direction: column; gap: 4px; }
.subp .row { font-size: .86rem; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: .88rem; margin-bottom: 8px; }
.crumbs a:hover { color: var(--accent); }
.hero { display: flex; gap: 20px; align-items: center; padding: 20px; margin-bottom: 8px; flex-wrap: wrap; }
.hero .t { flex: 1; min-width: 220px; }
.hero .desc { color: var(--muted); margin-top: 6px; white-space: pre-wrap; }

/* ---------- forms & modal ---------- */
input[type=text], input[type=password], input[type=number], input[type=date], textarea, select {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 80px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
label.field small { display: block; color: var(--muted); font-weight: 400; margin-top: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: flex; align-items: center; gap: 5px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }

.modal-bg {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 10, 40, .45);
  display: grid; place-items: center; padding: 16px; animation: fade .15s;
}
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: 18px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  animation: rise .2s ease;
}
.modal h2 { margin-bottom: 16px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-start; margin-top: 18px; flex-wrap: wrap; }
@media (max-width: 860px) {
  .modal-bg { place-items: end stretch; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.fab {
  display: none; position: fixed; z-index: 31; inset-inline-end: 18px; bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 8px 24px rgba(91, 76, 219, .45); cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }
@media (max-width: 860px) { .fab { display: grid; place-items: center; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 30px; text-align: center; }
.login img { width: 56px; margin-bottom: 10px; }
.login form { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--danger); font-size: .88rem; min-height: 1.2em; }

/* ---------- celebration ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 200; }
#toasts { position: fixed; z-index: 210; top: 18px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); animation: toastIn .3s ease, toastOut .4s ease 2.6s forwards; max-width: 90vw; text-align: center;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toastIn { from { transform: translateY(-20px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-20px); opacity: 0; } }
.trophy {
  position: fixed; inset: 0; z-index: 205; display: grid; place-items: center; pointer-events: none;
}
.trophy > div {
  background: var(--surface); border-radius: 24px; padding: 28px 36px; text-align: center; box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  animation: trophy 3.4s ease forwards;
}
.trophy .em { font-size: 3.6rem; }
.trophy h2 { font-size: 1.5rem; margin-top: 6px; }
@keyframes trophy {
  0% { transform: scale(.4); opacity: 0; } 12% { transform: scale(1.08); opacity: 1; } 20% { transform: scale(1); }
  85% { opacity: 1; } 100% { opacity: 0; transform: scale(.95); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
