/* ============================================================
   Caddie — casca e utilitários (sobre o Basecoat + theme.css)
   PC: barra lateral do Basecoat. iPhone (< 768 px): barra inferior com
   4 itens + botão "+" flutuante; janelas viram folhas encostadas embaixo.
   Campos de texto ≥ 16 px no celular (senão o iPhone amplia a página).
   ============================================================ */

/* ─── base ─────────────────────────────────────────────────── */
html { font-family: var(--font-sans); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh;
  background: var(--background); color: var(--foreground);
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.5;
}
:lang(ja), .jp { font-family: var(--font-jp); }
a { color: inherit; }
.muted { color: var(--muted-foreground); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.mt { margin-top: 12px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.ico { width: 18px; height: 18px; flex-shrink: 0; }
kbd { font-family: var(--font-mono); font-size: 12px; }

/* ─── casca ─────────────────────────────────────────────────── */
main.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: 56px;
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  background: color-mix(in srgb, var(--background) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.topbar .brand-mini { display: none; }
.page { padding: 20px 24px 40px; flex: 1; }
.page > .empty { margin-top: 8px; }
.page h2.sect { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-foreground); margin: 24px 0 10px; }
.page h2.sect:first-child { margin-top: 0; }

/* barra lateral: marca, grupos e rodapé */
.sidebar nav > header { padding: 14px 12px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 4px 6px; border-radius: var(--radius-md); }
.brand:hover { background: var(--sidebar-accent); }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: var(--primary-foreground); display: grid; place-items: center; flex-shrink: 0; }
.brand .mark svg { width: 20px; height: 20px; }
.brand b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.brand small { display: block; font-size: 11px; color: var(--muted-foreground); line-height: 1.2; }
.sidebar nav > footer { padding: 8px 10px 10px; border-top: 1px solid var(--sidebar-border); }
#usermenu [data-popover] { width: 100%; }
.userbtn { width: 100%; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-md); background: none; border: 0; color: inherit; cursor: pointer; text-align: left; font: inherit; }
.userbtn:hover, .userbtn[aria-expanded="true"] { background: var(--sidebar-accent); }
.av { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: var(--primary-foreground); font-weight: 600; font-size: 12px; display: grid; place-items: center; flex-shrink: 0; letter-spacing: .02em; }
.userbtn .ut { min-width: 0; flex: 1; }
.userbtn .ut b { display: block; font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbtn .ut small { display: block; font-size: 11px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar nav li > a .badge { margin-left: auto; }
.sidebar nav li > a[data-soon] span:last-child::after { content: "em breve"; font-size: 10px; color: var(--muted-foreground); margin-left: 8px; font-weight: 400; }

/* sino de avisos */
.bell { position: relative; }
.bell .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--destructive); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.notifs { width: min(360px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; }
.notifs .nf { display: block; padding: 10px 12px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.notifs .nf:last-child { border-bottom: 0; }
.notifs .nf.new { background: color-mix(in srgb, var(--secondary) 60%, transparent); }
.notifs .nf b { display: block; font-size: 13px; font-weight: 600; }
.notifs .nf .d { display: block; font-size: 12px; color: var(--muted-foreground); white-space: pre-line; margin-top: 2px; }
.notifs .nf time { display: block; font-size: 11px; color: var(--muted-foreground); margin-top: 4px; }
.notifs .nf-empty { padding: 20px 12px; text-align: center; color: var(--muted-foreground); font-size: 13px; }
.notifs-hd { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; }

/* barra inferior e botão "+" (só no celular) */
.tabbar { display: none; }
.fab { display: none; }

/* cartões da tela Hoje / listas */
.card.decide header h2 { font-size: 15px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-foreground); margin-right: 6px; vertical-align: middle; }
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.ch-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }
.ch-blog { background: var(--ch-blog); } .ch-instagram { background: var(--ch-instagram); } .ch-facebook { background: var(--ch-facebook); } .ch-gbp { background: var(--ch-gbp); } .ch-line { background: var(--ch-line); }
.field-help { font-size: 12px; color: var(--muted-foreground); margin-top: 4px; }
.form { display: grid; gap: 14px; }
.form .field { display: grid; gap: 6px; }
.copybox { display: flex; gap: 6px; align-items: center; }
.copybox .input { flex: 1; font-family: var(--font-mono); font-size: 12px; }

/* avisos push (bloco de controle) */
.push-ctl { display: flex; flex-direction: column; gap: 10px; }
.push-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── campo de data (dateField): nativo no PC, caixa formatada no celular ─── */
.datef { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.datef .dv { display: none; }
.datef .df-x { display: none; }
.datef input.fi { min-width: 150px; }

/* ─── folhas (dialog) ────────────────────────────────────────── */
.dialog > * > header h2 { font-size: 17px; font-weight: 600; margin: 0; }
.dialog > * > header p { color: var(--muted-foreground); font-size: 13px; margin: 4px 0 0; }
.dialog > * > footer { gap: 8px; }

/* ─── skeleton ──────────────────────────────────────────────── */
.sk { display: grid; gap: 10px; }
.sk .skeleton { height: 14px; }
.sk .skeleton.h { height: 22px; width: 40%; }
.sk .skeleton.w60 { width: 60%; }

/* ─── acessibilidade: foco visível, alvos ≥ 44 px no celular ─── */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn:focus-visible, .input:focus-visible, .select:focus-visible { outline: none; }

/* ─── PC: larguras e detalhes ─────────────────────────────────── */
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}

/* ─── celular ───────────────────────────────────────────────── */
@media (max-width: 767px) {
  .desktop-only { display: none !important; }
  body { font-size: 15px; }
  .sidebar { display: none !important; }
  .sidebar + * { margin-left: 0 !important; }
  .topbar { padding: 0 12px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
  .topbar .brand-mini { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--primary-foreground); flex-shrink: 0; }
  .topbar .brand-mini svg { width: 18px; height: 18px; }
  .topbar h1 { font-size: 17px; }
  .page { padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); }
  .grid2 { grid-template-columns: 1fr; }
  .input, .textarea, .select, input[type="date"], input[type="time"], input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea, select { font-size: 16px !important; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(58px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-top: 1px solid var(--border);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted-foreground); font-size: 11px; font-weight: 500; min-height: 44px; -webkit-tap-highlight-color: transparent; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[data-active="true"] { color: var(--primary); }
  .tabbar a .badge { position: absolute; margin-left: 22px; margin-top: -26px; }
  .fab {
    position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 41;
    display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; border: 0;
    background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-lg); cursor: pointer;
  }
  .fab svg { width: 26px; height: 26px; }
  .fab:active { transform: scale(.96); }
  body.kb-open .tabbar, body.kb-open .fab { display: none; }

  /* folhas encostadas embaixo */
  .dialog > * {
    top: auto !important; bottom: 0 !important; left: 0 !important;
    translate: 0 0 !important; width: 100% !important; max-width: none !important;
    max-height: 92dvh !important; border-radius: 18px 18px 0 0 !important;
    padding-bottom: calc(16px + env(safe-area-inset-bottom)) !important;
  }
  .dialog > * > footer { flex-direction: column-reverse !important; }
  .dialog > * > footer .btn { width: 100%; height: 44px; }
  body.kb-open .dialog > * > footer { display: none; }

  /* campo de data: caixa formatada com o seletor nativo por cima (invisível) */
  .datef { display: flex; }
  .datef .dv { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border: 1px solid var(--input); border-radius: var(--radius-md); background: var(--card); flex: 1; font-size: 16px; }
  .datef .dv.empty { color: var(--muted-foreground); }
  .datef .dv svg { width: 18px; height: 18px; color: var(--muted-foreground); }
  .datef input.fi { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-width: 0; -webkit-appearance: none; }
  .datef .df-x { display: grid; place-items: center; width: 44px; height: 44px; border: 0; background: none; color: var(--muted-foreground); position: relative; z-index: 1; cursor: pointer; }
  .datef .df-x[hidden] { display: none; }
  .datef .df-x svg { width: 18px; height: 18px; }
}

