:root {
    --kaju: #e85d04;
    --kaju-dark: #c44d00;
    --nexum: #1a2744;
    --bg: #f0f2f6;
    --card: #fff;
    --text: #1a1a1a;
    --muted: #6c757d;
    --danger: #c1121f;
    --success: #0c7f57;
    --warning: #856404;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06);
    --shadow-elevated: 0 8px 32px rgba(26, 39, 68, 0.1);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: linear-gradient(165deg, #fff8f3 0%, var(--bg) 45%, #e8edf5 100%);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100dvh;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1:focus,
h2:focus {
    outline: none;
}

#app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ── Shell & header ── */

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(26, 39, 68, 0.97);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(12px);
}

.app-header__inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px 16px;
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 16px;
    width: 100%;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    min-width: 0;
}

.app-brand__badge {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(180deg, var(--kaju) 0%, var(--kaju-dark) 100%);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    box-shadow: 0 4px 14px rgba(232, 93, 4, 0.35);
}

.app-brand__text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.app-brand__text strong {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-brand__text small {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 500;
}

.app-header__nav {
    display: flex;
    justify-content: center;
}

.app-navlink {
    padding: 8px 16px;
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.72);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background-color 0.15s, color 0.15s;
}

.app-navlink.active,
.app-navlink:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.app-header__session {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: end;
}

.app-header__user {
    display: none;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.25;
    min-width: 0;
}

.app-header__user strong {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.app-header__user small {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.app-main {
    flex: 1;
    padding: 20px 16px 32px;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
}

.app-main--public {
    max-width: 440px;
    padding-top: 12px;
}

/* ── Login ── */

.login-page {
    width: 100%;
}

.login-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 24px;
}

.login-logos__brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.login-logos__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(180deg, var(--kaju) 0%, var(--kaju-dark) 100%);
    color: #fff;
    font-weight: 800;
    font-size: 0.9rem;
    box-shadow: 0 4px 14px rgba(232, 93, 4, 0.3);
}

.login-logos__name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--nexum);
}

.login-logos__sep {
    width: 1px;
    height: 36px;
    background: #d1d5db;
}

.login-logos__partner {
    font-weight: 600;
    font-size: 1rem;
    color: var(--muted);
}

.login-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px 20px;
    box-shadow: var(--shadow-elevated);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.login-card h1 {
    font-size: 1.35rem;
    margin-bottom: 6px;
    color: var(--nexum);
}

.login-card__lead {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.login-card__tips {
    margin: 20px 0 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-card__tips li {
    position: relative;
    padding-left: 18px;
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.45;
}

.login-card__tips li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kaju);
}

/* ── Page sections ── */

.page-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-heading {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.section-heading h1 {
    font-size: 1.35rem;
    color: var(--nexum);
}

.section-heading h2 {
    font-size: 1.15rem;
    color: var(--nexum);
}

.section-heading p {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.section-heading--inline {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.section-heading__eyebrow,
.empty-state__eyebrow,
.pwa-install-tag {
    display: inline-block;
    width: fit-content;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    background: #fff3cd;
    color: var(--warning);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.section-heading--inline .toolbar-group {
    margin-top: 4px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--kaju);
}

.back-link::before {
    content: "←";
}

/* ── Status & stats ── */

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.78rem;
    white-space: nowrap;
}

.status-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-pill-success {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.status-pill-success::before {
    background: var(--success);
}

.status-pill-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.status-pill-warning::before {
    background: #f59e0b;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-card__label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
}

.stat-card__value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--nexum);
    line-height: 1.2;
}

.stat-card__value--sm {
    font-size: 1rem;
}

/* ── Mesa grid ── */

.mesas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

@media (min-width: 640px) {
    .mesas-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 12px;
    }
}

.mesa-card {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid #e9ecef;
    border-radius: var(--radius);
    background: var(--card);
    padding: 14px;
    text-align: left;
    cursor: pointer;
    box-shadow: var(--shadow-card);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    min-height: 148px;
}

.mesa-card:active {
    transform: scale(0.98);
}

@media (hover: hover) {
    .mesa-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(26, 39, 68, 0.1);
        border-color: rgba(232, 93, 4, 0.35);
    }
}

