/* =====================================================================
   MAYONGI TV — sistema de design do backoffice
   ---------------------------------------------------------------------
   Linguagem visual: Swiss / minimalismo funcional, densidade alta.
   Escuro por omissão (é uma consola de operação, usada horas seguidas),
   com tema claro completo. Sem gradientes, sem vidro, sem sombras
   decorativas: a hierarquia vem de espaço, peso e contraste.

   Todo o cromatismo passa por tokens semânticos. Nenhum componente
   escreve um hexadecimal — assim o tema claro é uma troca de variáveis
   e não uma reescrita de CSS.

   Contraste verificado: texto normal >= 4,5:1 e elementos gráficos
   >= 3:1 nos DOIS temas.
   ===================================================================== */

/* ------------------------------------------------------------ 1. tokens */
:root {
    color-scheme: dark;

    /* superfícies */
    --bg:            #0F172A;
    --bg-elevated:   #151E31;
    --surface:       #1B2336;
    --surface-hover: #212B40;
    --surface-sunken:#131A2A;
    --muted:         #272F42;

    /* texto — os três níveis cumprem 4,5:1 sobre --surface */
    --fg:            #F8FAFC;
    --fg-muted:      #A3B0C2;
    --fg-subtle:     #8494AA;
    --fg-inverse:    #0F172A;

    /* limites */
    --border:        #2E3950;
    --border-strong: #475569;
    --ring:          #4ADE80;

    /* acção */
    --accent:        #22C55E;
    --accent-hover:  #16A34A;
    --accent-fg:     #05230F;
    --accent-soft:   rgba(34, 197, 94, 0.14);

    /* estados operacionais — cada um tem par sólido + suave */
    --ok:            #22C55E;
    --ok-soft:       rgba(34, 197, 94, 0.14);
    --info:          #38BDF8;
    --info-soft:     rgba(56, 189, 248, 0.14);
    --warn:          #FBBF24;
    --warn-soft:     rgba(251, 191, 36, 0.14);
    --danger:        #F87171;
    --danger-soft:   rgba(248, 113, 113, 0.14);
    --neutral:       #94A3B8;
    --neutral-soft:  rgba(148, 163, 184, 0.14);

    /* tipografia */
    --font-sans: 'Fira Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'Cascadia Mono', ui-monospace, 'SFMono-Regular', monospace;

    --text-2xs: 0.6875rem;  /* 11px — etiquetas de coluna */
    --text-xs:  0.75rem;    /* 12px — metadados */
    --text-sm:  0.8125rem;  /* 13px — tabelas, corpo denso */
    --text-base:0.875rem;   /* 14px — corpo */
    --text-md:  1rem;       /* 16px — títulos de cartão */
    --text-lg:  1.25rem;    /* 20px — títulos de página */
    --text-xl:  1.75rem;    /* 28px — indicadores */
    --text-2xl: 2.25rem;    /* 36px — indicador principal */

    /* espaço — escala densa 4/8/12/16/24/32 */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.5rem;
    --sp-6: 2rem;
    --sp-7: 3rem;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;
    --radius-full: 999px;

    --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.4);
    --shadow:    0 4px 12px rgba(2, 6, 23, 0.45);
    --shadow-lg: 0 16px 40px rgba(2, 6, 23, 0.55);

    /* movimento — três tokens, escolhidos por distância percorrida */
    --motion-fast: 120ms;   /* estado local: hover, foco */
    --motion-base: 200ms;   /* revelar/esconder no lugar */
    --motion-slow: 280ms;   /* entrada de painéis com deslocamento */
    --ease: cubic-bezier(0.32, 0.72, 0, 1);

    --sidebar-w: 244px;
    --topbar-h: 56px;
    --z-drawer: 40;
    --z-modal: 60;
    --z-toast: 80;
}

