:root {
  --bg: #f4f3ef; --surface: #ffffff; --surface-2: #f0eee8; --surface-3: #e8e5dd;
  --text: #1d2125; --muted: #5f6872; --border: #e0ddd4; --accent: #1b5fbf; --accent-soft: #e5eefb;
  --ok: #1f7a46; --ok-soft: #e3f3e9; --danger: #b3261e; --danger-soft: #fbe9e7; --warn: #a15c00;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.03);
  --shadow-lift: 0 10px 24px rgba(0,0,0,.14);
  --radius: 12px;
  color-scheme: light;
}
/* Temas: claro (padrão), claro suave, escuro suave e escuro. Sem escolha, segue o sistema. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121417; --surface: #1b1e22; --surface-2: #23272c; --surface-3: #2c3137;
    --text: #e7e6e2; --muted: #9ba4ae; --border: #2e3238; --accent: #82b2ff; --accent-soft: #1d2b40;
    --ok: #5cc98a; --ok-soft: #17301f; --danger: #ff8a80; --danger-soft: #3a1c1a; --warn: #f0b54a;
    --shadow: none; --shadow-lift: 0 10px 24px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121417; --surface: #1b1e22; --surface-2: #23272c; --surface-3: #2c3137;
  --text: #e7e6e2; --muted: #9ba4ae; --border: #2e3238; --accent: #82b2ff; --accent-soft: #1d2b40;
  --ok: #5cc98a; --ok-soft: #17301f; --danger: #ff8a80; --danger-soft: #3a1c1a; --warn: #f0b54a;
  --shadow: none; --shadow-lift: 0 10px 24px rgba(0,0,0,.5);
  color-scheme: dark;
}
/* Claro suave: cinza quente, menos brilho que o claro. */
:root[data-theme="light-soft"] {
  --bg: #d9d6cf; --surface: #e8e5df; --surface-2: #dfdcd5; --surface-3: #cdc9c0;
  --text: #23272b; --muted: #555d66; --border: #c4c0b7; --accent: #1a55aa; --accent-soft: #d0dcee;
  --ok: #1c6b3e; --ok-soft: #cfe3d6; --danger: #a0231c; --danger-soft: #ecd6d3; --warn: #8a4f00;
  --shadow: 0 1px 2px rgba(0,0,0,.07); --shadow-lift: 0 10px 24px rgba(0,0,0,.16);
  color-scheme: light;
}
/* Escuro suave: cinza-azulado, menos contraste que o escuro. */
:root[data-theme="dark-soft"] {
  --bg: #2b2f35; --surface: #373c43; --surface-2: #31363c; --surface-3: #454b53;
  --text: #e3e2de; --muted: #a6aeb7; --border: #484e56; --accent: #8fb9ff; --accent-soft: #35455a;
  --ok: #6cd197; --ok-soft: #2c4335; --danger: #ff9b91; --danger-soft: #4b2e2c; --warn: #f3be5e;
  --shadow: none; --shadow-lift: 0 10px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 15px; line-height: 1.45;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 9px;
  padding: 6px 11px; font-size: .88rem; line-height: 1.3; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 3px 8px; font-size: .8rem; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
.btn:disabled { opacity: .4; cursor: not-allowed; background: transparent; }
.icon-btn {
  border: 0; background: transparent; border-radius: 8px; padding: 4px 7px; color: var(--muted);
  line-height: 1; font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input[type="text"], input[type="number"], input[type="search"], input[type="password"], select, textarea {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 6px 9px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- topo ---------- */
.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 1.05rem; margin: 0 8px 0 0; white-space: nowrap; }
.top h1 small { color: var(--muted); font-weight: 400; }
.top .search { flex: 1; min-width: 180px; max-width: 420px; }
.top .search input { width: 100%; }
.top .spacer { flex: 1; }
.contador { font-size: .8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.contador b { color: var(--text); font-weight: 600; }
.sync { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync[data-state="saving"]::before { background: var(--warn); }
.sync[data-state="offline"]::before { background: var(--danger); }
.sync[data-state="offline"] { color: var(--danger); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lift); padding: 6px; z-index: 50;
}
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 8px 10px;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.menu-list .menu-rotulo { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 6px 10px 2px; }
.menu-list button[data-tema] { display: flex; align-items: center; gap: 9px; }
.menu-list button[data-tema]::after { content: "✓"; margin-left: auto; color: var(--accent); visibility: hidden; }
.menu-list button[data-tema][aria-pressed="true"]::after { visibility: visible; }
.amostra { width: 16px; height: 16px; border-radius: 5px; border: 1px solid rgba(128,128,128,.5); flex: none; }

/* ---------- resumo das matérias ---------- */
.resumo { padding: 14px 18px 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.resumo-grupo { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.chip {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 11px 4px 5px; font-size: .82rem; box-shadow: var(--shadow);
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 0; }
.chip .ring {
  --p: 0; --c: var(--accent);
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-3) 0);
  font-size: .62rem; font-weight: 700;
}
.chip .ring span { width: 20px; height: 20px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.chip .sub { color: var(--muted); }

/* ---------- quadro ---------- */
.board {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 12px 18px 40px;
  align-items: start;
}
.coluna {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: 12px;
  min-height: 200px;
}
.coluna-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 10px; }
.coluna-head .titulo { font-weight: 700; font-size: 1.02rem; }
.coluna-head .quando { color: var(--muted); font-size: .82rem; }
.coluna-head .stats { margin-left: auto; text-align: right; font-size: .8rem; color: var(--muted); }
.coluna-head .stats b { color: var(--text); font-size: .95rem; }
.coluna-bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin: 0 4px 12px; }
.coluna-bar > div { height: 100%; background: var(--ok); border-radius: inherit; transition: width .3s; }
.lista { display: flex; flex-direction: column; gap: 8px; min-height: 40px; position: relative; }
.vazio { color: var(--muted); font-size: .88rem; text-align: center; padding: 18px 8px; border: 1px dashed var(--border); border-radius: 10px; }

.concluidos { margin-top: 14px; }
.concluidos summary {
  cursor: pointer; color: var(--muted); font-size: .86rem; padding: 6px 4px; list-style: none; user-select: none;
}
.concluidos summary::before { content: "▸ "; }
.concluidos[open] summary::before { content: "▾ "; }
.concluidos .lista { margin-top: 6px; }

/* ---------- card ---------- */
.card {
  --cor: #888;
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 9px 12px 10px 15px; cursor: grab;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: var(--radius) 0 0 var(--radius);
  background: var(--cor);
}
.card:hover { border-color: color-mix(in srgb, var(--cor) 45%, var(--border)); }
.card.dragging { opacity: .35; }
.card.aberto { cursor: default; border-color: color-mix(in srgb, var(--cor) 60%, var(--border)); box-shadow: var(--shadow-lift); }
.card.feito .card-titulo { color: var(--muted); }
.card-top { display: flex; align-items: center; gap: 8px; font-size: .74rem; }
.card-materia { color: color-mix(in srgb, var(--cor) 80%, var(--text)); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.badge { font-size: .68rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; letter-spacing: .03em; }
.badge.proximo { background: var(--accent-soft); color: var(--accent); }
.badge.andamento { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.card-pct { margin-left: auto; font-weight: 700; font-size: .82rem; font-variant-numeric: tabular-nums; }
.card-pct.cheio { color: var(--ok); }
.card-titulo { font-weight: 600; margin: 3px 0 7px; font-size: .95rem; }
.barra {
  height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; cursor: pointer; position: relative;
}
.barra > div { height: 100%; background: var(--cor); border-radius: inherit; transition: width .2s; }
.card.feito .barra > div { background: var(--ok); }
.barra:hover { outline: 2px solid color-mix(in srgb, var(--cor) 40%, transparent); }
.card-info { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 7px; font-size: .78rem; color: var(--muted); }
.card-info .preview-nota { flex-basis: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: italic; }

/* card aberto */
.card-corpo { margin-top: 10px; display: flex; flex-direction: column; gap: 12px; cursor: auto; }
.campo-titulo { width: 100%; font-weight: 600; font-size: 1rem; background: transparent !important; border-color: transparent !important; padding: 4px 6px; margin-left: -6px; }
.campo-titulo:hover { border-color: var(--border) !important; }
.linha { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.rotulo { font-size: .74rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.progresso-ctrl { display: flex; align-items: center; gap: 10px; }
.progresso-ctrl input[type="range"] { flex: 1; accent-color: var(--cor); }
.progresso-ctrl output { font-weight: 700; min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.atalhos { display: flex; gap: 5px; margin-top: 6px; }
.atalhos .btn { flex: 1; }

.subs { display: flex; flex-direction: column; gap: 2px; }
.sub-item { display: flex; align-items: flex-start; gap: 6px; border-radius: 7px; padding: 1px 2px; }
.sub-item:hover { background: var(--surface-2); }
.sub-item input[type="checkbox"] { accent-color: var(--cor); width: 16px; height: 16px; flex: none; margin-top: 7px; }
.sub-item textarea { flex: 1; background: transparent; border-color: transparent; padding: 3px 5px; resize: none; overflow: hidden; line-height: 1.4; }
.sub-item textarea:hover { border-color: var(--border); }
.sub-item.feito textarea { text-decoration: line-through; color: var(--muted); }
.sub-item .icon-btn { visibility: hidden; font-size: .85rem; }
.sub-item:hover .icon-btn { visibility: visible; }

textarea.notas {
  width: 100%; min-height: 110px; resize: vertical; line-height: 1.5; font-size: .92rem;
  background: color-mix(in srgb, var(--cor) 5%, var(--surface-2));
}
.questoes { display: grid; grid-template-columns: repeat(3, 1fr) auto; gap: 8px; align-items: end; }
.questoes label { font-size: .74rem; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.questoes input { width: 100%; }
.questoes .taxa { font-weight: 700; font-size: .95rem; padding-bottom: 6px; white-space: nowrap; }
.card-rodape { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--border); padding-top: 10px; }
.card-rodape .origem { color: var(--muted); font-size: .76rem; margin-right: auto; }

/* indicador de soltura */
.drop-line { height: 3px; border-radius: 3px; background: var(--accent); margin: -2px 4px; pointer-events: none; }

/* ---------- modal ---------- */
.modal-fundo {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lift); width: min(760px, 100%);
  max-height: calc(100vh - 40px); overflow: auto; padding: 18px 20px;
}
.modal h2 { margin: 0 0 12px; font-size: 1.1rem; }
.mat-tabela { width: 100%; border-collapse: collapse; }
.mat-tabela th { text-align: left; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 4px 6px; }
.mat-tabela td { padding: 4px 6px; border-top: 1px solid var(--border); }
.mat-tabela input[type="text"] { width: 100%; }
.mat-tabela input[type="number"] { width: 70px; }
.mat-tabela input[type="color"] { width: 36px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }
.modal-acoes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: .88rem;
  box-shadow: var(--shadow-lift); display: flex; gap: 12px; align-items: center;
}
.toast button { background: transparent; border: 0; color: inherit; font-weight: 700; text-decoration: underline; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: min(360px, 100%);
  box-shadow: var(--shadow-lift); display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { margin: 0; font-size: 1.2rem; }
.login-box p { margin: 0; color: var(--muted); font-size: .9rem; }
.login-box input { padding: 10px 12px; }
.login-box .erro { color: var(--danger); font-size: .88rem; min-height: 1.2em; }

@media (max-width: 900px) {
  .board, .resumo { grid-template-columns: 1fr; }
  .top { padding: 8px 12px; }
  .board { padding: 10px 12px 30px; }
}
