/* ==========================================================================
   OmniStudio — painel
   Design system: tokens + app shell (sidebar) + componentes. Light & dark.
   Sem dependências externas (CSP: default-src 'self').
   ========================================================================== */

:root {
  /* superfícies e texto (claro) */
  --bg: #eef0f6;
  --surface: #ffffff;
  --surface-2: #f4f5fa;
  --surface-3: #eceef5;
  --fg: #171a23;
  --fg-soft: #3b4150;
  --muted: #6b7280;
  --line: #e4e7f0;
  --line-strong: #d4d8e6;

  /* marca */
  --accent: #6d5efc;
  --accent-2: #9b5cf6;
  --accent-ink: #4b3fd6;
  --accent-fg: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --grad: linear-gradient(135deg, #6d5efc 0%, #9b5cf6 55%, #c25ff0 100%);

  /* estados */
  --ok: #15a34a;      --ok-soft: color-mix(in srgb, var(--ok) 14%, var(--surface));
  --warn: #d97706;    --warn-soft: color-mix(in srgb, var(--warn) 16%, var(--surface));
  --error: #dc2626;   --error-soft: color-mix(in srgb, var(--error) 13%, var(--surface));
  --info: #2563eb;    --info-soft: color-mix(in srgb, var(--info) 13%, var(--surface));

  /* sidebar (sempre escura, estilo produto) */
  --side-bg: #15172a;
  --side-bg-2: #1c1f38;
  --side-fg: #b9bedb;
  --side-fg-strong: #ffffff;
  --side-line: rgba(255,255,255,.08);
  --side-active: rgba(255,255,255,.07);

  --shadow-sm: 0 1px 2px rgba(18,20,35,.05), 0 1px 3px rgba(18,20,35,.04);
  --shadow: 0 2px 4px rgba(18,20,35,.04), 0 8px 24px rgba(18,20,35,.07);
  --shadow-lg: 0 12px 40px rgba(18,20,35,.16);

  --r: 16px; --r-md: 12px; --r-sm: 9px;
  --side-w: 250px;
  --maxw: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e15;
    --surface: #14161f;
    --surface-2: #191c27;
    --surface-3: #1f2330;
    --fg: #e9ebf3;
    --fg-soft: #c3c8d6;
    --muted: #8b92a6;
    --line: #262a38;
    --line-strong: #323748;
    --accent: #8578ff;
    --accent-2: #b07bff;
    --accent-ink: #a99dff;
    --accent-soft: color-mix(in srgb, var(--accent) 18%, var(--surface));
    --ok: #38c172;     --ok-soft: color-mix(in srgb, var(--ok) 18%, var(--surface));
    --warn: #f0a94c;   --warn-soft: color-mix(in srgb, var(--warn) 18%, var(--surface));
    --error: #ff6b6b;  --error-soft: color-mix(in srgb, var(--error) 16%, var(--surface));
    --info: #5b9bff;   --info-soft: color-mix(in srgb, var(--info) 16%, var(--surface));
    --side-bg: #0a0b13;
    --side-bg-2: #12141f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 2px 6px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.4);
    --shadow-lg: 0 16px 48px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; margin: 0; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; font-size: .86em;
       background: var(--surface-3); padding: .08em .4em; border-radius: 5px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* ---------- app shell ---------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 50;
  display: flex; flex-direction: column; gap: 2px;
  background: linear-gradient(180deg, var(--side-bg-2), var(--side-bg));
  border-right: 1px solid var(--side-line);
  padding: 18px 14px;
  overflow-y: auto;
}
.content { margin-left: var(--side-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; color: var(--side-fg-strong); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; flex: none;
              box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent); }
.brand-name { font-weight: 700; font-size: 1.12rem; letter-spacing: -.02em; }
.brand-name b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav-label { color: color-mix(in srgb, var(--side-fg) 60%, transparent);
             font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
             padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 10px;
  color: var(--side-fg); font-weight: 500; font-size: .92rem; position: relative;
}
.nav-link:hover { background: var(--side-active); color: var(--side-fg-strong); text-decoration: none; }
.nav-link.active { background: var(--side-active); color: var(--side-fg-strong); }
.nav-link.active::before { content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
                           width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--grad); }
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }

.side-spacer { flex: 1; }
.side-foot { border-top: 1px solid var(--side-line); padding-top: 12px; margin-top: 8px; display: grid; gap: 10px; }
.tenant-pick { display: grid; gap: 5px; }
.tenant-pick label { color: color-mix(in srgb, var(--side-fg) 70%, transparent); font-size: .68rem;
                     font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding-left: 2px; }