[data-theme='light'] {
    color-scheme: light;

    --bg:            #F4F6F8;
    --bg-elevated:   #FFFFFF;
    --surface:       #FFFFFF;
    --surface-hover: #F1F5F9;
    --surface-sunken:#F8FAFC;
    --muted:         #EEF2F6;

    --fg:            #0F172A;
    --fg-muted:      #4F5F76;
    --fg-subtle:     #5C6B82;
    --fg-inverse:    #FFFFFF;

    --border:        #E2E8F0;
    --border-strong: #C3CEDC;
    --ring:          #15803D;

    --accent:        #15803D;
    --accent-hover:  #166534;
    --accent-fg:     #FFFFFF;
    --accent-soft:   rgba(21, 128, 61, 0.10);

    --ok:            #15803D;
    --ok-soft:       rgba(21, 128, 61, 0.10);
    --info:          #0369A1;
    --info-soft:     rgba(3, 105, 161, 0.10);
    --warn:          #A15C07;
    --warn-soft:     rgba(161, 92, 7, 0.12);
    --danger:        #B91C1C;
    --danger-soft:   rgba(185, 28, 28, 0.10);
    --neutral:       #475569;
    --neutral-soft:  rgba(71, 85, 105, 0.10);

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow:    0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);
}

/* -------------------------------------------------------------- 2. base */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

/* Foco sempre visível: nunca é removido, só substituído por um anel
   com contraste próprio. */
:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

::selection { background: var(--accent-soft); }

/* Números em colunas usam algarismos de largura fixa, senão a coluna
   "dança" a cada actualização automática. */
.tnum, .stat__value, .table td.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Salto para o conteúdo (primeiro tab da página). */
.skip-link {
    position: absolute; left: var(--sp-3); top: -3rem; z-index: 100;
    background: var(--accent); color: var(--accent-fg);
    padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
    font-weight: 600; transition: top var(--motion-fast) var(--ease);
}
.skip-link:focus { top: var(--sp-3); }

/* ------------------------------------------------------- 3. estrutura */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100dvh;
}

/* ---- sidebar */
.sidebar {
    grid-row: 1 / -1;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: var(--topbar-h);
    padding: 0 var(--sp-4);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}
.sidebar__brand svg { width: 26px; height: 26px; color: var(--accent); flex: 0 0 auto; }
.sidebar__brand-text {
    font-weight: 600; letter-spacing: 0.06em; font-size: var(--text-base);
}
.sidebar__brand-text span { color: var(--accent); }

.sidebar__nav { padding: var(--sp-3) var(--sp-2) var(--sp-5); flex: 1 1 auto; }

.nav-group + .nav-group { margin-top: var(--sp-4); }
.nav-group__label {
    padding: 0 var(--sp-3) var(--sp-2);
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--fg-subtle);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    color: var(--fg-muted);
    font-size: var(--text-base);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--motion-fast) var(--ease),
                color var(--motion-fast) var(--ease);
}
.nav-item:hover { background: var(--surface-hover); color: var(--fg); }
.nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; }

/* O item activo é marcado por cor E por barra lateral: nunca só por cor. */
.nav-item--active {
    background: var(--accent-soft);
    color: var(--fg);
    font-weight: 600;
    box-shadow: inset 2px 0 0 var(--accent);
}

.nav-item__count {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--fg-subtle);
}
.nav-item__count--alert { color: var(--danger); font-weight: 600; }

.sidebar__footer {
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border);
    font-size: var(--text-xs);
    color: var(--fg-subtle);
    display: flex;
    justify-content: space-between;
    gap: var(--sp-2);
    flex: 0 0 auto;
}

/* ---- topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: 0 var(--sp-5);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.breadcrumb {
    display: flex; align-items: center; gap: var(--sp-2);
    font-size: var(--text-sm); color: var(--fg-subtle); min-width: 0;
}
.breadcrumb strong { color: var(--fg); font-weight: 600; }
.breadcrumb span { color: var(--border-strong); }

.topbar__spacer { flex: 1 1 auto; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--fg-muted);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--motion-fast) var(--ease),
                color var(--motion-fast) var(--ease),
                border-color var(--motion-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--fg); border-color: var(--border-strong); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn__dot {
    position: absolute; transform: translate(11px, -9px);
    width: 7px; height: 7px; border-radius: var(--radius-full);
    background: var(--danger); border: 2px solid var(--bg);
}

.user-chip {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-1);
    border: 1px solid var(--border); border-radius: var(--radius-full);
    background: var(--surface); cursor: pointer;
}
.user-chip:hover { border-color: var(--border-strong); }
.avatar {
    width: 26px; height: 26px; border-radius: var(--radius-full);
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center;
    font-size: var(--text-xs); font-weight: 700;
}
.user-chip__name { font-size: var(--text-sm); font-weight: 500; }
.user-chip__role { font-size: var(--text-2xs); color: var(--fg-subtle); }

/* ---- conteúdo */
.main { min-width: 0; display: flex; flex-direction: column; }
.content { padding: var(--sp-5); max-width: 1560px; width: 100%; }

