/* TurboDM — controle pelo celular/tablet/PC.
   Cores de estado têm significado fixo: fluxo = baixando, âmbar = na fila,
   cinza = pausado, verde = concluído, vermelho = erro. */

@font-face { font-family: "Archivo"; src: url("fonts/archivo.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/plex-mono-500.woff2") format("woff2");
  font-weight: 500; font-display: swap; }

:root {
  --bg: #EDF0F5; --surface: #FFFFFF; --surface-2: #F5F7FA; --line: #DBE1EA; --line-2: #C8D0DC;
  --ink: #101828; --ink-2: #475467; --ink-3: #7B8698;
  --brand: #1A5FD6; --brand-2: #144BAA; --brand-soft: #E3ECFB; --on-brand: #FFFFFF;
  --flow: #0B8F8A; --flow-soft: #DDF3F1;
  --queue: #B7790A; --queue-soft: #FBF0D9;
  --idle: #7B8698; --idle-soft: #ECEFF3;
  --done: #1E8E4E; --done-soft: #DFF3E7;
  --err: #CC3B3B; --err-soft: #FBE5E5;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 18px 48px -12px rgba(16,24,40,.28);
  --scrim: rgba(10,15,25,.48);
  --radius: 12px; --radius-sm: 8px;
  --ui: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --side-w: 256px; --detail-w: 400px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D121A; --surface: #141B26; --surface-2: #1A2330; --line: #243041; --line-2: #2F3D52;
    --ink: #E7EBF2; --ink-2: #A8B2C2; --ink-3: #758196;
    --brand: #5B8CF0; --brand-2: #7AA2F5; --brand-soft: #1A2B4A; --on-brand: #FFFFFF;
    --flow: #2BC2B9; --flow-soft: #103532; --queue: #E2A93A; --queue-soft: #3A2C10;
    --idle: #8D98AB; --idle-soft: #212B39; --done: #43C27A; --done-soft: #12301F;
    --err: #F06A6A; --err-soft: #3A1818;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 18px 48px -12px rgba(0,0,0,.7); --scrim: rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D121A; --surface: #141B26; --surface-2: #1A2330; --line: #243041; --line-2: #2F3D52;
  --ink: #E7EBF2; --ink-2: #A8B2C2; --ink-3: #758196;
  --brand: #5B8CF0; --brand-2: #7AA2F5; --brand-soft: #1A2B4A; --on-brand: #FFFFFF;
  --flow: #2BC2B9; --flow-soft: #103532; --queue: #E2A93A; --queue-soft: #3A2C10;
  --idle: #8D98AB; --idle-soft: #212B39; --done: #43C27A; --done-soft: #12301F;
  --err: #F06A6A; --err-soft: #3A1818;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 18px 48px -12px rgba(0,0,0,.7); --scrim: rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.45 var(--ui); font-stretch: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#i-play path, #i-bolt path, #i-pause rect, #i-more circle { fill: currentColor; stroke: none; }
.mono { font-variant-numeric: tabular-nums; }
.code { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0; }

/* ---------- botões e campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px; background: var(--surface-2); color: var(--ink);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn.solid-danger { background: var(--err); color: #fff; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.sm .i { width: 16px; height: 16px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.sm { width: 34px; }
.btn.block { width: 100%; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--surface); color: var(--ink); }
.field textarea { min-height: 84px; resize: vertical; }
.hint { font-size: 13px; color: var(--ink-3); margin: 0; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 24px; border-radius: 12px; background: var(--line-2); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- estrutura (celular primeiro) ---------- */
.app { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; grid-template-areas: "top" "main" "bottom"; }
.side { display: none; }
.top { grid-area: top; position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; font-stretch: 118%; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.main { grid-area: main; min-width: 0; padding: 16px 16px 24px; }
.bottom { grid-area: bottom; position: sticky; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom-btn { display: grid; justify-items: center; gap: 2px; padding: 8px 4px 10px; border: 0; background: none; color: var(--ink-3); font-size: 12px; font-weight: 600; cursor: pointer; }
.bottom-btn[aria-current="page"] { color: var(--brand); }
html.embed .top .brand { display: none; }

/* ---------- faixa de velocidade (assinatura) ---------- */
.meter { position: relative; }
.meter-read { display: flex; align-items: baseline; gap: 6px; position: relative; z-index: 1; }
.meter-num { font-variant-numeric: tabular-nums; font-size: 38px; font-weight: 650; font-stretch: 112%; line-height: 1; letter-spacing: -.035em; }
.meter-unit { font-weight: 700; font-size: 13px; font-stretch: 118%; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.meter-graph { display: block; width: 100%; height: 44px; margin-top: 6px; overflow: visible; }
.meter-area { fill: var(--flow-soft); }
.meter-line { fill: none; stroke: var(--flow); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.meter-sub { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }
.meter-sub b { font-weight: 600; color: var(--ink); }
.meter-compact { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: end; margin-top: 10px; }
.meter-compact .meter-read { grid-row: 1; grid-column: 1; }
.meter-compact .meter-num { font-size: 32px; }
.meter-compact .meter-graph { grid-row: 1; grid-column: 2; height: 32px; margin: 0; }
.meter-compact .meter-sub { grid-row: 2; grid-column: 1 / -1; margin-top: 6px; }
.limit-chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: var(--queue-soft); color: var(--queue); font-size: 12px; font-weight: 600; }

/* ---------- conexão com o PC ---------- */
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--idle); flex: none; }
.conn.on .dot { background: var(--done); box-shadow: 0 0 0 3px var(--done-soft); }
.conn.off .dot { background: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.conn .txt { display: grid; min-width: 0; }
.conn .txt b { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn .txt small { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-compact .txt small { display: none; }

/* ---------- conta iwil (só no relay) ---------- */
.acct { display: grid; gap: 4px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; min-width: 0; }
.acct b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct small { color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct .links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- cabeçalho da seção ---------- */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.view-head h1 { font-size: 24px; font-weight: 700; font-stretch: 118%; letter-spacing: -.02em; }
.head-actions { display: flex; gap: 8px; }

/* ---------- adicionar link ---------- */
.addbar { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.addbar:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.addbar-ico { color: var(--ink-3); }
.addbar input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 8px 0; font-size: 15px; }

/* ---------- filtros e busca ---------- */
.listbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; flex: 1 1 100%; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; cursor: pointer; }
.chip .n { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-3); }
.chip[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip[aria-selected="true"] .n { color: inherit; opacity: .7; }
.listbar-right { display: flex; gap: 8px; flex: 1 1 100%; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink-3); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
#btn-select[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.bulk { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 12px;
  border-radius: 12px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 14px; }
.bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.bulk .btn { background: var(--surface); }

/* ---------- lista de downloads ---------- */
.list { display: grid; gap: 8px; }
.item, .detail { --tone: var(--idle); --tone-soft: var(--idle-soft); }
.s-downloading, .s-connecting { --tone: var(--flow); --tone-soft: var(--flow-soft); }
.s-queued { --tone: var(--queue); --tone-soft: var(--queue-soft); }
.s-completed { --tone: var(--done); --tone-soft: var(--done-soft); }
.s-error { --tone: var(--err); --tone-soft: var(--err-soft); }
.item {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 12px 12px 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, box-shadow .15s; }
.item:hover { border-color: var(--line-2); }
.item.is-open { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.item.is-selected { border-color: var(--brand); background: var(--brand-soft); }
.item-sel { display: none; width: 22px; height: 22px; accent-color: var(--brand); margin: 0; }
.selecting .item-sel { display: block; }
.selecting .item { grid-template-columns: auto auto 1fr auto; }
.kind { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--tone-soft); color: var(--tone); }
.item-body { min-width: 0; display: grid; gap: 6px; }
.item-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.item-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-pct { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 12.5px; color: var(--ink-3); }
.item-meta .mono { color: var(--ink-2); font-weight: 500; }
.item-meta > span:empty { display: none; }
.state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--tone); }
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-downloading .state::before { animation: pulse 1.6s ease-in-out infinite; }
.item-err { margin: 0; font-size: 13px; color: var(--err); }
.item-acts { display: flex; gap: 4px; }
.item-acts .btn { width: 38px; min-height: 38px; padding: 0; border-radius: 10px; }
.item-acts .act-main { background: var(--tone-soft); color: var(--tone); }
.item-acts .act-main:hover { filter: brightness(.96); }

/* trilho de progresso: mostra as partes (conexões) quando o PC informa */
.rail { position: relative; height: 6px; border-radius: 3px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.rail-fill { position: absolute; inset: 0 auto 0 0; background: var(--tone); border-radius: 3px; transition: width .6s ease; }
.s-downloading .rail-fill { background-image: linear-gradient(90deg, transparent 0 40%, rgba(255,255,255,.35) 50%, transparent 60% 100%); background-size: 200% 100%; background-color: var(--tone); animation: sweep 2.2s linear infinite; }
.rail-parts { position: absolute; inset: 0; display: flex; }
.rail-parts i { position: relative; height: 100%; border-right: 2px solid var(--surface); }
.rail-parts i:last-child { border-right: 0; }
.rail-parts i b { position: absolute; inset: 0 auto 0 0; background: var(--tone); }
.rail.big { height: 12px; border-radius: 6px; }
.rail.indeterminate .rail-fill { width: 30% !important; animation: indet 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes sweep { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

@media (max-width: 759px) {
  .item { grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "kind name acts" "rail rail pct" "meta meta meta" "err err err"; gap: 8px 12px; padding: 12px; }
  .selecting .item { grid-template-columns: auto 40px minmax(0, 1fr) auto; grid-template-areas: "sel kind name acts" "sel rail rail pct" "sel meta meta meta" "sel err err err"; }
  .item-sel { grid-area: sel; align-self: center; }
  .kind { grid-area: kind; }
  .item-body, .item-top { display: contents; }
  .item-name { grid-area: name; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; align-self: center; }
  .item-pct { grid-area: pct; align-self: center; text-align: right; min-width: 4.5ch; }
  .item .rail { grid-area: rail; align-self: center; }
  .item-meta { grid-area: meta; }
  .item-err { grid-area: err; }
  .item-acts { grid-area: acts; }
  .s-completed .item-pct { display: none; }
  .s-completed .rail { grid-column: 1 / -1; }
}

.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty .i { width: 40px; height: 40px; color: var(--ink-3); margin-bottom: 10px; stroke-width: 1.5; }
.empty h2 { font-size: 18px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 auto 16px; max-width: 360px; }

/* ---------- painel de detalhes ---------- */
.detail { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); animation: slidein .2s ease; }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }
.d-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.d-head .grow { flex: 1; }
.d-title { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; margin-bottom: 14px; }
.d-title h2 { font-size: 18px; font-weight: 700; line-height: 1.3; word-break: break-word; }
.d-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.d-progress { display: grid; gap: 10px; }
.d-progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.d-progress-top .big { font-variant-numeric: tabular-nums; font-size: 32px; font-weight: 650; font-stretch: 112%; letter-spacing: -.035em; }
.d-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.kv { display: grid; gap: 2px; min-width: 0; }
.kv dt { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-stretch: 112%; }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-size: 14.5px; font-weight: 500; overflow-wrap: anywhere; }
.kv dd.txt { font-family: var(--ui); }
.d-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 10px 12px; font-weight: 600; font-size: 14px; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--brand); border-color: var(--brand); }
.parts-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(18px, 1fr)); gap: 3px; margin-bottom: 12px; }
.parts-map i { height: 18px; border-radius: 3px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); position: relative; overflow: hidden; }
.parts-map i b { position: absolute; inset: auto 0 0 0; background: var(--flow); }
.parts-map i.full b { background: var(--done); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td.mono { white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.chart { width: 100%; height: 160px; display: block; }
.chart .area { fill: var(--flow-soft); }
.chart .line { fill: none; stroke: var(--flow); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--brand-soft); color: var(--ink); font-size: 14px; }
.note .i { color: var(--brand); margin-top: 1px; }
.note.warn { background: var(--queue-soft); } .note.warn .i { color: var(--queue); }
.note.err { background: var(--err-soft); } .note.err .i { color: var(--err); }
.note a { color: var(--brand); font-weight: 600; }

/* ---------- folhas (diálogos) ---------- */
dialog.sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92dvh; background: transparent; color: var(--ink); }
dialog.sheet::backdrop { background: var(--scrim); }
dialog.sheet[open] { animation: up .22s ease; }
@keyframes up { from { transform: translateY(32px); opacity: 0; } }
.sheet-box { background: var(--surface); border-radius: 18px 18px 0 0; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head > .media-kind, .sheet-head > .thumb { flex: none; }
.sheet-head h2 { flex: 1; font-size: 19px; font-weight: 700; font-stretch: 112%; line-height: 1.3; word-break: break-word; }
.sheet-head p { margin: 4px 0 0; font-size: 13px; color: var(--ink-3); }
.sheet-foot { display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--surface);
  margin: 0 -16px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.menu-list { display: grid; gap: 2px; }
.menu-list button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 10px; border: 0; border-radius: 10px; background: none; text-align: left; font-weight: 500; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--err); }
.menu-list .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu-list .row-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 4px 0; }
.menu-list .row-btns button { justify-content: center; flex-direction: column; gap: 4px; font-size: 12px; padding: 10px 4px; background: var(--surface-2); }