.tenant-pick select {
  width: 100%; background: rgba(255,255,255,.06); color: var(--side-fg-strong);
  border: 1px solid var(--side-line); border-radius: 9px; padding: 8px 10px; font: inherit; font-size: .9rem;
}
.tenant-pick select option { color: #111; }
.tenant-static { display: flex; align-items: center; gap: 8px; color: var(--side-fg); font-size: .85rem; padding-left: 2px; }
.tenant-static .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--grad); flex: none; }

.side-user { display: flex; align-items: center; gap: 10px; padding: 4px 2px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
          background: var(--grad); color: #fff; font-weight: 700; font-size: .85rem; text-transform: uppercase; }
.side-user .who { min-width: 0; }
.side-user .who b { display: block; color: var(--side-fg-strong); font-size: .86rem; font-weight: 600;
                    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { color: color-mix(in srgb, var(--side-fg) 65%, transparent); font-size: .74rem; }
.logout-btn { margin-left: auto; background: transparent; border: 1px solid var(--side-line); color: var(--side-fg);
              border-radius: 8px; padding: 6px 8px; cursor: pointer; display: grid; place-items: center; }
.logout-btn:hover { background: var(--side-active); color: var(--side-fg-strong); }
.logout-btn svg { width: 16px; height: 16px; }

/* ---------- topbar (mobile) ---------------------------------------------- */
.topbar {
  display: none; align-items: center; gap: 12px; padding: 12px 16px;
  background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
}
.nav-toggle { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
              width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--fg); }
.nav-toggle svg { width: 20px; height: 20px; }
.topbar .brand-name { color: var(--fg); font-size: 1rem; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(8,9,15,.5); z-index: 45; }

/* ---------- main --------------------------------------------------------- */
.main { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 30px 32px 60px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: .95rem; margin-top: 3px; }
.page-head .tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.crumbs { color: var(--muted); font-size: .85rem; margin-bottom: 10px; display: flex; gap: 7px; align-items: center; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--fg); }

/* ---------- cards & grid ------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
        box-shadow: var(--shadow-sm); padding: 20px 22px; margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 1.02rem; font-weight: 650; }
.card > h2:first-child { font-size: 1.02rem; font-weight: 650; margin-bottom: 14px; }
.card-sub { color: var(--muted); font-size: .85rem; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* stat cards */
.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
        box-shadow: var(--shadow-sm); padding: 18px; display: flex; gap: 14px; align-items: flex-start; }
.stat .ic { width: 42px; height: 42px; border-radius: 11px; flex: none; display: grid; place-items: center;
            background: var(--accent-soft); color: var(--accent-ink); }
.stat .ic svg { width: 21px; height: 21px; }
.stat .n { font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; font-weight: 500; margin-top: 2px; }
.stat.ok .ic    { background: var(--ok-soft); color: var(--ok); }
.stat.warn .ic  { background: var(--warn-soft); color: var(--warn); }
.stat.info .ic  { background: var(--info-soft); color: var(--info); }

/* ---------- tables ------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -22px -20px; }
.card > .table-wrap:first-child { margin-top: -6px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th { text-align: left; font-weight: 600; font-size: .74rem; letter-spacing: .05em; text-transform: uppercase;
           color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
thead th:first-child { padding-left: 22px; } thead th:last-child { padding-right: 22px; }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody td:first-child { padding-left: 22px; } tbody td:last-child { padding-right: 22px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
td a { color: var(--fg); font-weight: 550; }
td a:hover { color: var(--accent-ink); }

/* key-value lists */
.kv { list-style: none; padding: 0; margin: 0; }
.kv li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv li:last-child { border-bottom: 0; }
.kv li > span:first-child { color: var(--muted); font-size: .88rem; }
.kv li b { font-weight: 600; text-align: right; }

/* ---------- pills / badges ----------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px;
        font-size: .76rem; font-weight: 600; letter-spacing: .01em; line-height: 1.6;
        background: var(--surface-3); color: var(--fg-soft); border: 1px solid transparent; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.plain::before { display: none; }

.st-DRAFT              { background: var(--surface-3); color: var(--muted); }
.st-SCRIPT_READY, .st-STORYBOARD_READY, .st-AUDIO_READY,
.st-RENDERED, .st-REVIEW_PENDING { background: var(--info-soft); color: var(--info); }
.st-RENDER_PENDING, .st-RENDERING, .st-COMPOSING { background: var(--warn-soft); color: var(--warn); }
.st-QUEUED, .st-LEASED, .st-RUNNING { background: var(--warn-soft); color: var(--warn); }
.st-APPROVED, .st-PUBLISHED, .st-SUCCEEDED, .st-online, .st-active { background: var(--ok-soft); color: var(--ok); }
.st-FAILED, .st-offline, .st-disabled { background: var(--error-soft); color: var(--error); }

/* ---------- pipeline stepper --------------------------------------------- */
.stepper { display: flex; gap: 0; flex-wrap: wrap; margin: 4px 0 2px; }
.step { flex: 1 1 0; min-width: 84px; display: flex; flex-direction: column; align-items: center; gap: 8px;
        position: relative; text-align: center; }
