/* Layout: barra do castelo no topo (marca + armazenamento + ação), calendário como tabuleiro de pedra,
   detalhes numa gaveta lateral. Tema único: a noite da abertura do estúdio Sir Alabar. */
:root {
  /* Céu e pedra */
  --night: #070918;        /* fundo, céu profundo */
  --night-2: #0f1326;      /* superfícies */
  --night-3: #191e34;      /* superfícies elevadas, hover */
  --stone: #2c3144;        /* bordas */
  --stone-hi: #484f68;     /* pedra do castelo, bordas ativas */
  --mist: #8f95ab;         /* texto secundário */
  /* Letreiro */
  --moon: #e4dbc7;         /* texto principal, creme do "SIR ALABAR" */
  --gold: #d6a640;         /* acento, dourado do "GAMES" */
  --gold-dim: #8f7444;
  --window: #f0c75e;       /* janelas acesas: hoje, enviando */
  --flag: #c8473a;         /* bandeiras: perigo */

  /* Estados */
  --st-scheduled: #8a93b8;
  --st-sending: var(--window);
  --st-posted: #6cc08f;
  --st-draft: #5cb8c8;
  --st-failed: #e0604f;
  --st-canceled: #5d6378;

  /* Redes */
  --yt: #e5372c;
  --ig: #c9448f;
  --tt: #e9e6df;

  --font-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-pixel: "Silkscreen", ui-monospace, "Courier New", monospace;
  --font-num: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;

  --radius: 6px;
  --shadow: 0 18px 50px rgba(0, 0, 6, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--moon);
  font: 14px/1.45 var(--font-body);
}
h1, h2, h3, h4, h5 { margin: 0; text-wrap: balance; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Topo: céu com estrelas ---------- */
.topbar {
  position: relative;
  display: flex; align-items: center; gap: 28px;
  padding: 16px max(24px, env(safe-area-inset-right, 0px)) 16px max(24px, env(safe-area-inset-left, 0px));
  background:
    radial-gradient(1px 1px at 12% 30%, rgba(228,219,199,.7), transparent),
    radial-gradient(1px 1px at 34% 70%, rgba(228,219,199,.45), transparent),
    radial-gradient(1px 1px at 57% 22%, rgba(228,219,199,.6), transparent),
    radial-gradient(1px 1px at 71% 64%, rgba(228,219,199,.35), transparent),
    radial-gradient(1.5px 1.5px at 88% 28%, rgba(228,219,199,.7), transparent),
    linear-gradient(180deg, #0c1024 0%, var(--night-2) 100%);
  border-bottom: 1px solid var(--stone);
}
.brand { display: flex; align-items: center; gap: 14px; margin-right: auto; }
.castle { width: 40px; height: 40px; flex: none; }
.lockup { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lockup h1 {
  font: 700 21px/1 var(--font-display);
  letter-spacing: .06em;
  background: linear-gradient(180deg, var(--moon) 45%, #b59a68 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lockup .tag {
  display: flex; align-items: center; gap: 8px;
  font: 400 10px/1 var(--font-pixel); letter-spacing: .25em; color: var(--gold);
}
.lockup .tag::before, .lockup .tag::after {
  content: ""; width: 26px; border-top: 1px dashed var(--gold-dim);
}

.usage { width: 230px; }
.usage-label {
  display: flex; justify-content: space-between; margin-bottom: 6px;
  font: 400 10px/1 var(--font-pixel); letter-spacing: .08em; color: var(--mist); text-transform: uppercase;
}
.usage-label #usage-text { font: 500 11px/1 var(--font-num); letter-spacing: 0; color: var(--moon); text-transform: none; }
.meter { height: 6px; background: var(--night); border: 1px solid var(--stone); border-radius: 1px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--gold); transition: width .4s; }
.meter-fill.warn { background: var(--window); }
.meter-fill.full { background: var(--flag); }

/* ---------- Botões ---------- */
.btn {
  border: 1px solid var(--stone); background: var(--night-2); border-radius: var(--radius);
  padding: 8px 14px; cursor: pointer; font-weight: 500; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--night-3); border-color: var(--stone-hi); }
.btn.primary {
  background: linear-gradient(180deg, #e3b654, var(--gold)); border-color: #e9c46f; color: #1a1205; font-weight: 600;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 4px 18px rgba(214,166,64,.22);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--night-3); border-color: var(--stone); }
.btn.danger { color: var(--st-failed); border-color: rgba(224,96,79,.35); }
.btn.danger:hover { background: rgba(200,71,58,.12); border-color: var(--flag); }
.btn.icon { padding: 6px 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

/* ---------- Barra de ferramentas ---------- */
.toolbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 18px max(24px, env(safe-area-inset-right, 0px)) 14px max(24px, env(safe-area-inset-left, 0px));
}
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--night-2); border: 1px solid var(--stone); border-radius: var(--radius); }
.seg-btn {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 4px; cursor: pointer;
  color: var(--mist); font-weight: 500;
}
.seg-btn:hover { color: var(--moon); }
.seg-btn.active { background: var(--night-3); color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav h2 {
  margin-left: 12px; font: 600 20px/1 var(--font-display); letter-spacing: .04em;
}

main { padding: 0 max(24px, env(safe-area-inset-right, 0px)) 48px max(24px, env(safe-area-inset-left, 0px)); }

/* ---------- Calendário ---------- */
.cal {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px;
  background: var(--stone); border: 1px solid var(--stone); border-radius: var(--radius); overflow: hidden;
}
.cal-head {
  background: var(--night-2); padding: 9px 10px;
  font: 400 10px/1 var(--font-pixel); letter-spacing: .14em; color: var(--mist); text-transform: uppercase;
}
.cal-day {
  background: var(--night); min-height: 124px; padding: 7px; display: flex; flex-direction: column; gap: 5px;
  cursor: pointer; transition: background .15s;
}
.cal-day:hover { background: var(--night-2); }
.cal-day:hover .daynum::after { content: "+ novo"; margin-left: 6px; font: 400 9px/1 var(--font-pixel); color: var(--gold-dim); letter-spacing: .1em; }
.cal-day.out { background: #05060f; }
.cal-day.out .daynum { opacity: .35; }
.cal-day.today { background: linear-gradient(180deg, rgba(240,199,94,.09), transparent 60%), var(--night); box-shadow: inset 0 0 0 1px rgba(240,199,94,.45); }
.cal-day.today .daynum { color: var(--window); }
.daynum { font: 500 12px/1 var(--font-num); color: var(--mist); display: flex; align-items: center; }

.chip {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 5px 7px; border-radius: 4px; cursor: pointer;
  background: var(--night-3); border: 1px solid var(--stone); border-left: 2px solid var(--gold-dim);
  font-size: 12px; transition: border-color .15s;
}
.chip:hover { border-color: var(--stone-hi); border-left-color: var(--gold); }
.chip time { font: 500 11px/1 var(--font-num); color: var(--gold); flex: none; }
.chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.dots { display: flex; gap: 3px; flex: none; }
.dot { width: 6px; height: 6px; border-radius: 1px; background: var(--st-scheduled); }

/* ---------- Badges de conta ---------- */
.acc {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px 2px 2px; border-radius: 4px;
  font: 500 11px/1.2 var(--font-num); border: 1px solid var(--stone); background: var(--night-2); color: var(--moon);
}
.acc i { font: 400 9px/1 var(--font-pixel); padding: 3px 4px; border-radius: 2px; color: #fff; letter-spacing: .05em; }
.acc i.youtube { background: var(--yt); }
.acc i.instagram { background: var(--ig); }
.acc i.tiktok { background: var(--tt); color: var(--night); }

/* ---------- Status ---------- */
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.st::before { content: ""; width: 7px; height: 7px; border-radius: 1px; background: currentColor; }
.st-scheduled { color: var(--st-scheduled); }
.st-sending { color: var(--st-sending); }
.st-posted { color: var(--st-posted); }
.st-draft_sent { color: var(--st-draft); }
.st-failed { color: var(--st-failed); }
.st-canceled { color: var(--st-canceled); }
.dot.st-scheduled { background: var(--st-scheduled); }
.dot.st-sending { background: var(--st-sending); box-shadow: 0 0 6px var(--window); }
.dot.st-posted { background: var(--st-posted); }
.dot.st-draft_sent { background: var(--st-draft); }
.dot.st-failed { background: var(--st-failed); }
.dot.st-canceled { background: var(--st-canceled); }

/* ---------- Lista ---------- */
.list { display: flex; flex-direction: column; gap: 8px; max-width: 920px; }
.list-day {
  margin: 18px 0 2px; font: 400 10px/1 var(--font-pixel); letter-spacing: .14em; color: var(--gold); text-transform: uppercase;
  display: flex; align-items: center; gap: 10px;
}
.list-day::after { content: ""; flex: 1; border-top: 1px dashed var(--stone); }
.list-day:first-child { margin-top: 0; }
.row {
  display: grid; grid-template-columns: 68px minmax(0, 1fr) auto; gap: 16px; align-items: center;
  background: var(--night-2); border: 1px solid var(--stone); border-radius: var(--radius); padding: 12px 16px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.row:hover { border-color: var(--stone-hi); background: var(--night-3); }
.row time { font: 500 17px/1 var(--font-num); color: var(--gold); }
.row .title { font-weight: 600; }
.row .accs { display: flex; gap: 6px 14px; flex-wrap: wrap; margin-top: 7px; }
.row .accs > span { display: inline-flex; align-items: center; gap: 6px; }
.row .file { font: 400 10px/1 var(--font-pixel); color: var(--mist); letter-spacing: .08em; text-transform: uppercase; }
.empty {
  color: var(--mist); padding: 48px 24px; text-align: center; border: 1px dashed var(--stone); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty strong { color: var(--moon); font: 600 18px/1.2 var(--font-display); letter-spacing: .03em; }

/* ---------- Contas ---------- */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; max-width: 980px; }
.acc-card {
  background: var(--night-2); border: 1px solid var(--stone); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.acc-card h4 { font: 600 15px/1.25 var(--font-display); letter-spacing: .02em; }
.acc-card .btn { align-self: flex-start; text-decoration: none; display: inline-block; }
.note { max-width: 70ch; margin-top: 20px; color: var(--mist); font-size: 13px; line-height: 1.6; }

/* ---------- Gaveta ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(460px, 100vw);
  background: var(--night-2); border-left: 1px solid var(--stone); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .22s ease; display: flex; flex-direction: column; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--stone); }
.drawer-head h3 { flex: 1; min-width: 0; font: 600 18px/1.25 var(--font-display); letter-spacing: .02em; }
.drawer-body { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 18px; }
.drawer video { width: 100%; max-height: 380px; background: #000; border-radius: var(--radius); border: 1px solid var(--stone); }
.kv { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 13px; }
.kv dt { font: 400 10px/1.6 var(--font-pixel); letter-spacing: .08em; color: var(--mist); text-transform: uppercase; }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.targets { display: flex; flex-direction: column; gap: 8px; }
.target { background: var(--night); border: 1px solid var(--stone); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.target-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.target .err { color: var(--st-failed); font-size: 12px; }
.target a { color: var(--gold); font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; border-top: 1px dashed var(--stone); padding-top: 16px; }
.section-title {
  font: 400 10px/1 var(--font-pixel); letter-spacing: .14em; color: var(--gold); text-transform: uppercase;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ""; flex: 1; border-top: 1px dashed var(--stone); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 3, 10, .72); backdrop-filter: blur(3px); display: none;
  align-items: center; justify-content: center; padding: 16px; z-index: 30;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--night-2); border: 1px solid var(--stone-hi); border-radius: 8px; box-shadow: var(--shadow);
  width: min(980px, 100%); max-height: calc(100% - 32px); display: flex; flex-direction: column;
}
.modal-head, .modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 18px; }
.modal-head { border-bottom: 1px solid var(--stone); }
.modal-head h3 { flex: 1; font: 600 19px/1.2 var(--font-display); letter-spacing: .03em; }
.modal-foot { border-top: 1px solid var(--stone); justify-content: flex-end; }
.modal-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; padding: 18px; overflow: auto; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.form-error { color: var(--st-failed); margin: 0 auto 0 0; font-size: 13px; }

.drop {
  border: 1px dashed var(--stone-hi); border-radius: var(--radius); aspect-ratio: 9 / 16; max-width: 100%;
  display: grid; place-items: center; cursor: pointer; overflow: hidden; text-align: center;
  background:
    linear-gradient(var(--night) , var(--night)) padding-box,
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(72,79,104,.12) 6px 7px);
  background-blend-mode: normal;
  transition: border-color .15s, background .15s;
}
.drop:hover { border-color: var(--gold-dim); }
.drop.over { border-color: var(--gold); border-style: solid; background: var(--night-3); }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px; color: var(--mist); }
.drop-empty strong { color: var(--moon); font: 600 16px/1.3 var(--font-display); letter-spacing: .03em; }
.drop-empty .frame {
  width: 44px; height: 78px; border: 1px solid var(--gold-dim); border-radius: 4px; margin-bottom: 6px;
  display: grid; place-items: center; font: 400 9px/1 var(--font-pixel); color: var(--gold); letter-spacing: .05em;
}
.drop video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.file-info { font-size: 12px; color: var(--mist); display: flex; flex-direction: column; gap: 4px; font-family: var(--font-num); }
.file-info .warn { color: var(--window); }
.file-info .ok { color: var(--st-posted); }
.progress { height: 6px; border-radius: 1px; background: var(--night); border: 1px solid var(--stone); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--gold); transition: width .2s; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span {
  display: flex; justify-content: space-between; align-items: baseline;
  font: 400 10px/1.2 var(--font-pixel); letter-spacing: .1em; color: var(--mist); text-transform: uppercase;
}
.field input, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius);
  border: 1px solid var(--stone); background: var(--night); color: var(--moon);
  transition: border-color .15s;
}
.field input::placeholder, .field textarea::placeholder { color: #4d536a; }
.field input:hover, .field textarea:hover { border-color: var(--stone-hi); }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(214,166,64,.15); }
.field textarea { resize: vertical; line-height: 1.5; }
.field input[type="datetime-local"] { font-family: var(--font-num); }
.count { font: 500 11px/1 var(--font-num); letter-spacing: 0; text-transform: none; font-style: normal; color: var(--mist); }
.count.over { color: var(--st-failed); }
.group { display: flex; flex-direction: column; gap: 14px; }
.accounts-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.accounts-pick > div { display: flex; flex-direction: column; gap: 6px; }
.accounts-pick h5 { margin: 2px 0 2px; font: 600 13px/1.2 var(--font-display); color: var(--gold); letter-spacing: .03em; }
.pick {
  display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px;
  padding: 6px 8px; border: 1px solid var(--stone); border-radius: var(--radius); background: var(--night);
}
.pick:hover { border-color: var(--stone-hi); }
.pick:has(input:checked) { border-color: var(--gold-dim); background: var(--night-3); }
.pick input { accent-color: var(--gold); margin: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translate(-50%, 20px); opacity: 0;
  background: var(--night-3); color: var(--moon); border: 1px solid var(--gold-dim);
  padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s; z-index: 40; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Telas estreitas ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 14px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .usage { order: 3; width: 100%; }
  .toolbar, main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .cal-day { min-height: 74px; padding: 5px; }
  .cal-day:hover .daynum::after { content: none; }
  .chip { padding: 4px; justify-content: center; }
  .chip .t, .chip time { display: none; }
  .modal-body { grid-template-columns: minmax(0, 1fr); }
  .drop { aspect-ratio: auto; min-height: 200px; }
  .accounts-pick { grid-template-columns: minmax(0, 1fr); }
  .row { grid-template-columns: 56px minmax(0, 1fr); }
  .row .file { display: none; }
}