.page-head {
    display: flex; align-items: flex-start; gap: var(--sp-4);
    flex-wrap: wrap; margin-bottom: var(--sp-5);
}
.page-head__title { font-size: var(--text-lg); }
.page-head__sub {
    margin-top: var(--sp-1); font-size: var(--text-sm); color: var(--fg-muted);
    max-width: 68ch;
}
.page-head__actions { margin-left: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ------------------------------------------------------- 4. componentes */

/* ---- cartão */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card__head {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-4) var(--sp-3);
    border-bottom: 1px solid var(--border);
}
.card__title { font-size: var(--text-md); font-weight: 600; }
.card__hint { font-size: var(--text-xs); color: var(--fg-subtle); }
.card__actions { margin-left: auto; display: flex; gap: var(--sp-2); }
.card__body { padding: var(--sp-4); }
.card__body--flush { padding: 0; }
.card__foot {
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border);
    font-size: var(--text-xs); color: var(--fg-subtle);
    display: flex; align-items: center; gap: var(--sp-3);
}

/* ---- grelhas */
.grid { display: grid; gap: var(--sp-4); }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid--split { grid-template-columns: 1fr; } }

/* ---- indicador (stat) */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    display: flex; flex-direction: column; gap: var(--sp-1);
    position: relative;
    transition: border-color var(--motion-fast) var(--ease);
}
.stat:hover { border-color: var(--border-strong); }
.stat__label {
    font-size: var(--text-2xs); text-transform: uppercase;
    letter-spacing: 0.09em; color: var(--fg-subtle); font-weight: 600;
    display: flex; align-items: center; gap: var(--sp-2);
}
.stat__value {
    font-size: var(--text-xl); font-weight: 600; line-height: 1.1;
    font-family: var(--font-mono); letter-spacing: -0.02em;
}
.stat--lead .stat__value { font-size: var(--text-2xl); }
.stat__meta { font-size: var(--text-xs); color: var(--fg-muted); }
.stat--ok     .stat__value { color: var(--ok); }
.stat--warn   .stat__value { color: var(--warn); }
.stat--danger .stat__value { color: var(--danger); }
.stat--info   .stat__value { color: var(--info); }

/* Barra de proporção sob um indicador (ex.: online / total). */
.meter {
    height: 4px; border-radius: var(--radius-full);
    background: var(--muted); overflow: hidden; margin-top: var(--sp-2);
}
.meter__fill { height: 100%; background: var(--ok); border-radius: inherit; }
.meter__fill--warn { background: var(--warn); }
.meter__fill--danger { background: var(--danger); }

/* ---- distintivo de estado (cor + texto, nunca só cor) */
.badge {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.1875rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: var(--text-xs); font-weight: 600; line-height: 1.35;
    white-space: nowrap;
}
.badge__dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; flex: 0 0 auto; }
.badge--ok      { background: var(--ok-soft);      color: var(--ok); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--neutral { background: var(--neutral-soft); color: var(--neutral); }
.badge--outline { background: transparent; border: 1px solid var(--border-strong); color: var(--fg-muted); }

/* Pulsação apenas no estado "a sincronizar": movimento com significado. */
.badge--info .badge__dot--live {
    animation: pulse 1.6s var(--ease) infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.35; transform: scale(0.82); }
}