.mesa-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.mesa-card__header strong {
    font-size: 1rem;
    color: var(--nexum);
}

.mesa-card__status {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    background: rgba(26, 39, 68, 0.08);
    color: var(--nexum);
    flex-shrink: 0;
}

.mesa-card__title {
    flex: 1;
    margin-bottom: 10px;
    color: var(--text);
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.mesa-card__meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 0 8px;
    padding-top: 8px;
    border-top: 1px solid #f0f2f6;
}

.mesa-card__meta > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mesa-card__meta dt {
    margin: 0;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
}

.mesa-card__meta dd {
    margin: 0;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--nexum);
}

.mesa-card__time {
    color: var(--muted);
    font-size: 0.72rem;
}

.mesa-card--livre { border-left: 4px solid #cad2e6; }
.mesa-card--aberto { border-left: 4px solid var(--kaju); }
.mesa-card--aberto .mesa-card__status { background: #fff3e6; color: var(--kaju-dark); }
.mesa-card--reservado { border-left: 4px solid #7c3aed; }
.mesa-card--reservado .mesa-card__status { background: #f3e8ff; color: #6d28d9; }
.mesa-card--manutencao { border-left: 4px solid var(--nexum); }
.mesa-card--fechando { border-left: 4px solid #f59e0b; }
.mesa-card--fechando .mesa-card__status { background: #fff8e8; color: var(--warning); }
.mesa-card--finalizado,
.mesa-card--cancelado { border-left: 4px solid var(--danger); opacity: 0.85; }

/* ── Detail layout ── */

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
}

@media (min-width: 900px) {
    .detail-layout {
        grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr);
        align-items: start;
    }

    .detail-layout > .panel-card:last-child {
        position: sticky;
        top: 76px;
    }
}

.detail-layout--single {
    max-width: 520px;
}

.panel-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f2f6;
    font-size: 0.88rem;
    color: var(--muted);
}

.detail-meta strong {
    color: var(--nexum);
}

/* ── Items table (desktop) / cards (mobile) ── */

.items-table {
    margin-top: 16px;
}

.items-table__header {
    display: none;
}

.items-table__row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: #fafbfc;
    border: 1px solid #e9ecef;
    border-radius: var(--radius-sm);
}

.items-table__row strong {
    display: block;
    font-size: 0.95rem;
    color: var(--nexum);
}

.items-table__row small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.78rem;
}

.items-table__row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 0.85rem;
}

.items-table__row-meta span {
    color: var(--muted);
}

.items-table__row-meta strong {
    display: inline;
    font-size: inherit;
    color: var(--text);
}

.items-table__empty {
    padding: 16px;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    background: #fafbfc;
    border-radius: var(--radius-sm);
    border: 1px dashed #d1d5db;
}

@media (min-width: 640px) {
    .items-table {
        border: 1px solid #e9ecef;
        border-radius: var(--radius-sm);
        overflow: hidden;
    }

    .items-table__header {
        display: grid;
        grid-template-columns: minmax(0, 2fr) 70px 90px 90px;
        gap: 8px;
        padding: 10px 14px;
        background: #f7f8fc;
        color: var(--muted);
        font-size: 0.78rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

    .items-table__row {
        display: grid;
        grid-template-columns: minmax(0, 2fr) 70px 90px 90px;
        gap: 8px;
        align-items: center;
        margin-bottom: 0;
        background: #fff;
        border: none;
        border-radius: 0;
        border-top: 1px solid #e9ecef;
        padding: 10px 14px;
    }

    .items-table__row-meta {
        display: none;
    }

    .items-table__empty {
        border: none;
        border-radius: 0;
        border-top: 1px solid #e9ecef;
    }
}

/* ── Forms ── */

.draft-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    margin-bottom: 10px;
    background: #fafbfc;
    border: 1px solid #e9ecef;
    border-radius: var(--radius-sm);
}

.draft-row .app-btn-compact {
    align-self: flex-start;
}

@media (min-width: 640px) {
    .draft-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 120px auto;
        align-items: end;
        padding: 0;
        background: transparent;
        border: none;
    }
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 16px 0;
}

