:root {
  --bg: #F4F5F7; --surface: #fff; --ink: #15171C; --muted: #5B6070; --line: #E3E5EA; --line2: #CDD1D9;
  --accent: #2F49D1; --accent-ink: #fff; --accent-soft: #E6EBFF; --accent-text: #2338A8;
  --ok-bg: #E2F4EA; --ok: #1D6B3F; --warn-bg: #FFF3D6; --warn: #7A4B00; --bad-bg: #FDE7E4; --bad: #9A2B1C;
  --grey-bg: #ECEDF0; --grey: #3D414C;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading { padding: 40px; color: var(--muted); }

.btn { min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line2); background: var(--surface);
  font-weight: 700; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(0.92); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); border-color: #E8B4AC; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 34px; min-height: 34px; padding: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .field select, .field textarea { min-height: 44px; border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px; background: #fff; }
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field .hint { font-size: 12px; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.err { color: var(--bad); font-size: 14px; }

/* Shell */
.shell { min-height: 100vh; display: flex; }
.side { width: 260px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 8px 6px; }
.client-link { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); border: 0; background: none; text-align: left; cursor: pointer; width: 100%; }
.client-link:hover { background: #F0F1F4; }
.client-link.on { background: var(--accent-soft); color: var(--accent-text); }
.client-link small { color: var(--muted); font-size: 12px; }
.side .foot { margin-top: auto; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
main { flex: 1; min-width: 0; padding: 28px 36px; display: flex; flex-direction: column; gap: 20px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 26px; font-weight: 800; }
.head p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.seg { display: inline-flex; background: #ECEEF3; padding: 3px; border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: transparent; min-height: 34px; padding: 0 12px; border-radius: 8px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.slots { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-text); padding: 6px 6px 6px 12px; border-radius: 99px; font-weight: 600; font-size: 13px; }
.chip button { border: 0; background: transparent; cursor: pointer; width: 24px; height: 24px; border-radius: 50%; color: inherit; }
.chip button:hover { background: rgba(0,0,0,.08); }
.slot-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.slot-add select, .slot-add input { min-height: 36px; border: 1px solid var(--line2); border-radius: 8px; padding: 0 8px; background: #fff; }

/* Fila */
.queue { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: 40px 76px minmax(0, 1fr) auto; gap: 14px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.item .num { font-weight: 800; font-size: 18px; color: var(--muted); text-align: center; }
.thumb { width: 76px; height: 95px; border-radius: 8px; background: #ECEEF3 center/cover no-repeat; position: relative; overflow: hidden; }
.thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .count { position: absolute; right: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 99px; }
.item .info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.item .title { font-weight: 700; }
.item .cap { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .when { font-size: 13px; font-weight: 600; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.b-rascunho { background: var(--warn-bg); color: var(--warn); }
.b-agendado { background: var(--accent-soft); color: var(--accent-text); }
.b-publicando { background: var(--accent-soft); color: var(--accent-text); }
.b-publicado { background: var(--ok-bg); color: var(--ok); }
.b-alteracao { background: var(--bad-bg); color: var(--bad); }
.b-erro { background: var(--bad-bg); color: var(--bad); }
.errline { color: var(--bad); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 32px; border: 2px dashed var(--line2); border-radius: 12px; }

/* Modal */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(21,23,28,.45); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 20px; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews img, .previews video { width: 72px; height: 90px; object-fit: cover; border-radius: 8px; background: #eee; }
.acc-list { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.acc-list button { display: flex; justify-content: space-between; width: 100%; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 10px 12px; cursor: pointer; text-align: left; }
.acc-list button:hover { background: #F4F5F7; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

@media (max-width: 860px) {
  body { -webkit-text-size-adjust: 100%; }
  /* iPhone: campos com 16px evitam o zoom automático ao tocar */
  .field input, .field select, .field textarea, .slot-add select, .slot-add input { font-size: 16px; }
  .shell { flex-direction: column; }
  /* barra de clientes no topo, rolando para o lado */
  .side { width: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .side > .brand { padding: 0 !important; margin-right: auto; }
  .side #newClient { min-height: 36px; padding: 0 12px; font-size: 13px; }
  .side h2 { display: none; }
  #clist { order: 5; width: 100%; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #clist::-webkit-scrollbar { display: none; }
  .client-link { width: auto; flex-shrink: 0; padding: 8px 12px; border: 1px solid var(--line); }
  .client-link.on { border-color: var(--accent-soft); }
  .side .foot { order: 6; width: 100%; margin: 0; padding: 8px 0 0; flex-direction: row; justify-content: space-between; align-items: center; }
  .side .foot .row { flex-wrap: nowrap; flex-shrink: 0; }
  .side .foot > span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  main { padding: 18px 14px calc(24px + env(safe-area-inset-bottom)); gap: 16px; }
  .head h1 { font-size: 22px; }
  .head > .row { width: 100%; }
  .head > .row .btn { flex: 1; }
  .grid2 { grid-template-columns: 1fr; }
  .seg { display: flex; }
  .seg button { flex: 1; padding: 0 8px; }
  .item { grid-template-columns: 24px 64px minmax(0, 1fr); gap: 10px; padding: 10px; }
  .item .num { font-size: 15px; }
  .thumb { width: 64px; height: 80px; }
  .item .cap { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .item .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .item .actions .btn.sm { min-height: 38px; }
  /* modais ocupam a tela toda no celular */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog form { padding: calc(20px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom)); min-height: 100%; }
  dialog .grid2 { grid-template-columns: 1fr; }
  #toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: none; } }
