/*
 * EchoSync no celular. Cores = coleção "EchoSync" do Figma (aliases do design system do Bookmark+),
 * modo Light/Dark seguindo o sistema. Layout = wireframes "Site mobile — PWA" e "Gerenciador no site mobile".
 */
:root {
  --bg: #f6f6f9;
  --card: #ffffff;
  --canvas: #f2f2f5;
  --border: #dbdbe0;
  --text: #1f1f24;
  --muted: #6b6b78;
  --accent: #2666f2;
  --accent-hover: #1d4ed8;
  --accent-soft: #e5f0ff;
  --on-accent: #ffffff;
  --red: #cc3333;
  --green: #33b266;
  --warn: #d96b0d;
  --radius-card: 8px;
  --radius-control: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* nomes usados pelo campo de tags do Bookmark+ */
  --line: var(--border);
  --surface: var(--card);
  --accent-bg: var(--accent-soft);
  --accent-text: var(--accent);
  --danger: var(--red);
  --radius: var(--radius-control);
  --chip-h: 28px;
  --color-text: var(--text);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212124;
    --card: #3b3b40;
    --canvas: #1e1e1e;
    --border: #b2b2bf59;
    --text: #ffffff;
    --muted: #b2b2bf;
    --accent-soft: #2666f226;
    --red: #ff8c8c;
    --accent-text: var(--text);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
mark { background: transparent; color: inherit; font-weight: 700; }
h1, h2, h3, p { margin: 0; }
.boot { padding: 40px 20px; color: var(--muted); }
.muted { color: var(--muted); }
.small, small { font-size: 12px; }
.error { color: var(--red); font-size: 14px; }
.ok { color: var(--green); font-weight: 600; }
.label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; margin-top: 4px; }
.hint { font-size: 12px; color: var(--muted); }
.empty { padding: 40px 12px; text-align: center; color: var(--muted); }

/* ---------- controles (WF/Button, WF/Input) ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--card); font-weight: 600; text-decoration: none; color: var(--text); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:active { background: var(--accent-hover); }
.btn--danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn--danger-text { border: 0; background: none; color: var(--red); font-weight: 600; min-height: 44px; align-self: flex-start; }
.btn--small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .45; }
.link { border: 0; background: none; padding: 4px 0; color: var(--accent); font-weight: 500; text-decoration: none; }
.link--strong { color: var(--text); font-weight: 600; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; font-size: 20px; color: var(--text); text-decoration: none; }
.icon-btn:active { background: var(--accent-soft); }
.input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--card); font-size: 16px; /* 16px: o iPhone não dá zoom */ }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.input--button { text-align: left; color: var(--text); }
textarea.input { resize: vertical; min-height: 96px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field > small { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions--split { justify-content: space-between; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }

/* chips (WF/Chip) e campo de tags do Bookmark+ */
.chip { display: inline-flex; align-items: center; gap: 6px; height: var(--chip-h); padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); font-size: 13px; font-weight: 500; white-space: nowrap; color: var(--text); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip__count { opacity: .65; font-size: 12px; }
.chip__x { margin-left: 2px; font-size: 16px; line-height: 1; opacity: .8; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips--scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips--scroll::-webkit-scrollbar { display: none; }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 44px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--card); }
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tag-input.is-invalid { border-color: var(--red); animation: shake .3s; }
.tag-input__chips { display: contents; }
.tag-input .chip { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); padding-right: 6px; }
.tag-input .chip__x { border: 0; background: none; padding: 0 2px; color: inherit; }
.tag-input__field { flex: 1; min-width: 100px; border: 0; outline: none; background: transparent; padding: 4px; font-size: 16px; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* abas (WF/Segmented) e Lista | Grid (WF/ViewToggle) */
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: var(--canvas); }
.segmented button { flex: 1; min-height: 34px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted); font-weight: 500; }
.segmented button.is-active { background: var(--card); border-color: var(--border); color: var(--text); font-weight: 600; }
.segmented--small button { min-height: 28px; padding: 0 10px; font-size: 13px; }

