/* =========================================================
   SANCTUS GRAPHICS — SISTEMA VISUAL COMPARTILHADO
   Direção: minimalismo sobre a fotografia da basílica.
   Painéis escuros translúcidos, tipografia com contraste,
   azul = ação, dourado = destaque, verde/vermelho = estado.
   Movimento sutil, sempre desligável (prefers-reduced-motion).
   Não afeta o overlay nem a arte SVG do lower third.
   ========================================================= */

:root {
    color-scheme: dark;

    /* Texto */
    --ink: #F4F1EA;              /* principal */
    --ink-soft: #B8C0D0;         /* secundário */

    /* Linhas e controles */
    --rule: rgba(255, 255, 255, .12);
    --control: #7C879D;          /* borda de campos e botões (>= 3:1 sobre o painel) */
    --wash: rgba(255, 255, 255, .06);
    --wash-2: rgba(255, 255, 255, .11);

    /* Superfícies */
    --night: #070B14;
    --panel: rgba(12, 19, 34, .76);
    --panel-solid: #0E1527;

    /* Azuis: ação principal */
    --blue-900: #0B3D91;
    --blue-700: #1456C3;
    --blue-300: #93C5FD;
    --blue-100: #DBEAFE;

    /* Dourado: destaque */
    --gold: #D4AF37;
    --gold-300: #F6D37A;

    /* Estados */
    --ok: #22C55E;           --ok-text: #86EFAC;
    --ok-bg: rgba(34, 197, 94, .14);   --ok-line: rgba(134, 239, 172, .45);
    --bad: #EF4444;          --bad-text: #FCA5A5;
    --bad-bg: rgba(239, 68, 68, .14);  --bad-line: rgba(252, 165, 165, .5);
    --warn-text: #F6D37A;
    --warn-bg: rgba(212, 175, 55, .14); --warn-line: rgba(246, 211, 122, .45);
    --info-text: #BFDBFE;
    --info-bg: rgba(59, 130, 246, .16); --info-line: rgba(147, 197, 253, .45);

    --font: "Geist", "SF Pro Display", "Helvetica Neue", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --serif: "Newsreader", "Lyon Text", Georgia, "Times New Roman", serif;
    --mono: "Geist Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

    --r-card: 12px;
    --r-ctl: 8px;
    --ease: cubic-bezier(.16, 1, .3, 1);
    --focus: 0 0 0 2px #070B14, 0 0 0 4px var(--blue-300);

    /* Aliases para estilos locais de páginas */
    --bg: var(--night);
    --ink-900: var(--night);
    --ink-800: var(--ink);
    --ink-600: var(--ink-soft);
    --line: var(--rule);
    --line-soft: var(--rule);
    --surface-2: var(--wash);
    --danger: var(--bad-text);
    --radius: var(--r-ctl);
    --radius-lg: var(--r-card);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--night); }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
}

/* ---------------------------------------------------------
   FUNDO: fotografia + véu escuro (para o texto ler bem)
   --------------------------------------------------------- */
body::before {
    content: "";
    position: fixed; inset: -4%; z-index: -2;
    background: url("/assets/fundo-basilica.jpg") 50% 10% / cover no-repeat;
    animation: bg-drift 80s ease-in-out infinite alternate;
    will-change: transform;
}
body::after {
    content: "";
    position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background: linear-gradient(180deg, rgba(6, 10, 20, .78) 0%, rgba(6, 10, 20, .66) 38%, rgba(6, 10, 20, .6) 62%, rgba(6, 10, 20, .84) 100%);
}
@keyframes bg-drift {
    from { transform: scale(1.02) translate3d(0, 0, 0); }
    to   { transform: scale(1.08) translate3d(-1.5%, -1%, 0); }
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }

.icon { width: 1.25em; height: 1.25em; flex-shrink: 0; fill: currentColor; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-ctl); }

select option { background: var(--panel-solid); color: var(--ink); }

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