/* análise do link */
.media-head { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.thumb { width: 120px; aspect-ratio: 16 / 9; border-radius: 10px; object-fit: cover; background: var(--surface-2); }
.media-kind { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.media-kind .i { width: 26px; height: 26px; }
.opts { display: grid; gap: 8px; }
.opt { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--surface); }
.opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.opt b { font-weight: 600; }
.opt small { display: block; color: var(--ink-3); font-size: 12.5px; }
.opt .sz { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.opt .warn { color: var(--queue); }
.checklist { border: 1px solid var(--line); border-radius: 12px; max-height: 46dvh; overflow-y: auto; }
.check-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.check-row:last-child { border-bottom: 0; }
.check-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.check-row .t { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.check-row .t small { display: block; color: var(--ink-3); font-size: 12px; }
.check-row .mono { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.langs { display: flex; flex-wrap: wrap; gap: 6px; }
.lang { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 600; cursor: pointer; }
.lang[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .9s linear infinite; margin: 8px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-check { width: 56px; height: 56px; border-radius: 50%; margin: 4px auto; display: grid; place-items: center; background: var(--done-soft); color: var(--done); }
.big-check .i { width: 30px; height: 30px; stroke-width: 2.5; }
.center { text-align: center; }

/* ---------- estatísticas e ajustes ---------- */
.stats, .settings { display: grid; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.tile dt { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-stretch: 112%; }
.tile dd { margin: 6px 0 0; font-variant-numeric: tabular-nums; font-weight: 650; font-stretch: 112%; font-size: 20px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; }
.card h2 { font-size: 16px; font-weight: 700; font-stretch: 112%; display: flex; align-items: center; gap: 10px; }
.card h2 .i { color: var(--brand); }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bars { display: grid; grid-template-columns: repeat(14, 1fr); align-items: end; gap: 4px; height: 150px; }
.bars div { display: grid; align-items: end; height: 100%; }
.bars i { display: block; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars div:last-child i { background: var(--flow); }
.bars-x { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; font-size: 10.5px; color: var(--ink-3); text-align: center; font-variant-numeric: tabular-nums; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; }
.days button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.time-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.card input[type="time"], .card input[type="number"] { min-height: 40px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink); }
.range-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.range-row input[type="range"] { width: 100%; accent-color: var(--brand); }
.range-row output { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3ch; text-align: right; }
.radio-list { display: grid; gap: 6px; }
.radio-list label { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.radio-list label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.radio-list input { accent-color: var(--brand); width: 18px; height: 18px; margin: 0; }

/* ---------- avisos ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 14px; border-radius: 12px; background: var(--ink); color: var(--surface); font-size: 14px; box-shadow: var(--shadow-lg); animation: up .2s ease; }
.toast.err { background: var(--err); color: #fff; }

/* ---------- tablet: barra lateral ---------- */
@media (min-width: 760px) {
  .app { grid-template-columns: var(--side-w) minmax(0, 1fr); grid-template-rows: 1fr; grid-template-areas: "side main"; }
  .top, .bottom { display: none; }
  .side { grid-area: side; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    padding: 20px 16px; background: var(--surface); border-right: 1px solid var(--line); }
  .nav { display: grid; gap: 2px; }
  .nav-btn, .side-filter { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 10px; background: none;
    color: var(--ink-2); font-weight: 600; font-size: 14px; cursor: pointer; text-align: left; }
  .nav-btn:hover, .side-filter:hover { background: var(--surface-2); }
  .nav-btn[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
  .side-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 10px 6px; font-stretch: 118%; }
  .side-filters { display: grid; gap: 1px; }
  .side-filter { font-weight: 500; padding: 7px 10px; }
  .side-filter .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ink-3)); flex: none; }
  .side-filter .lbl { flex: 1; }
  .side-filter .n { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-3); }
  .side-filter[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
  .side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
  .main { padding: 28px 28px 40px; }
  .chips { display: none; }
  .listbar-right { flex: 1 1 auto; max-width: 420px; margin-left: auto; }
  .listbar { justify-content: flex-end; }
  .detail { inset: 0 0 0 auto; width: min(var(--detail-w), 100%); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); padding: 20px; }
  dialog.sheet { margin: auto; width: min(640px, calc(100% - 48px)); }
  dialog.sheet.small { width: min(420px, calc(100% - 48px)); }
  .sheet-box { border-radius: 18px; padding: 22px 22px 22px; box-shadow: var(--shadow-lg); }
  .sheet-foot { bottom: -22px; margin: 0 -22px -22px; padding: 14px 22px 18px; }
  .sheet-foot .btn { flex: 0 0 auto; }
  .sheet-foot .btn.primary { margin-left: auto; order: 9; }
  .toasts { bottom: 24px; }
  .tiles { gap: 12px; }
  .tile dd { font-size: 26px; }
  .settings { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
}

/* ---------- desktop: detalhes como terceira coluna ---------- */
@media (min-width: 1180px) {
  .app.has-detail { grid-template-columns: var(--side-w) minmax(0, 1fr) var(--detail-w); grid-template-areas: "side main detail"; }
  .app.has-detail .detail { grid-area: detail; position: sticky; top: 0; height: 100dvh; inset: auto; width: auto; box-shadow: none; animation: none; background: var(--surface); }
  .item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .detail .d-back { display: none; }
}
@media (min-width: 1500px) { :root { --detail-w: 440px; } .main { padding: 32px 40px 48px; } }

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