/* ---- botões */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: var(--sp-2);
    min-height: 34px;
    padding: 0 var(--sp-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: inherit; font-size: var(--text-sm); font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--motion-fast) var(--ease),
                border-color var(--motion-fast) var(--ease),
                color var(--motion-fast) var(--ease);
}
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn--quiet { background: transparent; color: var(--fg-muted); }
.btn--quiet:hover { background: var(--surface-hover); color: var(--fg); }
.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn--danger:hover { background: var(--danger); color: var(--fg-inverse); }
.btn--sm { min-height: 28px; padding: 0 var(--sp-3); font-size: var(--text-xs); }
.btn--block { width: 100%; }
.btn[disabled], .btn[aria-disabled='true'] {
    opacity: 0.45; cursor: not-allowed; pointer-events: none;
}

/* Estado de espera: o botão trava e mostra o progresso no próprio sítio. */
.btn[data-loading='true'] { pointer-events: none; opacity: 0.75; }
.btn[data-loading='true'] .btn__label { opacity: 0.6; }
.spinner {
    width: 14px; height: 14px; flex: 0 0 auto;
    border: 2px solid currentColor; border-right-color: transparent;
    border-radius: var(--radius-full);
    animation: spin 620ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- formulários */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field + .field { margin-top: var(--sp-4); }
.field__label { font-size: var(--text-sm); font-weight: 600; }
.field__label .req { color: var(--danger); margin-left: 2px; }
.field__hint { font-size: var(--text-xs); color: var(--fg-subtle); }
.field__error { font-size: var(--text-xs); color: var(--danger); font-weight: 500; }

.input, .select, .textarea {
    width: 100%;
    min-height: 36px;
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--fg);
    font-family: inherit;
    font-size: var(--text-base);
    transition: border-color var(--motion-fast) var(--ease);
}
.textarea { min-height: 84px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid='true'] { border-color: var(--danger); }
.input:disabled, .select:disabled, .textarea:disabled {
    opacity: 0.5; cursor: not-allowed;
}
.input[readonly] { background: var(--muted); color: var(--fg-muted); }

.field-row { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.checkbox { display: flex; align-items: flex-start; gap: var(--sp-2); font-size: var(--text-base); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }

/* Resumo de erros no topo do formulário (recebe foco após submissão). */
.form-errors {
    border: 1px solid var(--danger);
    background: var(--danger-soft);
    border-radius: var(--radius);
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-4);
    font-size: var(--text-sm);
}
.form-errors h3 { font-size: var(--text-sm); color: var(--danger); margin-bottom: var(--sp-2); }
.form-errors ul { margin: 0; padding-left: var(--sp-4); }
.form-errors a { color: var(--danger); text-decoration: underline; }

/* ---- barra de filtros */
.toolbar {
    display: flex; align-items: center; gap: var(--sp-2);
    flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.toolbar .input, .toolbar .select { min-height: 34px; width: auto; }
.search {
    position: relative; flex: 0 1 300px; min-width: 200px;
}
.search svg {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: var(--fg-subtle); pointer-events: none;
}
.search .input { padding-left: 2rem; }

.chip {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    padding: 0.25rem 0.625rem;
    border: 1px solid var(--border); border-radius: var(--radius-full);
    background: var(--surface); color: var(--fg-muted);
    font-size: var(--text-xs); font-weight: 500; cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--fg); }
.chip--on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip__x { display: inline-grid; place-items: center; width: 14px; height: 14px; }

