/* =========================================================
   Tokens
   ========================================================= */
:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1e2621;
  --muted: #6b736d;
  --line: #e5e2d9;
  --primary: #3f5e4c;
  --primary-hover: #344f40;
  --primary-ink: #ffffff;
  --primary-soft: #e4ece6;
  --accent: #b8673f;
  --accent-soft: #f6e8df;
  --danger: #b4443a;
  --danger-soft: #f8e3e0;
  --ok: #2f7a4e;
  --ok-soft: #e0f0e6;
  --warn: #9a6210;
  --warn-soft: #fbefd9;
  --st-initial: #cdbb98;
  --st-detailed: #8fa88f;
  --st-pre_exec: #5c7c69;
  --st-execution: #c27a52;
  --st-done: #2f4a3b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30, 38, 33, .04), 0 6px 18px rgba(30, 38, 33, .06);
  --font: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a17; --surface: #1d2420; --surface-2: #222a25; --ink: #e8ebe7; --muted: #9aa49d; --line: #2f3833;
    --primary: #7fa58d; --primary-hover: #93b59f; --primary-ink: #0f1512; --primary-soft: #26352c;
    --accent: #d99470; --accent-soft: #3a2a21; --danger: #e07a6f; --danger-soft: #3b2220; --ok: #7cc79a; --ok-soft: #1f3528;
    --warn: #e5b45c; --warn-soft: #3a2f1a; --st-done: #a8c7b3;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a17; --surface: #1d2420; --surface-2: #222a25; --ink: #e8ebe7; --muted: #9aa49d; --line: #2f3833;
  --primary: #7fa58d; --primary-hover: #93b59f; --primary-ink: #0f1512; --primary-soft: #26352c;
  --accent: #d99470; --accent-soft: #3a2a21; --danger: #e07a6f; --danger-soft: #3b2220; --ok: #7cc79a; --ok-soft: #1f3528;
  --warn: #e5b45c; --warn-soft: #3a2f1a; --st-done: #a8c7b3;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; }
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 26px; font-weight: 700; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; min-height: 40px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); flex: none; cursor: pointer; }
.ic { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.d-block { display: block; }
.neg { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pre { white-space: pre-wrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.sm { min-height: 34px; padding: 5px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger) !important; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; flex: none;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--ink); text-decoration: none; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.star.on, .star-on { color: #d49b2a; }
.icon-btn.star.on .ic, .star-on .ic { fill: currentColor; }
.star-on .ic { width: 14px; height: 14px; vertical-align: -2px; }

/* Chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 13px;
  font-size: 14px; cursor: pointer; white-space: nowrap; min-height: 34px;
}
.chip-btn:hover { border-color: var(--primary); }
.chip-btn.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip.st-initial { background: color-mix(in srgb, var(--st-initial) 30%, transparent); color: var(--ink); border-color: transparent; }
.chip.st-detailed { background: color-mix(in srgb, var(--st-detailed) 30%, transparent); color: var(--ink); border-color: transparent; }
.chip.st-pre_exec { background: color-mix(in srgb, var(--st-pre_exec) 25%, transparent); color: var(--ink); border-color: transparent; }
.chip.st-execution { background: color-mix(in srgb, var(--st-execution) 25%, transparent); color: var(--ink); border-color: transparent; }
.chip.st-done { background: color-mix(in srgb, var(--st-done) 22%, transparent); color: var(--ink); border-color: transparent; }
.chip.q-draft { background: var(--surface-2); }
.chip.q-sent { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.q-approved { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.q-rejected { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 7px; }
.tag.prog { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

/* =========================================================
   Shell
   ========================================================= */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 236px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-inline-start: 0; border-inline-end: 1px solid var(--line); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.brand-name { font-weight: 700; line-height: 1.2; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); font-weight: 500; }
.nav-item .ic { color: var(--muted); }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item.active .ic { color: var(--primary); }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.scrim { display: none; }
.view { padding: 28px 32px 80px; max-width: 1280px; width: 100%; margin: 0 auto; }
.loading, .boot { display: grid; place-items: center; min-height: 40vh; }
.boot { min-height: 100vh; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub, .proj-head .sub { margin: 4px 0 0; color: var(--muted); }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 0; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 16px; font-weight: 600; margin-bottom: 14px; flex-wrap: wrap; }
.card-title small { font-weight: 400; }
.mini-link { font-size: 13px; font-weight: 500; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.cols-2 > div { display: flex; flex-direction: column; gap: 18px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 18px 0; }
.empty-state { text-align: center; padding: 26px 12px; color: var(--muted); }
.empty-state p { margin: 0; font-weight: 500; }
.empty-state small { display: block; margin-top: 4px; }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 16px; }
.toolbar .search { width: 240px; flex: 0 1 240px; }
.toolbar select { width: auto; }
.toolbar-end { display: flex; gap: 6px; margin-inline-start: auto; flex-wrap: wrap; }

/* =========================================================
   Dashboard
   ========================================================= */
.hero { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px; align-items: start; }
.hero-chart { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.donut { width: 180px; height: 180px; border-radius: 50%; display: grid; place-items: center; }
.donut-hole { width: 118px; height: 118px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-hole b { font-size: 34px; line-height: 1; }
.donut-hole span { color: var(--muted); font-size: 13px; }
.legend { list-style: none; margin: 0; padding: 0; width: 100%; max-width: 240px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend span { flex: 1; }
.hero-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.proj-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; color: var(--ink); border: 1px solid transparent; }
.proj-row:hover { background: var(--surface-2); border-color: var(--line); text-decoration: none; }
.proj-thumb { width: 64px; height: 50px; border-radius: 9px; object-fit: cover; flex: none; }
.cover-ph { display: grid; place-items: center; background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft)); color: var(--primary); font-weight: 700; }
.proj-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.proj-info span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.pm { display: inline-flex; align-items: center; gap: 6px; }
.mini-progress { width: 64px; height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; display: inline-block; }
.mini-progress i { display: block; height: 100%; background: var(--primary); }
.pm small { color: var(--muted); font-size: 12px; }
.link-more { align-self: flex-start; font-size: 14px; font-weight: 500; padding: 6px 8px; }
.up-group + .up-group { margin-top: 14px; }
.up-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.up-list { list-style: none; margin: 6px 0 0; padding: 0; }
.up-list li { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.up-list li:last-child { border-bottom: 0; }
.up-list label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; min-width: 0; }
.up-list input { margin-top: 2px; }
.up-list li.done span { text-decoration: line-through; color: var(--muted); }
.due { font-size: 12px; color: var(--muted); white-space: nowrap; background: var(--surface-2); border-radius: 6px; padding: 1px 7px; border: 1px solid var(--line); }
.due.overdue { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.due.today { color: var(--warn); background: var(--warn-soft); border-color: transparent; font-weight: 600; }
.mini-notes, .mini-quotes { list-style: none; margin: 0; padding: 0; }
.mini-notes li, .mini-quotes li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.mini-notes li:last-child, .mini-quotes li:last-child { border-bottom: 0; }
.mini-notes small, .mini-quotes small { display: block; color: var(--muted); font-size: 12px; }
.mini-quotes a { display: flex; justify-content: space-between; gap: 8px; color: var(--ink); }

/* =========================================================
   Projects
   ========================================================= */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.proj-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.proj-card > .btn { margin: 0 14px 14px; }
.proj-card-link { color: var(--ink); display: flex; flex-direction: column; flex: 1; }
.proj-card-link:hover { text-decoration: none; }
.proj-card-link:hover .proj-cover { opacity: .92; }
.proj-cover { width: 100%; height: 150px; object-fit: cover; font-size: 30px; }
.proj-card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }

.proj-head { margin-bottom: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.proj-head-main { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.proj-head-cover { width: 84px; height: 84px; border-radius: 16px; object-fit: cover; flex: none; font-size: 26px; }
.proj-head-text { flex: 1; min-width: 200px; }
.proj-head-actions { display: flex; gap: 6px; align-items: center; }
.contact { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 14px; }
.contact a { display: inline-flex; gap: 5px; align-items: center; }
.contact .ic { width: 15px; height: 15px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { display: flex; align-items: center; gap: 6px; padding: 8px 14px; color: var(--ink); font-weight: 500; white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.tab .ic { color: var(--muted); }
.tab:hover { border-color: var(--primary); text-decoration: none; }
.tab.on { color: var(--primary-ink); background: var(--primary); border-color: var(--primary); }
.tab.on .ic { color: var(--primary-ink); }
.tab .ic { width: 16px; height: 16px; }
.shop-projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 18px; }
a.group-card { color: var(--ink); }
a.group-card:hover { text-decoration: none; }
.card-title a { color: var(--ink); }

.stage-track { display: flex; gap: 4px; margin-bottom: 16px; }
.st-step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; cursor: pointer; padding: 4px 0; font-size: 12px; color: var(--muted); }
.st-step i { display: block; width: 100%; height: 8px; border-radius: 8px; background: var(--line); }
.st-step.on i { background: var(--primary); }
.st-step.cur span { color: var(--primary); font-weight: 700; }
.st-step:hover i { outline: 2px solid var(--primary-soft); }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; font-size: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; font-weight: 500; }
.desc { margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 14px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stats3 > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stats3 small { display: block; color: var(--muted); font-size: 12px; }
.stats3 b { font-size: 17px; }
.budget-bar, .progress-line { height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; margin-bottom: 6px; }
.budget-bar i, .progress-line i { display: block; height: 100%; background: var(--primary); border-radius: 10px; }
.budget-bar.over i { background: var(--danger); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.g-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.g-cover { position: absolute; top: 5px; inset-inline-start: 5px; width: 28px; height: 28px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .85); color: #8a8a8a; display: grid; place-items: center; cursor: pointer; }
.g-cover .ic { width: 15px; height: 15px; }
.g-cover.on { color: #d49b2a; }
.g-cover.on .ic { fill: currentColor; }
.danger-zone { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

/* Tasks */
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.task { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.task-title { font-weight: 500; }
.task-tags { display: flex; gap: 6px; }
.task-tags:empty { display: none; }
.task.done { background: var(--surface-2); }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.row-actions { display: flex; gap: 2px; align-items: center; }
.today-line { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 13px; font-weight: 600; margin: 6px 0; }
.today-line::before, .today-line::after { content: ''; flex: 1; height: 2px; background: var(--accent); opacity: .5; border-radius: 2px; }

/* Notes */
.note-add { margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.note-add select { width: auto; max-width: 60%; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.note-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.note-card.done { opacity: .65; }
.note-card.done .note-text { text-decoration: line-through; }
.note-top { display: flex; justify-content: space-between; align-items: center; }
.note-check { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.note-text { white-space: normal; word-break: break-word; flex: 1; }
.note-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.note-meta .row-actions { margin-inline-start: auto; }

/* Files */
.folder-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.folder-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: start; }
.folder-card .ic { width: 24px; height: 24px; color: var(--accent); }
.folder-card small { color: var(--muted); }
.folder-card.on { border-color: var(--primary); background: var(--primary-soft); }
.dropzone { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 20px; border: 2px dashed var(--line); border-radius: var(--radius); margin-bottom: 16px; color: var(--muted); background: var(--surface-2); text-align: center; }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone small { flex-basis: 100%; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.file-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.file-thumb { display: block; height: 120px; background: var(--surface-2); }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-icon { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--accent); font-weight: 700; font-size: 13px; }
.file-icon:hover { text-decoration: none; }
.file-icon .ic { width: 34px; height: 34px; }
.file-info { padding: 8px 10px 0; min-width: 0; }
.file-info b { display: block; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info small { color: var(--muted); font-size: 12px; }
.file-card .row-actions { padding: 2px 6px 6px; justify-content: flex-end; }

/* Groups (shopping / budget) */
.summary-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.summary-strip > div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.summary-strip small { display: block; color: var(--muted); font-size: 12px; }
.summary-strip b { font-size: 18px; }
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 16px 0; }
.group-card { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: start; transition: border-color .15s, transform .15s; }
.group-card:hover { border-color: var(--primary); }
.group-card b { font-weight: 600; }
.group-card span { font-size: 17px; font-weight: 600; color: var(--primary); }
.group-card small { color: var(--muted); font-size: 12px; }
.group-card.on { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.group-card.is-empty { opacity: .6; }
.group-card.is-empty span { color: var(--muted); }
.gbar { display: block; width: 100%; height: 5px; border-radius: 5px; background: var(--line); margin-top: 6px; overflow: hidden; }
.gbar i { display: block; height: 100%; background: var(--primary); }
.gbar.over i { background: var(--danger); }
.table-card { margin-bottom: 18px; scroll-margin-top: 16px; }

/* Tables */
.table-wrap { overflow-x: auto; container-type: inline-size; }

/* Stacked tables: when the table's own box is narrow (phone, or a small window), each row becomes a card */
@container (max-width: 700px) {
  .tbl.stack thead { display: none; }
  .tbl.stack, .tbl.stack tbody, .tbl.stack tr, .tbl.stack td { display: block; width: 100%; }
  .tbl.stack tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  .tbl.stack tr:last-child td { border-bottom: 0; }
  .tbl.stack td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: end; }
  .tbl.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: start; flex: none; }
  .tbl.stack td.img-cell { width: auto; }
  .tbl.stack .item-img { width: 96px; height: 76px; }
  .tbl.stack td.actions { justify-content: flex-end; border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 6px; }
}
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: start; font-weight: 600; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.actions { white-space: nowrap; text-align: end; }
.tbl .img-cell { width: 88px; }
.item-img {
  width: 76px; height: 60px; padding: 0; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); overflow: hidden; cursor: pointer; display: grid; place-items: center; flex: none;
}
.item-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-img:hover { border-color: var(--primary); }
.item-img.empty { border-style: dashed; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.item-img.empty .ic { width: 22px; height: 22px; }
.item-img.empty small { font-size: 10px; line-height: 1.1; }
.item-img.empty:hover { color: var(--primary); background: var(--primary-soft); }
.lightbox-img { display: block; max-width: 100%; max-height: 62vh; margin: 0 auto; border-radius: 12px; object-fit: contain; background: var(--surface-2); }
input[type="file"] { padding: 7px; cursor: pointer; }
.tbl tr.it-bought td { color: var(--muted); }
.ext .ic { width: 14px; height: 14px; vertical-align: -2px; }
.status-sel { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; border-radius: 8px; }
.status-sel.s-bought { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-sel.s-ordered { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* Timer */
.timer-card { display: flex; flex-direction: column; gap: 12px; }
.timer-display { font-size: 48px; font-weight: 300; text-align: center; letter-spacing: 2px; font-variant-numeric: tabular-nums; color: var(--muted); direction: ltr; }
.timer-display.running { color: var(--primary); font-weight: 500; }
.big-num { font-size: 36px; font-weight: 300; font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }
.cat-sum { list-style: none; margin: 12px 0 0; padding: 0; }
.cat-sum li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.timer-pill {
  position: fixed; bottom: 16px; inset-inline-start: 50%; transform: translateX(50%); z-index: 40;
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; border-radius: 999px;
  background: var(--ink); color: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: calc(100% - 32px);
}
.timer-pill[hidden] { display: none; }
.timer-pill a { color: inherit; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.timer-pill b { font-variant-numeric: tabular-nums; direction: ltr; }
.tp-dot { width: 9px; height: 9px; border-radius: 50%; background: #e0604f; animation: pulse 1.4s ease-in-out infinite; flex: none; }
@keyframes pulse { 50% { opacity: .35; } }

/* Quotes */
.quote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.quote-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; color: var(--ink); box-shadow: var(--shadow); }
.quote-card:hover { border-color: var(--primary); text-decoration: none; }
.quote-form { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.list-rows { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 8px; }
.list-row, .pay-row { display: flex; gap: 8px; align-items: center; }
.pay-row input[name="pl"] { flex: 2; }
.pay-row input[name="pd"] { flex: 1.3; }
.pay-row input[name="pa"] { flex: 1; }
.split-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 14px; padding: 12px; background: var(--surface-2); border-radius: 12px; font-size: 14px; }
.split-row label { display: flex; align-items: center; gap: 6px; }
.split-row input, .split-row select { width: auto; min-height: 34px; padding: 4px 8px; }
.split-row input[type="number"] { width: 64px; }
.chips.wrap { margin-bottom: 4px; }

/* Print view */
.print-bar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.paper { background: #fff; color: #1e2621; max-width: 800px; margin: 0 auto; padding: 48px 56px; border-radius: 6px; box-shadow: var(--shadow); font-size: 15px; }
.paper-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 18px; border-bottom: 2px solid #3f5e4c; }
.paper-biz { font-size: 22px; font-weight: 700; color: #3f5e4c; }
.paper-contact { font-size: 13px; color: #6b736d; margin-top: 4px; }
.paper-date { color: #6b736d; white-space: nowrap; }
.paper-title { font-size: 28px; margin: 28px 0 12px; }
.paper h2 { font-size: 17px; margin: 24px 0 8px; color: #3f5e4c; }
.paper p { margin: 4px 0; }
.paper-list { margin: 0; padding-inline-start: 20px; }
.paper-fee { font-size: 20px; font-weight: 700; }
.paper-fee small { font-size: 14px; font-weight: 400; color: #6b736d; }
.paper-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.paper-table th, .paper-table td { border: 1px solid #e5e2d9; padding: 7px 10px; text-align: start; }
.paper-table th { background: #f5f4ef; }
.sign { display: flex; gap: 40px; margin-top: 56px; }
.sign div { flex: 1; color: #6b736d; font-size: 13px; }
.sign span { display: block; border-bottom: 1px solid #1e2621; height: 36px; margin-bottom: 6px; }

/* Templates */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tpl-card { display: flex; flex-direction: column; gap: 6px; }
.tpl-card .row-actions { margin-top: 6px; justify-content: space-between; }
.tpl-head, .tpl-row { display: grid; grid-template-columns: minmax(0, 1fr) 76px 130px 36px; gap: 6px; align-items: center; }
.tpl-head { margin-top: 12px; padding: 0 2px; }
.tpl-items { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; max-height: 50vh; overflow-y: auto; }

/* =========================================================
   Forms & modals
   ========================================================= */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.cols-3f { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field.full, .check-field.full { grid-column: 1 / -1; }
.check-field { display: flex; align-items: center; gap: 8px; cursor: pointer; padding-top: 22px; }
.form-error { color: var(--danger); min-height: 0; margin: 8px 0 0; font-size: 14px; }
.form-error:empty { display: none; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.warn-box { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; margin: 0; }

.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(15, 20, 17, .45); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .18s; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { font-size: 19px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-text { margin: 0; line-height: 1.6; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.toasts { position: fixed; top: 16px; inset-inline-start: 50%; transform: translateX(50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100% - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-size: 14px; transition: opacity .3s, transform .3s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 56px; height: 56px; }
.login-card h1 { font-size: 22px; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1100px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: 240px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; transform: translateX(100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(15, 20, 17, .4); }
  .topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line); padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .topbar-title { font-weight: 700; color: var(--ink); flex: 1; text-align: center; }
  .topbar-spacer { width: 36px; }
  .view { padding: 18px 16px 90px; }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-chart { flex-direction: row; justify-content: center; }
  .donut { width: 140px; height: 140px; }
  .donut-hole { width: 92px; height: 92px; }
  .donut-hole b { font-size: 28px; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 22px; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .page-head { align-items: stretch; }
  .page-head .head-actions .btn { flex: 1; }
  .toolbar .search { flex: 1 1 100%; width: 100%; }
  .toolbar-end { margin-inline-start: 0; }
  .chips { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; max-width: 100%; }
  .chips::-webkit-scrollbar { display: none; }
  .chips.wrap { flex-wrap: wrap; }
  .form-grid, .form-grid.cols-3f { grid-template-columns: minmax(0, 1fr); }
  .check-field { padding-top: 0; }
  .folder-row { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .folder-card { padding: 10px; }
  .file-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .file-thumb { height: 100px; }
  .group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats3 { grid-template-columns: minmax(0, 1fr); }
  .stats3 > div { display: flex; justify-content: space-between; align-items: center; }
  .st-step span { font-size: 10px; }
  .tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .tab { flex-direction: column; gap: 3px; padding: 8px 2px; border-radius: 12px; font-size: 12px; white-space: normal; text-align: center; line-height: 1.2; }
  .tab .ic { width: 20px; height: 20px; }
  .shop-projects { grid-template-columns: minmax(0, 1fr); }
  .hero-chart { flex-direction: column; }
  .task { flex-wrap: wrap; }
  .task .row-actions { margin-inline-start: auto; }
  .proj-head-cover { width: 60px; height: 60px; }
  .modal-back { place-items: end center; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .modal.wide { max-width: 100%; }
  .tpl-head { display: none; }
  .tpl-row { grid-template-columns: minmax(0, 1fr) 64px 36px; }
  .tpl-row select { grid-column: 1 / 3; }
  .pay-row { flex-wrap: wrap; }
  .pay-row input[name="pl"] { flex: 1 1 100%; }
  .paper { padding: 24px 18px; }
  .sign { gap: 18px; }

}

/* =========================================================
   Print
   ========================================================= */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .sidebar, .topbar, .scrim, .no-print, .timer-pill, .toasts { display: none !important; }
  .view { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; max-width: none; }
}