.app-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.app-field span {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--nexum);
}

.app-input {
    width: 100%;
    padding: 14px 12px;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: #fafbfc;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.app-input:focus {
    outline: none;
    border-color: var(--kaju);
    box-shadow: 0 0 0 3px rgba(232, 93, 4, 0.15);
    background: #fff;
}

.app-input-area {
    min-height: 96px;
    resize: vertical;
}

/* ── Buttons ── */

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    transition: transform 0.12s, opacity 0.12s;
}

.app-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.app-btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.app-btn-primary {
    background: linear-gradient(180deg, var(--kaju) 0%, var(--kaju-dark) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(232, 93, 4, 0.35);
}

.app-btn-secondary {
    background: #e9ecef;
    color: var(--text);
}

.app-btn-ghost {
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.25);
    min-height: 36px;
    padding: 8px 14px;
    font-size: 0.88rem;
}

.app-btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.app-btn-block {
    width: 100%;
}

.app-btn-compact {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.88rem;
}

.toolbar-group .app-btn-primary {
    flex: 1;
}

@media (min-width: 480px) {
    .toolbar-group .app-btn-primary {
        flex: none;
    }
}

/* ── Feedback & empty ── */

.feedback {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.45;
}

.feedback-error {
    color: var(--danger);
    background: #fff1f1;
    border: 1px solid #ffd4d4;
}

.feedback-success {
    color: var(--success);
    background: #effcf6;
    border: 1px solid #c9f0de;
}

.feedback-warning {
    color: var(--warning);
    background: #fff8e8;
    border: 1px solid #fde3ad;
}

.empty-state,
.loading-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.empty-state h2 {
    margin: 8px 0;
    color: var(--nexum);
}

.empty-state p,
.loading-card {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.validation-summary-errors {
    margin: 0 0 14px;
    padding-left: 16px;
    color: var(--danger);
    font-size: 0.88rem;
}

/* ── PWA install ── */

.pwa-install-button {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 30;
    min-height: 48px;
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--kaju) 0%, var(--kaju-dark) 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(232, 93, 4, 0.4);
}

.pwa-install-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(12, 20, 38, 0.55);
    backdrop-filter: blur(8px);
}

.pwa-install-dialog {
    position: relative;
    width: min(100%, 440px);
    padding: 24px 20px;
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-elevated);
}

.pwa-install-dialog h2 {
    margin: 8px 0 12px;
    color: var(--nexum);
}

.pwa-install-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: #e9ecef;
    cursor: pointer;
    color: var(--nexum);
    font-size: 1.1rem;
    line-height: 1;
}

.pwa-install-text {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.pwa-install-steps {
    margin: 12px 0 0;
    padding-left: 18px;
    color: var(--muted);
    line-height: 1.65;
    font-size: 0.9rem;
}

/* ── Blazor loading & errors ── */

#blazor-error-ui {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    z-index: 50;
    display: none;
    padding: 14px 48px 14px 14px;
    border-radius: var(--radius);
    background: #431515;
    color: #fff;
    box-shadow: var(--shadow-elevated);
}

#blazor-error-ui .reload {
    font-weight: 700;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: 10px;
    right: 14px;
    cursor: pointer;
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 22vh auto 1rem;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e6f4;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--kaju);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    inset: calc(22vh + 3.25rem) 0 auto 0;
    text-align: center;
    font-weight: 700;
    color: var(--nexum);
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Carregando");
}

/* ── Responsive ── */

@media (min-width: 480px) {
    .app-header__user {
        display: flex;
    }
}

@media (max-width: 640px) {
    .app-header__inner {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
    }

    .app-brand {
        grid-column: 1;
    }

    .app-header__session {
        grid-column: 2;
        grid-row: 1;
    }

    .app-header__nav {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .section-heading--inline {
        flex-direction: column;
    }

    .section-heading--inline .toolbar-group {
        width: 100%;
    }

    .section-heading--inline .toolbar-group .app-btn {
        flex: 1;
    }

    .pwa-install-actions {
        flex-direction: column;
    }
}