/* ---------- telas de entrada ---------- */
.onboard { max-width: 440px; margin: 0 auto; padding: calc(32px + var(--safe-top)) 20px 32px; display: grid; gap: 16px; }
.onboard h1 { font-size: 24px; line-height: 1.2; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 10px; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.who { font-size: 13px; color: var(--muted); }
.gbutton { min-height: 44px; }
.code-input { font: 600 24px/1.2 ui-monospace, "DM Mono", Menlo, monospace; letter-spacing: .08em; text-transform: uppercase; }

/* ---------- estrutura do app ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.appbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; min-height: 56px; padding: var(--safe-top) 8px 0 16px; background: var(--bg); border-bottom: 1px solid var(--border); }
.appbar h1 { flex: 1; font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .icon-btn:first-child { margin-left: -8px; }
.appbar__actions { display: flex; align-items: center; gap: 4px; }
.statusline { display: flex; align-items: center; gap: 8px; margin: 10px 16px 0; padding: 8px 12px; border-radius: var(--radius-card); background: var(--canvas); font-size: 13px; }
.statusline__text { flex: 1; display: grid; }
.statusline__text small { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.dot--busy { background: var(--accent); animation: pulse 1s infinite alternate; }
.dot--warn { background: var(--warn); }
.dot--err { background: var(--red); }
@keyframes pulse { to { opacity: .3; } }
.content { flex: 1; display: grid; align-content: start; gap: 12px; padding: 12px 16px calc(96px + var(--safe-bottom)); }
.bottomnav, .batchbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; padding: 6px 8px calc(6px + var(--safe-bottom)); background: var(--bg); border-top: 1px solid var(--border); }
.bottomnav a { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: 12px; text-decoration: none; }
.bottomnav a.is-active { color: var(--text); font-weight: 600; }
.nav__icon { position: relative; display: grid; place-items: center; width: 56px; height: 28px; border-radius: 14px; font-size: 16px; }
.bottomnav a.is-active .nav__icon { background: var(--accent-soft); color: var(--accent); }
.badge { position: absolute; top: -2px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.batchbar { gap: 8px; }
.batchbar .btn { flex: 1; }
.fab { position: fixed; right: 16px; bottom: calc(80px + var(--safe-bottom)); z-index: 6; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; font-size: 28px; text-decoration: none; box-shadow: 0 6px 16px #0003; }

/* ---------- favoritos ---------- */
.fav-top { display: grid; gap: 10px; }
.fav-body { display: grid; gap: 10px; }
.search { -webkit-appearance: none; appearance: none; }
.suggest { display: grid; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); padding: 6px 0; }
.suggest .label, .suggest .hint { padding: 4px 12px; }
.suggest__row { display: flex; justify-content: space-between; min-height: 44px; align-items: center; padding: 0 12px; border: 0; background: none; text-align: left; }
.suggest__row small { color: var(--muted); }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs .link { font-size: 13px; color: var(--muted); padding: 0; }
.folder-title { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; font-size: 20px; font-weight: 700; text-align: left; }
.folder-title span { color: var(--muted); font-size: 16px; }
.chips--clamp { max-height: none; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { display: grid; align-content: start; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile.is-selected, .row.is-selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.tile.is-selected .tile__thumb::before, .row.is-selected .row__icon::before { content: "✓"; position: absolute; top: 6px; left: 6px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 13px; }
.tile__thumb { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 10; background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 45% 32%); font-size: 30px; font-weight: 700; }
@media (prefers-color-scheme: dark) { .tile__thumb { background: hsl(var(--h) 30% 26%); color: hsl(var(--h) 60% 80%); } }
.tile__body { display: grid; gap: 3px; padding: 8px 10px 10px; min-width: 0; }
.tile h3 { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__url { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__tags { display: flex; flex-wrap: wrap; gap: 4px; overflow: hidden; max-height: 22px; }
.tag { display: inline-block; max-width: 100%; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__note { font-size: 11px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list { display: grid; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 12px; border-bottom: 1px solid var(--border); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.row:last-child { border-bottom: 0; }
.row__icon { position: relative; flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 45% 32%); font-weight: 700; }
.row__info { min-width: 0; }
.row h3 { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row p { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { height: 1px; }

/* pastas (WF/FolderRow, WF/TreeRow) */
.rows { display: grid; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); overflow: hidden; }
.folder { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); }
.folder:last-child { border-bottom: 0; }
.folder.is-active { background: var(--accent-soft); }
.folder__main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 4px 8px 12px; border: 0; background: none; text-align: left; }
.folder__icon { flex: none; width: 20px; height: 15px; border-radius: 3px; background: var(--muted); opacity: .8; }
.folder.is-active .folder__icon, .tree__row.is-active .folder__icon { background: var(--accent); opacity: 1; }
.folder__name { flex: 1; min-width: 0; display: grid; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder__name small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.folder.is-active .folder__name { font-weight: 600; }
.folder__count { color: var(--muted); }
.folder__enter { flex: none; width: 44px; border: 0; background: none; color: var(--muted); font-size: 22px; font-weight: 700; }
.tree { display: grid; }
.tree__row { display: flex; align-items: center; min-height: 44px; padding-left: calc(var(--lv) * 18px); border-radius: 6px; }
.tree__row.is-active { background: var(--accent-soft); font-weight: 600; }
.tree__toggle { width: 32px; height: 40px; border: 0; background: none; color: var(--muted); font-weight: 700; }
.tree__toggle[hidden] { display: block !important; visibility: hidden; }
.tree__name { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 40px; border: 0; background: none; text-align: left; }
.tree__name small { margin-left: auto; padding-right: 8px; color: var(--muted); }

/* tags (WF/TagCheckRow) */
.tagrow { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px; border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; }
.tagrow:last-child { border-bottom: 0; }
.tagrow.is-active { background: var(--accent-soft); font-weight: 600; }
.tagrow .box { display: grid; place-items: center; width: 20px; height: 20px; border: 1.5px solid var(--muted); border-radius: 4px; font-size: 13px; color: #fff; }
.tagrow.is-active .box { background: var(--accent); border-color: var(--accent); }
.tagrow__name { flex: 1; }
.tagrow small { color: var(--muted); }
.sticky-actions { position: sticky; bottom: calc(76px + var(--safe-bottom)); display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; background: var(--bg); }
.sticky-actions .btn--primary { flex: 1; }

/* formulário do favorito */
.form { display: grid; gap: 14px; }

/* lobby, aparelhos, pareamento */
.lobby { display: grid; gap: 10px; }
.card { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); }
.card h3 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.device:last-child { border-bottom: 0; }
.device__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--canvas); color: var(--muted); }
.device__info { flex: 1; min-width: 0; display: grid; }
.device__info small { color: var(--muted); }
.pill { padding: 2px 8px; border-radius: 999px; background: var(--canvas); font-size: 12px; color: var(--muted); white-space: nowrap; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); text-align: left; }
.choice.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice b, .choice small { display: block; }
.choice small { color: var(--muted); }
.radio { flex: none; width: 18px; height: 18px; margin-top: 2px; border: 1.5px solid var(--muted); border-radius: 50%; }
.choice.is-active .radio { border: 5px solid var(--accent); }
.pair { display: grid; gap: 12px; }
.codebox { display: grid; gap: 8px; padding: 14px; border-radius: var(--radius-card); background: var(--canvas); }
.code { font: 700 32px/1.1 ui-monospace, "DM Mono", Menlo, monospace; letter-spacing: .06em; }
.qr { display: grid; justify-items: center; gap: 8px; text-align: center; }
.qr svg { width: 200px; height: 200px; border-radius: 8px; }
.qr--row { grid-template-columns: 110px 1fr; justify-items: start; text-align: left; align-items: center; }
.qr--row svg { width: 110px; height: 110px; }
.step { font-weight: 600; }
.waiting { color: var(--muted); }

/* ---------- camadas: folha de baixo, diálogo, aviso ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: #0008; animation: fade .15s; }
.scrim--center { align-items: center; justify-content: center; padding: 24px; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-height: 88dvh; display: flex; flex-direction: column; border-radius: 14px 14px 0 0; background: var(--bg); padding-bottom: var(--safe-bottom); animation: rise .2s ease-out; }
.sheet--full { height: 92dvh; max-height: none; }
@keyframes rise { from { transform: translateY(40px); opacity: .5; } }
.sheet__grip { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--border); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; }
.sheet__head h2 { font-size: 17px; }
.sheet__body { flex: 1; overflow: auto; padding: 4px 16px 12px; display: grid; gap: 10px; align-content: start; }
.sheet__foot { display: grid; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--border); }
.picker { display: grid; gap: 10px; margin-top: 10px; }
.picker__chosen { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb { text-align: left; }
.newfolder { display: grid; gap: 8px; padding: 10px; border-radius: var(--radius-card); background: var(--canvas); }
.options { display: grid; }
.option { display: flex; justify-content: space-between; align-items: center; min-height: 48px; border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; }
.option.is-active { font-weight: 600; }
.dialog { width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 20px; border-radius: 14px; background: var(--card); box-shadow: 0 10px 30px #0004; }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dialog__head h2 { font-size: 18px; }
.dialog__actions { display: grid; gap: 8px; margin-top: 4px; }
.scan { display: grid; gap: 10px; }
.scan__video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-card); background: #000; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 30; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-size: 14px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }
.toast--error { background: var(--red); color: #fff; }

/* No computador: a mesma coluna do celular, centralizada. */
@media (min-width: 560px) {
  body { background: var(--canvas); }
  .app { max-width: 480px; margin: 0 auto; background: var(--bg); box-shadow: 0 0 0 1px var(--border); }
  .bottomnav, .batchbar { max-width: 480px; margin: 0 auto; }
  .fab { right: calc(50% - 240px + 16px); }
  .sheet { max-width: 480px; margin: 0 auto; }
}
.fav-body > .link, .content > .link { justify-self: start; }
.folder__main:last-child { padding-right: 14px; }

/* autocompletar do campo de tags (WF/TagField "Sugestões") */
.tag-suggest { display: grid; margin-top: 4px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); box-shadow: 0 6px 16px #0002; overflow: hidden; }
.tag-suggest__row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; font-size: 15px; }
.tag-suggest__row:last-child { border-bottom: 0; }
.tag-suggest__row:active { background: var(--accent-soft); }
.tag-suggest__row small { color: var(--muted); font-size: 12px; white-space: nowrap; }
