:root {
  --bg: #f6f4ef; --panel: #fffdf9; --ink: #1d1c1a; --muted: #77736b; --line: #e7e2d8;
  --soft: #efebe3; --accent: #d9480f; --accent-ink: #fff; --ok: #2b8a3e;
  --p1: #1c7ed6; --p2: #f08c00; --p3: #e03131; --over: #c92a2a;
  --shadow: 0 1px 2px rgba(40,30,10,.06), 0 4px 16px rgba(40,30,10,.05);
  --radius: 12px; --side: 248px; --detail: 440px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151518; --panel: #1d1d21; --ink: #ecebe8; --muted: #9a978f; --line: #2d2d33;
    --soft: #26262b; --accent: #ff6b35; --accent-ink: #1a0d06;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: var(--soft); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 14px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--soft); color: var(--ink); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--over); }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px 10px; border-radius: 8px; }
.icon-btn:hover { background: var(--soft); }

/* ---------- layout */
#app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100%; }
#sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 12px;
  border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 750; font-size: 19px; letter-spacing: -.02em; padding: 2px 10px 14px; display: flex; align-items: center; gap: 9px; }
.brand.big { font-size: 28px; justify-content: center; padding-bottom: 8px; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 15px; }
.brand.big .logo { width: 38px; height: 38px; font-size: 22px; border-radius: 11px; }
#sidebar nav button, #sidebar nav a {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 0;
  background: transparent; padding: 7px 10px; border-radius: 8px; color: var(--ink); text-decoration: none;
}
#sidebar nav button:hover { background: var(--soft); }
#sidebar nav button.active { background: var(--soft); font-weight: 650; }
#sidebar nav .ic { width: 18px; text-align: center; color: var(--muted); }
#sidebar nav .n { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.side-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; padding: 18px 10px 4px; }
.side-head button { border: 0; background: transparent; color: var(--muted); font-size: 16px; border-radius: 6px; }
.side-head button:hover { background: var(--soft); color: var(--ink); }
.side-foot { margin-top: auto; padding-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.side-foot button, .side-foot a { border: 0; background: transparent; text-align: left; padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px; width: 100%; }
.side-foot button:hover, .side-foot a:hover { background: var(--soft); color: var(--ink); }
.side-foot form { margin: 0; }
#scrim { display: none; }

#main { min-width: 0; padding: 18px clamp(14px, 4vw, 48px) 80px; max-width: 920px; width: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topbar h1 { font-size: 26px; letter-spacing: -.025em; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu { display: none; }
.search input { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 12px; width: 220px; outline: none; }
.search input:focus { border-color: var(--accent); }

/* ---------- composer */
#composer { padding: 10px 12px 8px; margin-bottom: 18px; }
#composer.drag { outline: 2px dashed var(--accent); }
#quick { width: 100%; border: 0; outline: none; background: transparent; resize: none; padding: 4px 2px; max-height: 320px; font-size: 16px; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.composer-bar .hint { flex: 1; color: var(--muted); font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#pending { display: flex; flex-wrap: wrap; gap: 6px; }
#pending:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--soft); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; max-width: 260px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 5px; margin-left: -6px; }
.chip button { border: 0; background: transparent; color: var(--muted); border-radius: 50%; width: 20px; height: 20px; padding: 0; }

/* ---------- task rows */
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 4px 6px; }
.task {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; position: relative;
}
.task:hover { background: var(--panel); border-color: var(--line); }
.task.open { background: var(--panel); border-color: var(--accent); }
.task + .task { margin-top: 1px; }
.task.drop { outline: 2px dashed var(--accent); }
.check {
  width: 21px; height: 21px; border-radius: 50%; border: 2px solid var(--muted); background: transparent;
  margin-top: 1px; padding: 0; display: grid; place-items: center; color: transparent; font-size: 12px; flex: none;
  transition: background .15s, color .15s;
}
.check.p1 { border-color: var(--p1); } .check.p2 { border-color: var(--p2); } .check.p3 { border-color: var(--p3); background: color-mix(in srgb, var(--p3) 10%, transparent); }
.check:hover { color: var(--muted); }
.task.done .check, .check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.done .t-title { color: var(--muted); text-decoration: line-through; }
.t-body { min-width: 0; }
.t-title { font-weight: 520; word-wrap: break-word; }
.t-notes { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.t-meta .due.over { color: var(--over); font-weight: 600; }
.t-meta .due.today { color: var(--ok); font-weight: 600; }
.t-meta .listname { background: var(--soft); padding: 0 7px; border-radius: 5px; }
.t-thumbs { display: flex; gap: 6px; margin-top: 8px; }
.t-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--soft); }
.pin { position: absolute; right: 10px; top: 9px; font-size: 12px; opacity: .6; }
#empty { text-align: center; color: var(--muted); padding: 60px 20px; }
#empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

