:root {
    --brand-900: #0b1f3a;
    --brand-800: #12305a;
    --primary: #2563eb;
    --primary-600: #1d4ed8;
    --primary-50: #eff4ff;
    --accent: #f59e0b;
    --accent-50: #fff7e6;
    --success: #16a34a;
    --success-50: #ecfdf3;
    --danger: #dc2626;
    --danger-50: #fef2f2;
    --violet: #7c3aed;
    --violet-50: #f4efff;
    --bg: #f2f4f7;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
    --tabbar-h: 64px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

a, .btn-link { color: var(--primary); }

h1:focus { outline: none; }

/* ---------- Casca do app ---------- */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
    background: var(--brand-900);
    color: #fff;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -.01em;
    color: #fff;
    text-decoration: none;
    min-width: 0;
}

.app-brand-logo {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--primary);
    flex-shrink: 0;
}

.app-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: rgba(255, 255, 255, .8);
    min-width: 0;
}

.app-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, .1);
    color: #fff;
    flex-shrink: 0;
}

    .icon-btn:active { background: rgba(255, 255, 255, .2); }

.app-main {
    max-width: 680px;
    margin: 0 auto;
    padding: 20px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}

.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
}

    .app-tabbar .tab-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 11px;
        font-weight: 600;
        color: var(--muted);
        text-decoration: none;
    }

        .app-tabbar .tab-link.active { color: var(--primary); }

.app-sidebar { display: none; }

@media (min-width: 992px) {
    .app-tabbar { display: none; }

    .app-sidebar {
        display: flex;
        flex-direction: column;
        gap: 4px;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 240px;
        padding: 76px 12px 16px;
        background: var(--surface);
        border-right: 1px solid var(--border);
        z-index: 20;
    }

        .app-sidebar .side-link {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 11px 14px;
            border-radius: 12px;
            font-weight: 600;
            font-size: 15px;
            color: var(--muted);
            text-decoration: none;
        }

            .app-sidebar .side-link:hover { background: var(--bg); color: var(--text); }
            .app-sidebar .side-link.active { background: var(--primary-50); color: var(--primary); }

    .app-topbar { z-index: 40; }

    .app-main {
        margin-left: 240px;
        max-width: none;
        padding: 28px 40px 40px;
    }

        .app-main > * { max-width: 960px; }
}

/* ---------- Tipografia ---------- */

.page-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 0 0 4px;
}

.page-subtitle {
    color: var(--muted);
    margin: 0 0 20px;
    font-size: 15px;
}

.section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin: 24px 4px 10px;
}

.muted { color: var(--muted); }

/* ---------- Cartões ---------- */

.card-app {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

    .card-app + .card-app { margin-top: 12px; }

.list-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    background: none;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    width: 100%;
    text-align: left;
}

    .list-item:last-child { border-bottom: 0; }
    button.list-item:active, a.list-item:active { background: var(--bg); }

.list-item-main { flex: 1; min-width: 0; }

.list-item-title {
    font-weight: 700;
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-item-sub {
    font-size: 13.5px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--primary-50);
    color: var(--primary);
    font-weight: 800;
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    padding: 36px 20px;
    color: var(--muted);
}

    .empty-state .empty-icon {
        display: inline-grid;
        place-items: center;
        width: 56px;
        height: 56px;
        border-radius: 16px;
        background: var(--surface);
        box-shadow: var(--shadow);
        color: var(--muted);
        margin-bottom: 12px;
    }

/* ---------- Status / chips ---------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 700;
    background: var(--bg);
    color: var(--muted);
    white-space: nowrap;
}

.chip-success { background: var(--success-50); color: var(--success); }
.chip-warning { background: var(--accent-50); color: #b45309; }
.chip-primary { background: var(--primary-50); color: var(--primary); }
.chip-danger { background: var(--danger-50); color: var(--danger); }

.status-hero {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    padding: 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand-800), var(--primary-600));
    box-shadow: 0 8px 24px rgba(29, 78, 216, .25);
}

    .status-hero .hero-plate {
        font-size: 30px;
        font-weight: 800;
        letter-spacing: .02em;
        margin: 10px 0 2px;
    }

    .status-hero .hero-sub { color: rgba(255, 255, 255, .8); font-size: 14.5px; }

    .status-hero .hero-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        margin-top: 16px;
        padding-top: 14px;
        border-top: 1px solid rgba(255, 255, 255, .18);
    }

    .status-hero .hero-label {
        font-size: 11.5px;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: rgba(255, 255, 255, .65);
    }

    .status-hero .hero-value { font-weight: 700; font-size: 15px; }

    .status-hero .hero-full { grid-column: 1 / -1; }

.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .16);
    font-size: 12.5px;
    font-weight: 700;
}

    .live-dot::before {
        content: "";
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #4ade80;
        box-shadow: 0 0 0 4px rgba(74, 222, 128, .25);
    }

/* ---------- Ações em grade ---------- */

.tile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px;
    min-height: 116px;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    margin: 0;
}

    .tile:active { transform: scale(.98); }
    .tile.is-busy { opacity: .6; pointer-events: none; }
    .tile.is-open { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }

.tile-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
}

.tile-title { font-weight: 700; font-size: 15.5px; line-height: 1.2; }
.tile-sub { font-size: 12.5px; color: var(--muted); line-height: 1.3; }

.tone-primary { background: var(--primary-50); color: var(--primary); }
.tone-accent { background: var(--accent-50); color: #d97706; }
.tone-danger { background: var(--danger-50); color: var(--danger); }
.tone-violet { background: var(--violet-50); color: var(--violet); }
.tone-success { background: var(--success-50); color: var(--success); }

.photo-cta {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px;
    border: 2px dashed #bfd0f7;
    border-radius: var(--radius);
    background: var(--primary-50);
    color: var(--text);
    cursor: pointer;
    margin: 0;
}

    .photo-cta:active { transform: scale(.99); }
    .photo-cta.is-busy { opacity: .7; pointer-events: none; }

    .photo-cta .tile-icon {
        width: 52px;
        height: 52px;
        border-radius: 14px;
        background: var(--primary);
        color: #fff;
        flex-shrink: 0;
    }

.file-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.counters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

/* ---------- Formulários ---------- */

.field { margin-bottom: 14px; }

    .field > label, .field-label {
        display: block;
        font-size: 13.5px;
        font-weight: 600;
        color: var(--muted);
        margin: 0 0 6px 2px;
    }

.field-hint { font-size: 12.5px; color: var(--muted); margin: 6px 2px 0; }

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-control, .form-select {
    min-height: 50px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    font-size: 16px;
    background-color: #fbfcfe;
}

    .form-control:focus, .form-select:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 4px rgba(37, 99, 235, .15);
        background-color: #fff;
    }

.input-with-icon { position: relative; }

    .input-with-icon .form-control { padding-left: 44px; }

    .input-with-icon .input-icon {
        position: absolute;
        left: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--muted);
        pointer-events: none;
    }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

    .form-grid .field { margin-bottom: 0; }

/* ---------- Botões ---------- */

.btn { border-radius: var(--radius-sm); font-weight: 600; }

.btn-primary {
    color: #fff;
    background-color: var(--primary);
    border-color: var(--primary);
}

    .btn-primary:hover, .btn-primary:active, .btn-primary:focus {
        background-color: var(--primary-600) !important;
        border-color: var(--primary-600) !important;
    }

.btn-app {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 54px;
    font-size: 17px;
    font-weight: 700;
    border-radius: 14px;
}

.btn-soft {
    background: var(--bg);
    border: 0;
    color: var(--text);
}

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    border: 0;
    background: var(--bg);
    color: var(--muted);
}

    .btn-icon.danger { color: var(--danger); background: var(--danger-50); }

.btn:focus, .btn:active:focus {
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .2);
}

/* ---------- Avisos ---------- */

.notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 14.5px;
    margin-bottom: 14px;
}

.notice-success { background: var(--success-50); color: #166534; }
.notice-error { background: var(--danger-50); color: #991b1b; }
.notice-info { background: var(--primary-50); color: #1e3a8a; }

.spinner {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2.5px solid currentColor;
    border-right-color: transparent;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

.loading-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 0;
    color: var(--muted);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tela de login ---------- */

.auth-screen {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
    background:
        radial-gradient(1200px 500px at 50% -10%, #1d4ed8 0%, transparent 60%),
        var(--brand-900);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: 24px;
    padding: 24px 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}

.auth-hero {
    text-align: center;
    color: #fff;
    margin-bottom: 24px;
}

    .auth-hero .app-brand-logo {
        width: 64px;
        height: 64px;
        border-radius: 18px;
        margin: 0 auto 14px;
        box-shadow: 0 10px 30px rgba(37, 99, 235, .5);
    }

    .auth-hero h1 { font-size: 26px; font-weight: 800; margin: 0; }
    .auth-hero p { color: rgba(255, 255, 255, .7); margin: 6px 0 0; }

.auth-switch {
    display: block;
    width: 100%;
    margin-top: 14px;
    border: 0;
    background: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 15px;
}

/* ---------- Tabelas (painel do gestor, desktop) ---------- */

.table-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

    .table-card .table { margin: 0; }
    .table-card th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; border-bottom-color: var(--border); padding: 12px 16px; }
    .table-card td { padding: 12px 16px; vertical-align: middle; border-color: var(--border); }
    .table-card tr.clickable { cursor: pointer; }
    .table-card tr.clickable:hover td { background: var(--bg); }

/* ---------- Validação / erro Blazor ---------- */

.valid.modified:not([type=checkbox]) { outline: none; }
.invalid { outline: none; border-color: var(--danger) !important; }
.validation-message { color: var(--danger); font-size: 13px; }

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
    border-radius: var(--radius-sm);
}

    .blazor-error-boundary::after { content: "Ocorreu um erro inesperado nesta tela."; }

#blazor-error-ui {
    background: #fff4d6;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.8rem 1.25rem 0.8rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