.step::before, .step::after { content: ""; position: absolute; top: 15px; height: 2px; background: var(--line-strong); z-index: 0; }
.step::before { left: 0; right: 50%; } .step::after { left: 50%; right: 0; }
.step:first-child::before, .step:last-child::after { display: none; }
.step .bullet { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
                background: var(--surface); border: 2px solid var(--line-strong); color: var(--muted);
                font-size: .8rem; font-weight: 700; }
.step .bullet svg { width: 15px; height: 15px; }
.step .cap { font-size: .76rem; color: var(--muted); font-weight: 550; }
.step.done .bullet { background: var(--grad); border-color: transparent; color: #fff; }
.step.done::before, .step.done::after { background: var(--accent); }
.step.active .bullet { border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 4px var(--accent-soft); }
.step.active .cap, .step.done .cap { color: var(--fg); }

/* ---------- forms & buttons ---------------------------------------------- */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: .88rem; }
input, select, textarea {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--fg); width: 100%; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 6rem; }
::placeholder { color: var(--muted); opacity: .8; }

.btn { font: inherit; font-weight: 600; font-size: .9rem; padding: 10px 16px; border: 1px solid transparent;
       border-radius: var(--r-sm); cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
       background: var(--surface-2); color: var(--fg); transition: filter .12s, background .12s, transform .05s; white-space: nowrap; }
.btn:hover { filter: brightness(1.03); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--fg-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--error-soft); color: var(--error); border-color: color-mix(in srgb, var(--error) 30%, transparent); }
.btn-sm { padding: 6px 11px; font-size: .84rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-link { background: none; border: 0; color: var(--accent-ink); padding: 0; cursor: pointer; font: inherit; font-weight: 600; }

/* action row (episode) */
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.actions form { display: flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.actions input[type=text] { width: auto; min-width: 190px; }
form { margin: 0; }

/* ---------- media -------------------------------------------------------- */
video { width: 100%; border-radius: var(--r-md); background: #000; display: block; aspect-ratio: 16/9; }
.media-cap { color: var(--muted); font-size: .82rem; margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- misc --------------------------------------------------------- */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, monospace; font-size: .85rem; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .ic { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 12px; background: var(--surface-3);
             display: grid; place-items: center; color: var(--muted); }
.empty .ic svg { width: 24px; height: 24px; }
.empty code { background: var(--surface-3); }

.flash { border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 20px; font-size: .9rem;
         background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
         color: var(--fg); display: flex; gap: 9px; align-items: center; }
.flash.error { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 35%, transparent); }
.flash svg { width: 18px; height: 18px; flex: none; }

.notes { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.notes li { padding: 10px 12px; border-radius: 9px; font-size: .87rem; border: 1px solid var(--line);
            background: var(--surface-2); }
.notes li.warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.notes li.error { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 30%, transparent); color: var(--error); }

.warn-box { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
            color: var(--warn); border-radius: 9px; padding: 10px 13px; font-size: .86rem; margin-top: 12px; }

.progress { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 90px; }
.progress > i { display: block; height: 100%; background: var(--grad); border-radius: 999px; }

/* ---------- auth (login) ------------------------------------------------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 24px;
         background:
           radial-gradient(1100px 520px at 15% -5%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
           radial-gradient(900px 500px at 100% 110%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 55%),
           var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
             border-radius: 20px; box-shadow: var(--shadow-lg); padding: 34px 32px; }
.auth-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; }
.auth-brand .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
.auth-brand .brand-name { color: var(--fg); font-size: 1.3rem; }
.auth-card h1 { text-align: center; font-size: 1.15rem; font-weight: 650; margin: 14px 0 4px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 22px; }
.auth-card form { display: flex; flex-direction: column; gap: 15px; }

/* ---------- responsive --------------------------------------------------- */
@media (max-width: 880px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; }
  .topbar { display: flex; }
  .scrim.show { display: block; }
  .main { padding: 22px 18px 50px; }
  .table-wrap { margin-left: -22px; margin-right: -22px; }
}
@media (max-width: 560px) {
  .page-head h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .stat { padding: 15px; }
}

/* ---------- utilitários (evitam style="" inline por causa do CSP) -------- */
.ta-right { text-align: right; }
.text-error { color: var(--error); }
.mt-sm { margin-top: 12px; }
.progress .w0{width:0}    .progress .w10{width:10%}  .progress .w20{width:20%}
.progress .w30{width:30%} .progress .w40{width:40%}  .progress .w50{width:50%}
.progress .w60{width:60%} .progress .w70{width:70%}  .progress .w80{width:80%}
.progress .w90{width:90%} .progress .w100{width:100%}