/* ---------- detail panel */
#detail {
  position: fixed; right: 0; top: 0; bottom: 0; width: var(--detail); max-width: 100vw; background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0,0,0,.08); transform: translateX(102%);
  transition: transform .22s ease; overflow-y: auto; z-index: 30; padding: 14px 18px 60px;
}
#detail.show { transform: none; }
.d-top { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.d-top .spacer { flex: 1; }
.d-title-row { display: flex; gap: 12px; align-items: flex-start; }
.d-title { font-size: 20px; font-weight: 650; letter-spacing: -.015em; border: 0; outline: none; width: 100%; background: transparent; resize: none; padding: 0; line-height: 1.3; }
.d-props { display: grid; grid-template-columns: 82px 1fr; gap: 8px 10px; align-items: center; margin: 16px 0 8px; font-size: 14px; }
.d-props label { color: var(--muted); }
.d-props select, .d-props input[type=date] { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 5px 8px; }
.seg { justify-self: start; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--soft); font-weight: 650; }
.seg .p1.on { color: var(--p1); } .seg .p2.on { color: var(--p2); } .seg .p3.on { color: var(--p3); }
.due-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
@media (max-width: 420px) { .due-row .btn.small { padding: 4px 8px; } .due-row input[type=date] { max-width: 150px; } }
.d-sec { margin-top: 22px; }
.d-sec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.d-sec h3 .count { font-weight: 500; letter-spacing: 0; text-transform: none; }
textarea.notes { width: 100%; min-height: 90px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px; outline: none; resize: vertical; }
textarea.notes:focus, .add-in:focus { border-color: var(--accent); }
.progress { height: 4px; background: var(--soft); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.progress div { height: 100%; background: var(--ok); transition: width .2s; }
.ci { display: flex; align-items: center; gap: 10px; padding: 4px 2px; border-radius: 7px; }
.ci .check { width: 18px; height: 18px; font-size: 10px; border-width: 2px; }
.ci input.txt { flex: 1; border: 0; background: transparent; outline: none; padding: 2px 0; min-width: 0; }
.ci.done input.txt { color: var(--muted); text-decoration: line-through; }
.x { border: 0; background: transparent; color: var(--muted); opacity: 0; border-radius: 6px; padding: 2px 7px; }
.ci:hover .x, .link:hover .x, .file:hover .x, .img:hover .x { opacity: 1; }
@media (hover: none) { .x { opacity: .7; } }
.add-in { width: 100%; border: 1px dashed var(--line); background: transparent; border-radius: 8px; padding: 7px 10px; outline: none; margin-top: 6px; resize: vertical; }
.link { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--bg); margin-bottom: 4px; min-width: 0; }
.link a { flex: 1; min-width: 0; text-decoration: none; display: flex; flex-direction: column; }
.link .ltitle { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.link .ltitle.muted { color: var(--muted); font-weight: 400; font-style: italic; font-size: 13px; }
.link .lurl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.link .ltitle + .lurl .host { font-weight: 500; color: var(--muted); }
.link .host { font-weight: 600; color: var(--ink); }
.link .path { color: var(--muted); }
.imgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; margin-bottom: 8px; }
.img { position: relative; aspect-ratio: 1; }
.img img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; cursor: zoom-in; border: 1px solid var(--line); }
.img .x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff; }
.file { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 9px; background: var(--bg); margin-bottom: 4px; }
.file .fi { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 750; color: #fff; flex: none; }
.fi.sheet { background: #2f9e44; } .fi.doc { background: #1971c2; } .fi.pdf { background: #e03131; } .fi.file { background: #868e96; }
.file .fname { flex: 1; min-width: 0; }
.file .fname div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .fname small { color: var(--muted); }
.drop-hint { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.drop-hint label { color: var(--accent); cursor: pointer; text-decoration: underline; }
.d-foot { margin-top: 28px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- overlays */
#dropzone { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); display: none; place-items: center; z-index: 60; pointer-events: none; }
#dropzone div { background: var(--panel); padding: 18px 28px; border-radius: 14px; font-weight: 650; border: 2px dashed var(--accent); }
body.dragging #dropzone { display: grid; }
#modal { position: fixed; inset: 0; background: rgba(10,10,12,.62); z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal-box { background: var(--panel); border-radius: 14px; max-width: min(1100px, 100%); max-height: 100%; overflow: auto; position: relative; padding: 22px; min-width: min(420px, 100%); }
.modal-box.bare { background: transparent; padding: 0; overflow: visible; }
.modal-x { position: absolute; top: 8px; right: 8px; border: 0; background: var(--soft); border-radius: 50%; width: 30px; height: 30px; z-index: 2; }
.lightbox { display: flex; align-items: center; gap: 10px; }
.lightbox img { max-width: calc(100vw - 140px); max-height: calc(100vh - 60px); border-radius: 8px; display: block; }
.lightbox .nav { border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 26px; width: 44px; height: 44px; border-radius: 50%; }
.lightbox .cap { position: absolute; bottom: -28px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }
.lightbox .cap a { color: #fff; }
.sheet-tabs { display: flex; gap: 4px; margin: 8px 0 10px; flex-wrap: wrap; }
.sheet-tabs button { border: 1px solid var(--line); background: transparent; border-radius: 7px; padding: 3px 10px; font-size: 13px; }
.sheet-tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.sheet-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; }
table.sheet { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.sheet th, table.sheet td { border: 1px solid var(--line); padding: 4px 8px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.sheet th { background: var(--soft); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
table.sheet td.rh { background: var(--soft); color: var(--muted); text-align: right; position: sticky; left: 0; }
.doc-text { white-space: pre-wrap; max-width: 760px; font-size: 14.5px; line-height: 1.6; max-height: 72vh; overflow: auto; }
.modal-body h2 { margin: 0 30px 4px 0; font-size: 17px; word-break: break-all; }
.muted { color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 80; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); max-width: calc(100vw - 30px); }
#toast button { border: 0; background: transparent; color: var(--accent); font-weight: 700; }

/* ---------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login { padding: 30px; display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }
.login input { border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 10px 12px; outline: none; }
.login input:focus { border-color: var(--accent); }
.login .btn { justify-content: center; padding: 10px; }
.err { color: var(--over); margin: 0; min-height: 1.2em; font-size: 14px; text-align: center; }

/* ---------- responsive */
@media (min-width: 1300px) {
  #app.has-detail { grid-template-columns: var(--side) 1fr var(--detail); }
  #app.has-detail #detail { position: sticky; height: 100vh; transform: none; box-shadow: none; }
  #app.has-detail #detail:not(.show) { display: none; }
}
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 40; background: var(--panel); transform: translateX(-102%); transition: transform .2s; }
  body.side-open #sidebar { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  #menu { display: block; margin-left: -8px; }
  .topbar h1 { font-size: 22px; }
  .search input { width: 130px; }
  .search input:focus { width: 180px; }
  #main { padding-top: max(12px, env(safe-area-inset-top)); }
  #detail { width: 100vw; border-left: 0; padding-top: max(14px, env(safe-area-inset-top)); }
  .composer-bar .hint { display: none; }
  .composer-bar { justify-content: space-between; }
  .lightbox .nav { position: absolute; bottom: -54px; }
  .lightbox .nav.prev { left: 30%; } .lightbox .nav.next { right: 30%; }
  .lightbox img { max-width: calc(100vw - 40px); max-height: calc(100vh - 140px); }
  .x { opacity: .7; }
}
