* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

:root {
    --cassems-red: #d6222a;
    --cassems-red-dark: #a81820;
    --cassems-blue: #1d71b8;
    --cassems-blue-dark: #0b4b8c;
    --ink: #1c2733;
    --ink-muted: #5b6b7c;
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-muted: #f4f6f9;
    --border: #dde4ec;
    --success: #1f9d55;
    --danger: #d6222a;
    --radius-lg: 20px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* Casca compacta: preenche a tela no celular; vira um cartao no estilo popup em telas maiores. */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 430px;
    margin: 0 auto;
    background: var(--surface);
}

@media (min-width: 480px) {
    .app-shell {
        min-height: 720px;
        max-height: 92vh;
        margin: 4vh auto;
        border-radius: var(--radius-lg);
        box-shadow: 0 24px 60px -20px rgba(11, 27, 46, 0.35), 0 2px 8px rgba(11, 27, 46, 0.08);
        overflow: hidden;
        border: 1px solid var(--border);
    }
}

.accent-bar {
    height: 5px;
    flex: 0 0 auto;
    background: linear-gradient(90deg, var(--cassems-red) 0%, var(--cassems-red) 48%, var(--cassems-blue) 100%);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--ink);
    flex: 0 0 auto;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.topbar .brand img {
    height: 32px;
    display: block;
}

.topbar .brand-fallback {
    font-size: 1.05rem;
    color: var(--cassems-red-dark);
}

.topbar nav {
    display: flex;
    gap: 0.25rem;
}

.topbar nav a {
    color: var(--ink-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    transition: background 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover {
    background: var(--surface-muted);
    color: var(--ink);
}

.topbar nav a.active {
    background: rgba(29, 113, 184, 0.12);
    color: var(--cassems-blue-dark);
}

.content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    overflow-y: auto;
}

.hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    justify-content: center;
    flex: 1;
}

.hero h1 {
    font-size: 1.4rem;
    margin: 0;
}

.hero p {
    color: var(--ink-muted);
    margin: 0;
    font-size: 0.95rem;
}

.actions {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 1.25rem;
    border-radius: var(--radius-md);
    background: var(--cassems-blue);
    color: #fff;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: background 0.15s ease, transform 0.05s ease;
}

.button:hover {
    background: var(--cassems-blue-dark);
}

.button:active {
    transform: scale(0.98);
}

.button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.button-secondary {
    background: var(--surface-muted);
    color: var(--ink);
    border: 1px solid var(--border);
}

.button-secondary:hover {
    background: var(--border);
}

.button-outline {
    background: transparent;
    color: var(--cassems-blue);
    border: 1px solid var(--cassems-blue);
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
}

.button-outline:hover {
    background: rgba(29, 113, 184, 0.08);
}

/* ===== Painel de captura ===== */

.capture-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
}

#searchStep,
#captureStep {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.step-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.step-subtitle {
    font-size: 0.85rem;
    color: var(--ink-muted);
    margin: -0.5rem 0 0;
}

/* ===== Busca de beneficiario ===== */

.search-field {
    position: relative;
}

.search-field input {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--ink);
    font-size: 0.95rem;
}

.search-field input:focus {
    outline: none;
    border-color: var(--cassems-blue);
    background: var(--surface);
}

.search-hint {
    min-height: 1.2rem;
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin: 0.4rem 0 0;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 260px;
    overflow-y: auto;
}

.search-result {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    text-align: left;
    font: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.search-result:hover {
    border-color: var(--cassems-blue);
    background: rgba(29, 113, 184, 0.05);
}

.search-result-nome {
    font-weight: 600;
    font-size: 0.9rem;
}

.search-result-meta {
    font-size: 0.78rem;
    color: var(--ink-muted);
}

.selected-beneficiario {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    border: 1px solid var(--border);
}

.selected-beneficiario-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.selected-beneficiario-nome {
    font-weight: 700;
    font-size: 0.95rem;
}

.selected-beneficiario-meta {
    font-size: 0.78rem;
    color: var(--ink-muted);
}

/* ===== Camera ===== */

.camera-wrapper {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
}

.camera-wrapper video {
    width: 100%;
    display: block;
    transform: scaleX(-1);
}

.camera-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
}

.camera-wrapper.state-blink,
.camera-wrapper.state-calibrate {
    animation: pulse-ring 1.6s ease-in-out infinite;
}

.camera-wrapper.state-complete {
    animation: pulse-ring-success 0.6s ease-out 1;
}

@keyframes pulse-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(29, 113, 184, 0.35); }
    50% { box-shadow: 0 0 0 12px rgba(29, 113, 184, 0); }
}

@keyframes pulse-ring-success {
    0% { box-shadow: 0 0 0 0 rgba(31, 157, 85, 0.5); }
    100% { box-shadow: 0 0 0 18px rgba(31, 157, 85, 0); }
}

.status-message {
    text-align: center;
    min-height: 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
}

.status-message.state-align { color: #b8790f; }
.status-message.state-calibrate,
.status-message.state-blink { color: var(--cassems-blue); }
.status-message.state-complete { color: var(--success); }
.status-message.state-multiple-faces { color: var(--danger); }

.result-message {
    text-align: center;
    min-height: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.result-message.success {
    color: var(--success);
}

.result-message.failure {
    color: var(--danger);
}

.capture-panel input[type="text"] {
    width: 100%;
    padding: 0.6rem;
    margin: 0.5rem 0 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--ink);
}

/* Embedado num <iframe> do c-conecte-frontend: o proprio iframe ja fica dentro de um modal do
   app pai, entao o "cartao popup" (sombra/borda/margem) e o header (logo/nav) da pagina
   standalone so duplicam moldura — preenche o iframe inteiro sem chrome proprio. */
.embed-mode .accent-bar,
.embed-mode .topbar {
    display: none;
}

.embed-mode .app-shell {
    max-width: none;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
}