/* ---------------------------------------------------------
   ENTRADA SUAVE (só ao abrir a página)
   --------------------------------------------------------- */
.reveal { opacity: 0; animation: rise .7s var(--ease) both; animation-delay: calc(var(--i, 0) * 80ms); }
@keyframes rise {
    from { opacity: 0; transform: translate3d(0, 14px, 0); }
    to   { opacity: 1; transform: none; }
}

/* =========================================================
   BARRA DO APLICATIVO
   ========================================================= */
.app-bar {
    background: rgba(7, 11, 20, .6);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(212, 175, 55, .45);
}
.app-bar-inner {
    max-width: 1080px; margin: 0 auto; padding: 10px 24px;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand-plate { display: flex; align-items: center; background: #fff; border-radius: var(--r-ctl); padding: 6px 12px; height: 48px; flex-shrink: 0; }
.brand-plate img { display: block; height: 32px; width: auto; max-width: 150px; object-fit: contain; }

.app-bar-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.conn-pill {
    display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px;
    border: 1px solid var(--rule); border-radius: 999px;
    font-size: 13px; color: var(--ink);
}
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #94A3B8; flex-shrink: 0; }
.connection-dot.online { background: #4ADE80; }
.connection-dot.offline { background: #F87171; }

/* =========================================================
   PÁGINA
   ========================================================= */
.page { max-width: 1080px; margin: 0 auto; padding: 44px 24px 80px; }

.page-head { margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; color: var(--gold-300); font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.page-title {
    margin: 0; font-family: var(--serif); font-size: 46px; font-weight: 400;
    line-height: 1.05; letter-spacing: -0.025em; color: #FBF8F1;
    text-shadow: 0 2px 24px rgba(0, 0, 0, .35);
}
.page-desc { margin: 12px 0 0; color: var(--ink); font-size: 16px; max-width: 62ch; }
.back-link {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin-bottom: 8px;
    color: var(--blue-300); font-weight: 500; text-decoration: none;
}
.back-link:hover { color: #fff; text-decoration: underline; }

/* =========================================================
   BOTÕES
   ========================================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px;
    border: 1px solid transparent; border-radius: var(--r-ctl);
    font-size: 15px; font-weight: 500; line-height: 1.2; text-decoration: none; white-space: nowrap;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .12s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--blue-700); border-color: rgba(147, 197, 253, .5); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1B66E0; border-color: var(--blue-300); }

.btn-secondary { background: var(--wash); border-color: var(--control); color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: var(--wash-2); border-color: #A5AEC1; }

.btn-ghost { background: transparent; border-color: var(--control); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--wash-2); }

.btn-danger { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-text); font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, .24); border-color: var(--bad-text); }
.btn-danger-solid { background: #C62828; border-color: #C62828; color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: #A91F1F; border-color: #A91F1F; }

/* =========================================================
   CARTÕES: vidro escuro sobre a fotografia
   ========================================================= */
.card {
    background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r-card); overflow: hidden;
    -webkit-backdrop-filter: blur(18px) saturate(1.1); backdrop-filter: blur(18px) saturate(1.1);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 20px 24px; border-bottom: 1px solid var(--rule);
}
.card-title { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.3; }
.card-description { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; }
.card-body { padding: 24px; }

/* =========================================================
   FAIXA "NO AR"
   ========================================================= */
.live-bar {
    position: sticky; top: 8px; z-index: 30;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    margin-bottom: 24px; padding: 14px 16px 14px 20px;
    background: var(--panel); border: 1px solid var(--rule); border-left: 4px solid #7C879D;
    border-radius: var(--r-card);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    transition: background-color .4s ease, border-color .4s ease;
}
.live-bar[data-state="on"] { background: rgba(10, 46, 28, .86); border-color: var(--ok-line); border-left-color: var(--ok); }

.live-status { display: flex; align-items: center; gap: 12px; min-width: 0; }
.live-dot { position: relative; width: 12px; height: 12px; border-radius: 50%; background: #7C879D; flex-shrink: 0; }
.live-bar[data-state="on"] .live-dot { background: var(--ok); }
.live-bar[data-state="on"] .live-dot::after {
    content: ""; position: absolute; inset: 0; border-radius: 50%;
    border: 2px solid var(--ok); animation: live-ring 2.2s ease-out infinite;
}
@keyframes live-ring { from { transform: scale(1); opacity: .8; } to { transform: scale(2.6); opacity: 0; } }

.live-label { font-size: 18px; font-weight: 700; letter-spacing: .02em; color: var(--ink-soft); transition: color .3s ease; }
.live-bar[data-state="on"] .live-label { color: var(--ok-text); }

.live-detail { flex: 1 1 200px; min-width: 0; font-size: 15px; overflow-wrap: anywhere; }
.live-detail strong { font-weight: 600; }
.live-sync { display: block; margin-top: 2px; color: var(--ink-soft); font-family: var(--mono); font-size: 12px; }
.live-bar .btn { flex-shrink: 0; }

/* =========================================================
   LAYOUT DA TRANSMISSÃO
   ========================================================= */
.stage-grid {
    display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, 1fr);
    gap: 24px; align-items: start; margin-bottom: 44px;
}
.stack { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

.preview-area { padding: 16px; background: rgba(0, 0, 0, .28); display: flex; justify-content: center; }
.preview-frame { display: block; width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--rule); background: transparent; border-radius: 6px; }

/* Tema */
.theme-current {
    width: 100%; min-height: 72px; padding: 14px 24px; border: 0; background: transparent;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left;
    transition: background-color .18s ease;
}
.theme-current:hover { background: var(--wash); }
.theme-info { display: flex; align-items: center; gap: 14px; min-width: 0; }
.theme-color { width: 36px; height: 36px; border-radius: var(--r-ctl); border: 1px solid rgba(255, 255, 255, .25); flex-shrink: 0; }
.theme-name { font-size: 16px; font-weight: 600; }
.theme-label { margin-top: 2px; color: var(--ink-soft); font-size: 14px; }
.theme-arrow { color: var(--ink-soft); display: flex; transition: transform .25s var(--ease); }
.theme-current[aria-expanded="true"] .theme-arrow { transform: rotate(180deg); }

.theme-options { display: none; padding: 16px 20px 20px; grid-template-columns: repeat(2, 1fr); gap: 10px; border-top: 1px solid var(--rule); }
.theme-options.open { display: grid; animation: fade-in .25s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.theme-option { min-height: 64px; padding: 10px; text-align: left; border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--wash); transition: border-color .18s ease, background-color .18s ease; }
.theme-option:hover { border-color: var(--control); background: var(--wash-2); }
.theme-option.active { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); background: rgba(212, 175, 55, .1); }
.theme-option-color { height: 22px; border-radius: 4px; margin-bottom: 8px; border: 1px solid rgba(255, 255, 255, .2); }
.theme-option-name { font-size: 14px; font-weight: 500; }

/* Ferramentas (editor, links do OBS, liturgia) */
.tool { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; padding: 16px 24px; }
.tool + .tool { border-top: 1px solid var(--rule); }
.tool-text { flex: 1 1 200px; min-width: 0; }
.tool-title { margin: 0; font-size: 15px; font-weight: 600; }
.tool-desc { margin: 2px 0 0; color: var(--ink-soft); font-size: 13.5px; line-height: 1.5; }
.tool-status { margin: 6px 0 0; color: var(--ok-text); font-size: 13px; font-weight: 500; }
.tool-status:empty { display: none; }

/* =========================================================
   ABAS
   ========================================================= */
.tabs { display: flex; gap: 4px; margin: 0; padding: 0 12px; border-bottom: 1px solid var(--rule); }
.tab {
    min-height: 44px; padding: 0 20px; margin-bottom: -1px;
    border: 0; border-bottom: 2px solid transparent; border-radius: 0;
    background: transparent; color: var(--ink-soft); font-size: 16px; font-weight: 500;
    transition: color .18s ease, border-color .25s ease;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--gold-300); border-bottom-color: var(--gold); font-weight: 600; }

/* =========================================================
   LISTA DE PREDEFINIÇÕES
   ========================================================= */
.preset-list { padding: 0; }

.preset-row { display: flex; align-items: center; gap: 8px; min-height: 76px; padding: 10px 16px 10px 8px; border-left: 4px solid transparent; transition: background-color .25s ease, border-color .25s ease; }
.preset-row + .preset-row { border-top: 1px solid var(--rule); }
.preset-row:hover { background: var(--wash); }
.preset-row.active { background: var(--ok-bg); border-left-color: var(--ok); }

.drag-handle {
    width: 36px; min-width: 36px; height: 56px; display: flex; align-items: center; justify-content: center;
    color: var(--ink-soft); cursor: grab; touch-action: none; border-radius: var(--r-ctl);
    user-select: none; -webkit-user-select: none;
}
.drag-handle:hover { background: var(--wash-2); color: var(--ink); }
.drag-handle:active { cursor: grabbing; }

.preset-content { flex: 1; min-width: 0; }
.preset-name-input {
    width: 100%; min-height: 32px; padding: 2px 6px; margin-left: -6px;
    border: 1px solid transparent; border-radius: 6px; outline: 0;
    background: transparent; color: var(--ink); font-size: 16px; font-weight: 600;
}
.preset-name-input:hover { border-color: var(--rule); }
.preset-name-input:focus { border-color: var(--blue-300); background: rgba(0, 0, 0, .3); box-shadow: var(--focus); }
.preset-description { margin-top: 2px; color: var(--ink-soft); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge-live {
    display: inline-flex; align-items: center; flex-shrink: 0; height: 24px; padding: 0 10px;
    border-radius: 9999px; background: rgba(0, 0, 0, .3); border: 1px solid var(--ok-line); color: var(--ok-text);
    font-size: 11px; font-weight: 700; letter-spacing: .08em;
}

.preset-edit-button {
    width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--control); border-radius: var(--r-ctl); background: var(--wash); color: var(--ink);
    transition: background-color .18s ease;
}
.preset-edit-button:hover { background: var(--wash-2); }

/* Interruptor: área de toque 56x44 */
.switch { position: relative; width: 56px; height: 44px; flex-shrink: 0; display: block; margin: 0; cursor: pointer; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch-slider {
    position: absolute; left: 2px; right: 2px; top: 50%; height: 30px; transform: translateY(-50%);
    border-radius: 999px; background: #6B7690; transition: background-color .25s ease; pointer-events: none;
}
.switch-slider::before {
    content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
    border-radius: 50%; background: #fff; transition: transform .25s var(--ease);
}
.switch input:checked + .switch-slider { background: #16A34A; }
.switch input:checked + .switch-slider::before { transform: translateX(22px); }
.switch input:focus-visible + .switch-slider { box-shadow: var(--focus); }

/* Arrastar */
.preset-row.is-dragging { opacity: .4; background: var(--wash-2); outline: 1px dashed var(--control); }
.preset-placeholder { min-height: 76px; border: 1px dashed var(--blue-300); background: var(--info-bg); pointer-events: none; }

/* Estados vazio / erro */
.empty-state { padding: 48px 24px; text-align: center; color: var(--ink-soft); font-size: 15px; }
.empty-state p { margin: 0 0 16px; }
.empty-state.is-error p { color: var(--bad-text); font-weight: 600; }

/* =========================================================
   FORMULÁRIOS
   ========================================================= */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field label, .field-label { display: block; margin-bottom: 6px; color: var(--ink); font-size: 14px; font-weight: 500; }
.field input, .field select, .field textarea {
    width: 100%; min-height: 46px; padding: 10px 12px;
    border: 1px solid var(--control); border-radius: var(--r-ctl);
    background: rgba(0, 0, 0, .3); color: var(--ink); font-size: 16px;
    transition: border-color .18s ease, background-color .18s ease;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--blue-300); box-shadow: var(--focus); background: rgba(0, 0, 0, .42); }
.field input::placeholder { color: #8A93A8; }
.field small { display: block; margin-top: 6px; color: var(--ink-soft); font-size: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.auto-save { min-height: 20px; margin-top: 16px; color: var(--ink-soft); font-size: 14px; }

/* =========================================================
   MODAIS
   ========================================================= */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center;
    padding: 16px; background: rgba(4, 7, 14, .66);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; animation: fade-only .2s ease both; }
@keyframes fade-only { from { opacity: 0; } to { opacity: 1; } }
.modal {
    width: min(480px, 100%); max-height: calc(100vh - 32px); overflow: auto;
    background: rgba(13, 20, 36, .97); border: 1px solid rgba(255, 255, 255, .16); border-radius: 14px;
}
.modal-backdrop.open .modal { animation: pop-in .3s var(--ease) both; }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
.modal.wide { width: min(640px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--rule); }
.modal-title { margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 400; letter-spacing: -0.01em; color: #FBF8F1; }
.modal-close { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--r-ctl); background: transparent; color: var(--ink-soft); }
.modal-close:hover { background: var(--wash-2); color: var(--ink); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: space-between; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--rule); background: rgba(0, 0, 0, .25); flex-wrap: wrap; }
.modal-text { margin: 0; }
.modal-text + .modal-text { margin-top: 10px; }
.steps { margin: 0; padding-left: 22px; line-height: 1.7; }
.steps li { margin: 8px 0; }

/* =========================================================
   AVISOS
   ========================================================= */
.notice {
    display: flex; gap: 12px 16px; align-items: center; flex-wrap: wrap;
    padding: 14px 16px; margin-bottom: 20px;
    border: 1px solid var(--rule); border-radius: var(--r-card);
    background: var(--panel); color: var(--ink); font-size: 15px;
}
.notice strong { font-weight: 600; }
.notice.is-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }
.notice.is-info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-text); }

/* =========================================================
   TOAST
   ========================================================= */
.toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 200; max-width: min(92vw, 460px);
    padding: 12px 18px; border-radius: var(--r-ctl); background: #F4F1EA; color: #14181F;
    font-size: 15px; font-weight: 500; text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
    opacity: 0; pointer-events: none; transform: translate(-50%, 14px);
    transition: opacity .25s ease, transform .35s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #B42318; color: #fff; }

/* =========================================================
   RESPONSIVO
   ========================================================= */
@media (max-width: 980px) {
    .stage-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    body::before { background-position: 44% 40%; }
    .app-bar-inner { padding: 10px 14px; gap: 10px; }
    .app-bar-tools { gap: 8px; }
    .page { padding: 28px 14px 56px; }
    .page-title { font-size: 34px; }
    .card-header, .card-body, .tool { padding-left: 16px; padding-right: 16px; }
    .theme-current { padding-left: 16px; padding-right: 16px; }
    .live-bar { padding: 12px; gap: 10px; }
    .live-label { font-size: 16px; }
    .live-bar .btn { width: 100%; }
    .field-row { grid-template-columns: 1fr; }
    .stage-grid { margin-bottom: 28px; }
}

@media (max-width: 520px) {
    /* Uma linha só: alça, nome, lápis e interruptor. O selo "NO AR" some aqui
       porque o estado já aparece na faixa do topo, no fundo verde da linha e
       na posição do interruptor. */
    .drag-handle { width: 28px; min-width: 28px; }
    .badge-live { display: none; }
    .preset-row { gap: 6px; padding-right: 10px; }
    .app-bar-tools .btn .btn-label { display: none; }
    .app-bar-tools .btn.btn-icon-mobile { width: 44px; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    .reveal { opacity: 1; }
}