/* ---- tabela */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--surface-sunken);
    text-align: left;
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--text-2xs); text-transform: uppercase;
    letter-spacing: 0.08em; font-weight: 600; color: var(--fg-subtle);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr { transition: background var(--motion-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table td.actions { text-align: right; white-space: nowrap; }
.table__primary { font-weight: 600; color: var(--fg); }
.table__meta { font-size: var(--text-xs); color: var(--fg-subtle); }

th[aria-sort] { cursor: pointer; }
th[aria-sort='ascending']::after  { content: ' ↑'; color: var(--accent); }
th[aria-sort='descending']::after { content: ' ↓'; color: var(--accent); }

/* ---- estados vazios / carregamento / erro */
.empty {
    padding: var(--sp-7) var(--sp-5);
    text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
}
.empty__icon {
    width: 44px; height: 44px; color: var(--fg-subtle);
    background: var(--muted); border-radius: var(--radius-lg);
    display: grid; place-items: center;
}
.empty__icon svg { width: 22px; height: 22px; }
.empty__title { font-size: var(--text-md); font-weight: 600; }
.empty__text { font-size: var(--text-sm); color: var(--fg-muted); max-width: 46ch; }

.skeleton {
    background: linear-gradient(90deg, var(--muted) 25%, var(--surface-hover) 37%, var(--muted) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease-in-out infinite;
    border-radius: var(--radius);
    height: 1rem;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.state-error {
    border: 1px solid var(--danger); background: var(--danger-soft);
    border-radius: var(--radius); padding: var(--sp-4);
    display: flex; gap: var(--sp-3); align-items: flex-start;
    font-size: var(--text-sm);
}
.state-error svg { width: 18px; height: 18px; color: var(--danger); flex: 0 0 auto; }

/* ---- modal */
.overlay {
    position: fixed; inset: 0; z-index: var(--z-modal);
    background: rgba(2, 6, 23, 0.62);
    backdrop-filter: blur(2px);
    display: grid; place-items: center;
    padding: var(--sp-4);
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: min(520px, 100%);
    max-height: min(86dvh, 760px);
    display: flex; flex-direction: column;
}
.modal--wide { width: min(880px, 100%); }
.modal__head {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: var(--sp-3);
}
.modal__title { font-size: var(--text-md); }
.modal__body { padding: var(--sp-5); overflow-y: auto; }
.modal__foot {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: var(--sp-2);
}

/* ---- drawer lateral (detalhe de dispositivo) */
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--z-drawer);
    width: min(520px, 100%);
    background: var(--bg-elevated);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
}
.drawer__head {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: flex-start; gap: var(--sp-3);
}
.drawer__body { padding: var(--sp-5); overflow-y: auto; flex: 1 1 auto; }

/* ---- lista de definição (detalhe) */
.dl { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--text-sm); }
.dl dt { color: var(--fg-subtle); }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---- linha temporal (eventos) */
.timeline { display: flex; flex-direction: column; }
.timeline__item {
    display: grid; grid-template-columns: 14px 1fr; gap: var(--sp-3);
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
}
.timeline__item:last-child { border-bottom: 0; }
.timeline__mark {
    width: 8px; height: 8px; margin-top: 6px; border-radius: var(--radius-full);
    background: var(--neutral);
}
.timeline__mark--error { background: var(--danger); }
.timeline__mark--warning { background: var(--warn); }
.timeline__mark--info { background: var(--info); }
.timeline__meta { font-size: var(--text-xs); color: var(--fg-subtle); margin-top: 2px; }

/* ---- notificações (toasts) */
.toasts {
    position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: var(--z-toast);
    display: flex; flex-direction: column; gap: var(--sp-2);
    width: min(360px, calc(100vw - 2rem));
}
.toast {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--neutral);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--text-sm);
}
.toast--ok     { border-left-color: var(--ok); }
.toast--error  { border-left-color: var(--danger); }
.toast--warn   { border-left-color: var(--warn); }
.toast__title { font-weight: 600; }
.toast__text { color: var(--fg-muted); font-size: var(--text-xs); margin-top: 2px; }
.toast__close { margin-left: auto; background: none; border: 0; color: var(--fg-subtle); cursor: pointer; }

/* ---- código de activação (grande, para ler à distância) */
.pair-code {
    font-family: var(--font-mono);
    font-size: 2.75rem;
    font-weight: 600;
    letter-spacing: 0.32em;
    text-indent: 0.32em;
    color: var(--accent);
    background: var(--surface-sunken);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    text-align: center;
}

/* ---- miniatura de conteúdo */
.thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: grid; place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb__type {
    position: absolute; bottom: var(--sp-2); left: var(--sp-2);
    background: rgba(2, 6, 23, 0.72); color: #F8FAFC;
    font-size: var(--text-2xs); font-weight: 600;
    padding: 0.125rem 0.375rem; border-radius: var(--radius-sm);
    font-family: var(--font-mono);
}
.thumb__placeholder { color: var(--fg-subtle); }
.thumb__placeholder svg { width: 26px; height: 26px; }

.media-card { display: flex; flex-direction: column; gap: var(--sp-2); }
.media-card__name { font-size: var(--text-sm); font-weight: 600; overflow-wrap: anywhere; }
.media-card__meta { font-size: var(--text-xs); color: var(--fg-subtle); font-family: var(--font-mono); }

