:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --line: #e3e6ef;
  --text: #1b1f2a;
  --muted: #6b7286;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --p3: #e5484d;
  --p2: #f08c00;
  --p1: #3b82f6;
  --p0: #a0a7b8;
  --ok: #12a150;
  --danger: #d92d20;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --tab-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a22;
    --surface-2: #1e222c;
    --line: #2a2f3b;
    --text: #e8eaf0;
    --muted: #9399a8;
    --accent: #7b93ff;
    --accent-soft: #232a45;
    --p3: #ff6b70;
    --p2: #ffa94d;
    --p1: #6aa6ff;
    --p0: #5c6375;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.err { color: var(--danger); font-size: 13px; min-height: 1em; }
.ic { width: 20px; height: 20px; flex: none; }

/* ---------- Layout ---------- */
#app { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
#sidebar { display: none; }
#main { padding: 14px 14px calc(var(--tab-h) + 90px + env(safe-area-inset-bottom)); max-width: 980px; width: 100%; margin: 0 auto; }

@media (min-width: 860px) {
  #app { grid-template-columns: 264px 1fr; }
  #sidebar {
    display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px;
  }
  #main { padding: 22px 32px 100px; }
  #tabbar { display: none !important; }
  #fab { bottom: 28px !important; right: 32px !important; }
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 14px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text);
  cursor: pointer; font-size: 14.5px;
}
.side-link:hover { background: var(--surface-2); }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link .count { margin-left: auto; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.side-link.active .count { color: var(--accent); }
.side-link .count.red { color: var(--p3); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c, var(--p0)); margin: 0 5px; }
.side-section { margin-top: 14px; }
.side-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; font-weight: 600; }
.side-add { background: none; border: 0; color: var(--muted); padding: 8px 10px; cursor: pointer; font-size: 14px; text-align: left; width: 100%; border-radius: 10px; }
.side-add:hover { background: var(--surface-2); color: var(--text); }
.side-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }

/* ---------- Topo ---------- */
#topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 2px 12px; }
#topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
#view-sub { font-size: 13.5px; margin-top: 2px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--line); width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--text); }
.icon-btn.spin .ic { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Banner ---------- */
#banner:empty { display: none; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px;
  background: var(--accent-soft); color: var(--text); font-size: 14px;
}
.banner.warn { background: color-mix(in srgb, var(--p2) 16%, var(--surface)); }
.banner .grow { flex: 1; }

/* ---------- Entrada rápida ---------- */
#quickadd { margin-bottom: 16px; }
.qa-box {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 8px 4px 12px; box-shadow: var(--shadow);
}
.qa-box:focus-within { border-color: var(--accent); }
.qa-plus { color: var(--accent); }
#qa-input { flex: 1; border: 0; outline: 0; background: none; padding: 11px 2px; min-width: 0; font-size: 15.5px; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 8px; font-weight: 600; font-size: 14px; }
#qa-preview { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 4px 0; }
#qa-preview:empty { display: none; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px;
  background: color-mix(in srgb, var(--c, var(--p0)) 14%, transparent); color: var(--c, var(--muted)); font-weight: 600;
  white-space: nowrap;
}
.chip .ic { width: 13px; height: 13px; }

/* ---------- Painel ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  cursor: pointer; box-shadow: var(--shadow); text-align: left; transition: transform .1s;
}
.stat:active { transform: scale(.98); }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.red .n { color: var(--p3); }
.stat.blue .n { color: var(--accent); }
.stat.green .n { color: var(--ok); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 2px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.dash-cols { display: grid; gap: 18px; }
@media (min-width: 1180px) { .dash-cols { grid-template-columns: 1fr 1fr; } }

.section { margin-bottom: 18px; }
.section-h { display: flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); margin: 0 4px 8px; }
.section-h.red { color: var(--p3); }
.section-h .n { font-weight: 600; }
.empty { color: var(--muted); padding: 18px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); font-size: 14px; }
.empty.big { padding: 40px 18px; }

/* ---------- Tarefas ---------- */
.tasks { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); cursor: pointer; position: relative; }
.task:first-child { border-top: 0; }
.task:hover { background: var(--surface-2); }
.check {
  --pc: var(--p0);
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--pc); background: color-mix(in srgb, var(--pc) 10%, transparent);
  flex: none; cursor: pointer; margin-top: 1px; display: grid; place-items: center; padding: 0;
}
.check::after { content: ""; width: 10px; height: 5px; border: 2.2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.p1 .check { --pc: var(--p1); } .p2 .check { --pc: var(--p2); } .p3 .check { --pc: var(--p3); }
.task.done .check, .check.checked { background: var(--pc); }
.task.done .check::after, .check.checked::after { opacity: 1; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.task.leaving { opacity: .45; transition: opacity .25s; }
.t-body { flex: 1; min-width: 0; }
.t-title { font-size: 15px; word-wrap: break-word; }
.t-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.t-meta .m { display: inline-flex; align-items: center; gap: 4px; }
.t-meta .ic { width: 13px; height: 13px; }
.t-meta .late { color: var(--p3); font-weight: 600; }
.t-meta .today { color: var(--accent); font-weight: 600; }
.pflag { font-size: 11px; font-weight: 700; color: var(--p3); }
.task.compact { padding: 9px 12px; }

/* ---------- Matriz ---------- */
.matrix { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 620px) { .matrix { grid-template-columns: 1fr 1fr; } }
.quad { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; min-height: 180px; }
.quad-h { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); border-top: 4px solid var(--qc); }
.quad-h b { display: flex; justify-content: space-between; font-size: 15px; }
.quad-h small { color: var(--muted); font-size: 12.5px; }
.quad .tasks { border: 0; border-radius: 0; box-shadow: none; }
.quad .empty { border: 0; background: none; padding: 26px 14px; }
.q1 { --qc: var(--p3); } .q2 { --qc: var(--accent); } .q3 { --qc: var(--p2); } .q4 { --qc: var(--p0); }

/* ---------- Listas ---------- */
.list-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 18px; }
.list-card {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer;
}
.list-card .name { flex: 1; font-weight: 600; }
.list-card .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.list-card .ic { color: var(--muted); }
.toggle-done { margin: 14px 4px; }