/* ─── fase 1: posts, quadro, Hoje, calendário, mídia ───────── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input { min-width: 160px; }
.btn.chip .ch-dot { margin-right: 4px; }
.ch-dot.hollow { background: transparent; box-shadow: inset 0 0 0 2px currentColor; opacity: .7; }
.ch-dot.ch-blog.hollow { color: var(--ch-blog); } .ch-dot.ch-instagram.hollow { color: var(--ch-instagram); } .ch-dot.ch-facebook.hollow { color: var(--ch-facebook); } .ch-dot.ch-gbp.hollow { color: var(--ch-gbp); } .ch-dot.ch-line.hollow { color: var(--ch-line); }
.badge.st-ready { background: var(--secondary); color: var(--secondary-foreground); }
.badge.st-scheduled { background: color-mix(in srgb, var(--ch-gbp) 25%, var(--card)); color: var(--foreground); }
.badge.st-idea { background: var(--muted); color: var(--muted-foreground); }

/* cartão de post */
.pcard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.pcard:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.pcard-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.pcard-top .ai { width: 14px; height: 14px; color: var(--primary); }
.pcard-title { font-size: 14px; font-weight: 500; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.pcard-err { margin-top: 6px; font-size: 12px; color: var(--destructive); }
.pcard-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.pcard.decide { padding: 14px; }
.pcard.decide.failed { border-color: color-mix(in srgb, var(--destructive) 50%, var(--border)); }
.pcard.decide.ready { border-left: 4px solid var(--primary); }
.pcard.dragging { opacity: .4; }

/* quadro (PC) */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; align-items: start; }
.bcol { background: var(--muted); border-radius: var(--radius); padding: 8px; min-height: 120px; }
.bcol > header { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 8px; font-size: 13px; }
.bcol-body { display: flex; flex-direction: column; gap: 8px; }
.bcol-empty { color: var(--muted-foreground); text-align: center; padding: 16px; font-size: 13px; }