/* ---- itens de playlist (reordenáveis) */
.pl-item {
    display: grid;
    grid-template-columns: 28px 72px minmax(0, 1fr) auto auto;
    align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.pl-item + .pl-item { margin-top: var(--sp-2); }
.pl-item__pos { font-family: var(--font-mono); color: var(--fg-subtle); font-size: var(--text-xs); text-align: center; }
.pl-item__thumb { aspect-ratio: 16/9; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-sunken); }
.pl-item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.pl-item--dragging { opacity: 0.5; border-style: dashed; }
.pl-item--over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- gráfico de barras minimalista (24 h) */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 52px; }
.spark__bar { flex: 1 1 0; background: var(--info-soft); border-radius: 2px 2px 0 0; min-height: 2px; }
.spark__bar--err { background: var(--danger); }

/* ---- paginação */
.pager { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-sm); }
.pager__info { color: var(--fg-subtle); font-size: var(--text-xs); margin-right: auto; }

/* ---------------------------------------------------- 5. responsividade */
@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: var(--z-drawer);
        width: var(--sidebar-w);
        transform: translateX(-100%);
        transition: transform var(--motion-slow) var(--ease);
    }
    .sidebar[data-open='true'] { transform: none; }
    .sidebar-scrim {
        position: fixed; inset: 0; z-index: calc(var(--z-drawer) - 1);
        background: rgba(2, 6, 23, 0.6);
    }
    .content { padding: var(--sp-4); }
    .grid--split { grid-template-columns: 1fr; }
}

@media (min-width: 1025px) {
    .nav-toggle { display: none; }
}

@media (max-width: 640px) {
    .topbar { padding: 0 var(--sp-4); }
    .user-chip__name, .user-chip__role { display: none; }
    .page-head__actions { width: 100%; }
    .pair-code { font-size: 2rem; letter-spacing: 0.2em; text-indent: 0.2em; }
}