/* ---------- Ajustes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card p { margin: 4px 0 12px; color: var(--muted); font-size: 13.5px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
.set-row .lbl { flex: 1; }
.set-row .lbl small { display: block; color: var(--muted); font-size: 12.5px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.device { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.device:first-child { border-top: 0; }
.device .grow { flex: 1; }
.device small { color: var(--muted); display: block; font-size: 12px; }
.tag-this { font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 1px 7px; border-radius: 99px; font-weight: 600; margin-left: 6px; }
.list-edit { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.list-edit:first-child { border-top: 0; }
.list-edit input[type=text] { flex: 1; }
.list-edit input[type=color] { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--surface); }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); padding: 9px 14px; border-radius: 11px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn.danger-ghost { color: var(--danger); border-color: transparent; background: none; }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 10px; outline: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.switch { appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.chip-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 11px; font-size: 13px; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Abas (celular) ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line); display: flex; z-index: 20;
}
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; color: var(--muted); }
#tabbar a.active { color: var(--accent); font-weight: 600; }
#tabbar .ic { width: 22px; height: 22px; }
#fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 18px; border: 0; background: var(--accent); color: #fff; box-shadow: 0 8px 24px rgba(59,91,219,.35);
  display: grid; place-items: center; cursor: pointer; z-index: 21;
}
#fab .ic { width: 26px; height: 26px; }

/* ---------- Editor (folha) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 24, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.overlay.center { align-items: center; background: var(--bg); }
.sheet {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column; box-shadow: 0 -8px 40px rgba(0,0,0,.2); animation: up .2s ease-out;
}
@media (min-width: 700px) { .overlay:not(.center) { align-items: center; } .sheet { border-radius: 20px; max-height: 88vh; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sheet-body { padding: 16px; overflow-y: auto; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.ed-title { font-size: 18px !important; font-weight: 600; border: 0 !important; padding: 4px 0 !important; border-radius: 0 !important; }
#ed-notes { margin: 6px 0 4px; border: 0; padding: 4px 0; background: none; border-radius: 0; color: var(--muted); }
.field { margin-top: 16px; }
.field > label, .field > .lbl { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 7px; }
.grid2 { display: grid; gap: 0 16px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 9px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.p1.on { color: var(--p1); } .seg button.p2.on { color: var(--p2); } .seg button.p3.on { color: var(--p3); }
.date-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick-dates button { border: 1px solid var(--line); background: none; border-radius: 99px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.quick-dates button:hover { color: var(--accent); border-color: var(--accent); }
#ed-custom { margin-top: 8px; }
.switch-row { display: flex !important; align-items: center; justify-content: space-between; gap: 12px; text-transform: none !important; letter-spacing: 0 !important; font-size: 14.5px !important; color: var(--text) !important; font-weight: 600 !important; }
.switch-row small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.insist-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.insist-row select { width: auto; }
.subs { list-style: none; margin: 0; padding: 0; }
.subs li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.subs li .check { width: 20px; height: 20px; border-radius: 6px; --pc: var(--accent); }
.subs li span { flex: 1; font-size: 14.5px; }
.subs li.done span { text-decoration: line-through; color: var(--muted); }
.subs li .rm { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; display: grid; }
.sub-add { display: flex; gap: 8px; margin-top: 6px; }
.ed-actions { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); }
.snooze { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; font-size: 13.5px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------- Login ---------- */
.login-card { width: min(340px, 92vw); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 22px; }
.login-card img { border-radius: 14px; }
.login-card h2 { margin: 0 0 6px; }
.login-card .btn { width: 100%; }

/* ---------- Aviso (toast) ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1b1f2a; color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; display: flex; gap: 14px;
  align-items: center; opacity: 0; pointer-events: none; transition: all .2s; z-index: 80; max-width: 92vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: #9db0ff; font-weight: 700; cursor: pointer; padding: 0; }
@media (min-width: 860px) { #toast { bottom: 30px; } }