/* janela do post */
.dlg-post .pform .textarea.mono-jp { font-family: var(--font-jp); line-height: 1.7; }
.dlg-post .pf-more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted-foreground); }
.dlg-post .pf-foot { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.dlg-post .pf-foot > .row:last-child { justify-content: flex-end; }
.faq-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: start; background: var(--muted); padding: 8px; border-radius: var(--radius-md); }
.faq-row textarea { grid-column: 1 / -1; }
.media-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.media-thumb { position: relative; width: 84px; height: 84px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); background: var(--muted); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .media-video { display: grid; place-items: center; height: 100%; font-size: 11px; color: var(--muted-foreground); }
.media-thumb .media-x { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; cursor: pointer; }
.media-thumb .media-x svg { width: 12px; height: 12px; }
.media-add { width: 84px; height: 84px; border: 1px dashed var(--border); border-radius: var(--radius-md); background: none; color: var(--muted-foreground); display: grid; place-items: center; cursor: pointer; }
.media-add:hover { border-color: var(--primary); color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.ico.spin { animation: spin 1s linear infinite; }
.jp { font-family: var(--font-jp); }

/* calendário */
.cal-label { min-width: 150px; text-align: center; }
.cal-legend { gap: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-foreground); text-align: center; padding: 4px 0; }
.cal-cell { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); min-height: 110px; padding: 4px; display: flex; flex-direction: column; gap: 4px; }
.cal-cell.off { opacity: .45; }
.cal-cell.today { border-color: var(--primary); }
.cal-cell.drop, .cal-wcol.drop { background: var(--secondary); }
.cal-n { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted-foreground); padding: 2px 4px; }
.cal-cell.today .cal-n span { background: var(--primary); color: var(--primary-foreground); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; font-weight: 600; }
.cal-add { width: 22px; height: 22px; border: 0; background: none; color: var(--muted-foreground); border-radius: 50%; display: grid; place-items: center; cursor: pointer; opacity: 0; }
.cal-cell:hover .cal-add, .cal-wcol:hover .cal-add { opacity: 1; }
.cal-add svg { width: 14px; height: 14px; }
.cal-item { padding: 6px 8px; }
.cal-item .pcard-title { font-size: 12px; -webkit-line-clamp: 2; }
.cal-item .pcard-top .small { display: none; }
.cal-item .pcard-top { margin-bottom: 2px; }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wcol { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 6px; min-height: 240px; display: flex; flex-direction: column; gap: 6px; }
.cal-wcol.today { border-color: var(--primary); }
.cal-dots { display: flex; gap: 3px; flex-wrap: wrap; padding: 0 4px; }

/* mídia */
.upl { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: var(--radius-md); background: var(--primary); color: var(--primary-foreground); font-size: 14px; font-weight: 500; cursor: pointer; }
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mgrid.pick { max-height: 60vh; overflow: auto; }
.mtile { margin: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; cursor: pointer; }
.mtile:hover { border-color: var(--primary); }
.mtile img, .mtile video { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--muted); }
.mtile figcaption { padding: 6px 8px; font-size: 12px; display: flex; flex-direction: column; gap: 2px; }

@media (max-width: 767px) {
  .toolbar { gap: 8px; }
  .toolbar .input { flex: 1 1 100%; max-width: none !important; }
  .cal-cell { min-height: 54px; padding: 2px; }
  .cal-cell.sel { background: var(--secondary); }
  .cal-n { padding: 2px; font-size: 12px; }
  .cal-week { grid-template-columns: 1fr; }
  .cal-legend { display: none; }
  .faq-row { grid-template-columns: 1fr auto; }
  .dlg-post .pf-foot .btn { width: 100%; height: 44px; }
  .dlg-post .pf-foot > .row { flex-direction: column; }
  .mgrid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── fase 3: notícias ──────────────────────────────────────── */
.ngrid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.ncard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-sm); }
.ncard.picked { border-left: 4px solid var(--primary); }
.ncard.hidden { opacity: .6; }
.ncard-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ncard-title { font-size: 15px; font-weight: 600; line-height: 1.4; margin: 0; }
.ncard-title a { text-decoration: none; }
.ncard-title a:hover { text-decoration: underline; }
.ncard-sum { margin: 0; font-size: 13px; }
.ncard-hook { margin: 0; font-size: 13px; color: var(--primary); display: flex; gap: 6px; align-items: flex-start; }
.ncard-hook svg { flex-shrink: 0; margin-top: 2px; }
.ncard-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.badge.score { font-variant-numeric: tabular-nums; }
.badge.score.hi { background: var(--primary); color: var(--primary-foreground); }
.badge.score.mid { background: var(--secondary); color: var(--secondary-foreground); }
.badge.score.lo { background: var(--muted); color: var(--muted-foreground); }
.src-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.src-row:last-child { border-bottom: 0; }
.src-row .src-url { font-size: 12px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-row .src-err { font-size: 12px; color: var(--warn); }
@media (max-width: 767px) { .ngrid { grid-template-columns: 1fr; } .src-row { grid-template-columns: auto 1fr; } .src-row .src-actions { grid-column: 1 / -1; } }