/* ------------------------------------------------- 6. movimento reduzido */
/* Quem pediu menos movimento recebe o estado final, não uma animação
   mais curta. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- animações de entrada (aplicadas por classe, nunca globalmente) */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise    { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-in-right { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.anim-fade  { animation: fade-in var(--motion-base) var(--ease) both; }
.anim-rise  { animation: rise var(--motion-base) var(--ease) both; }
.anim-panel { animation: slide-in-right var(--motion-slow) var(--ease) both; }

/* Escalonamento de entrada em grelhas: 40 ms por item, no máximo 8 —
   passado esse ponto o utilizador sente atraso, não polimento. */
.anim-stagger > * { animation: rise var(--motion-base) var(--ease) both; }
.anim-stagger > *:nth-child(1) { animation-delay: 0ms; }
.anim-stagger > *:nth-child(2) { animation-delay: 40ms; }
.anim-stagger > *:nth-child(3) { animation-delay: 80ms; }
.anim-stagger > *:nth-child(4) { animation-delay: 120ms; }
.anim-stagger > *:nth-child(5) { animation-delay: 160ms; }
.anim-stagger > *:nth-child(6) { animation-delay: 200ms; }
.anim-stagger > *:nth-child(7) { animation-delay: 240ms; }
.anim-stagger > *:nth-child(n+8) { animation-delay: 280ms; }

/* Realce momentâneo de um valor que acabou de mudar (auto-refresh):
   o operador vê O QUE mudou sem ter de comparar com a memória. */
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.just-changed { animation: flash 900ms var(--ease) both; border-radius: var(--radius-sm); }

/* ------------------------------------------- 6b. manual do fluxo (fluxo.php)

   Coluna estreita de propósito: são passos que se leem por ordem, e uma
   linha de texto larga de mais faz perder o sítio entre um passo e o
   seguinte. As setas fazem metade do trabalho de dizer que isto é uma
   sequência e não um menu.                                                  */
/* A largura é a mesma para a coluna de passos, para as setas e para o cartão
   final. Fica no .content e não no .fluxo porque o cartão final é irmão da
   coluna, e uma variável declarada em .fluxo não lhe chegava. */
.content { --fluxo-w: 720px; }

.fluxo { max-width: var(--fluxo-w); display: grid; gap: 0; }

.fluxo-passo {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius);
    padding: var(--sp-4);
    display: grid;
    gap: var(--sp-3);
}

/* Laranja só quando há algo à espera de alguém. Se estivesse sempre aceso,
   deixava de ser lido — é o mesmo princípio do aviso de licença. */
.fluxo-passo--atencao { border-left-color: var(--warn); }

.fluxo-passo__head { display: flex; align-items: flex-start; gap: var(--sp-3); }

.fluxo-passo__n {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    display: grid; place-items: center;
    border-radius: var(--radius-full);
    background: var(--accent-soft); color: var(--accent);
    font-size: var(--text-sm); font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.fluxo-passo__id { flex: 1 1 auto; min-width: 0; }

.fluxo-passo__titulo {
    display: flex; align-items: center; gap: var(--sp-2);
    font-size: var(--text-md); font-weight: 600;
}
.fluxo-passo__titulo svg { width: 16px; height: 16px; color: var(--fg-subtle); flex: 0 0 auto; }

.fluxo-passo__meta { font-size: var(--text-xs); color: var(--fg-subtle); margin-top: 2px; }

.fluxo-passo__texto {
    font-size: var(--text-sm); color: var(--fg-muted);
    line-height: 1.6; max-width: 66ch; margin: 0;
}

.fluxo-figura { margin: 0; display: grid; gap: var(--sp-2); }
.fluxo-figura__zoom {
    padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); cursor: zoom-in; overflow: hidden; display: block; width: 100%;
}
.fluxo-figura__zoom:hover { border-color: var(--border-strong); }
.fluxo-figura__zoom img { display: block; width: 100%; height: auto; }
.fluxo-figura figcaption { font-size: var(--text-xs); color: var(--fg-subtle); }

.fluxo-passo .btn { justify-self: start; }

.fluxo-seta {
    max-width: var(--fluxo-w);
    text-align: center;
    color: var(--border-strong);
    font-size: var(--text-lg);
    line-height: 1;
    padding: var(--sp-2) 0;
}

.fluxo-extras { display: grid; gap: var(--sp-4); }
.fluxo-extra { display: flex; align-items: flex-start; gap: var(--sp-3); }
.fluxo-extra__ico { color: var(--fg-subtle); margin-top: 2px; flex: 0 0 auto; }
.fluxo-extra > div { flex: 1 1 auto; min-width: 0; }
.fluxo-extra__titulo { font-size: var(--text-sm); font-weight: 600; }
.fluxo-extra__texto { font-size: var(--text-xs); color: var(--fg-muted); line-height: 1.55; max-width: 62ch; }
.fluxo-extra .btn { flex: 0 0 auto; }

/* Ampliação. É um overlay simples e não um <dialog> porque o backdrop
   nativo não aceita os tokens de tema — ficava preto no tema claro. */
/* `display:grid` numa classe ganha ao atributo `hidden`, que não tem
   especificidade nenhuma — sem esta linha a ampliação nasce aberta. */
.fluxo-lupa[hidden] { display: none; }

.fluxo-lupa {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0, 0, 0, .74);
    display: grid; place-items: center;
    padding: var(--sp-5);
    cursor: zoom-out;
}
.fluxo-lupa__caixa {
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius); overflow: hidden;
    max-width: min(1280px, 96vw); max-height: 92vh;
    display: flex; flex-direction: column; cursor: default;
}
.fluxo-lupa__head {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
}
.fluxo-lupa__head strong { flex: 1 1 auto; }
.fluxo-lupa img { display: block; max-width: 100%; max-height: calc(92vh - 52px); object-fit: contain; }

@media (max-width: 640px) {
    .fluxo-passo__head { flex-wrap: wrap; }
    .fluxo-extra { flex-wrap: wrap; }
}

/* ---------------------------------------------------------- 7. impressão */
@media print {
    .sidebar, .topbar, .page-head__actions, .toolbar, .toasts { display: none !important; }
    body { background: #fff; color: #000; }
    .card { border-color: #ccc; box-shadow: none; }
}
