:root {
    color-scheme: light;
    --ink: #17202a;
    --muted: #627184;
    --line: #d8dee8;
    --bg: #f6f8fb;
    --panel: #ffffff;
    --teal: #12796f;
    --teal-dark: #0d5f58;
    --amber: #b45f06;
    --red: #b42318;
    --green: #16703c;
    --blue: #2557a7;
    --shadow: 0 8px 24px rgba(23, 32, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.admin-page {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.public-shell {
    width: min(620px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.brand strong {
    font-size: 22px;
    line-height: 1.1;
}

.brand span {
    color: var(--muted);
    font-size: 14px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel-body {
    padding: 22px;
}

.grid {
    display: grid;
    gap: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.stat strong {
    display: block;
    margin-top: 6px;
    font-size: 26px;
    line-height: 1;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field label,
.check-row span {
    font-weight: 650;
    font-size: 14px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

textarea {
    min-height: 88px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(18, 121, 111, 0.16);
    border-color: var(--teal);
}

.row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.check-row input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
}

.help {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 13px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.button-primary,
button.button-primary {
    background: var(--teal);
    color: #fff;
}

.button-primary:hover {
    background: var(--teal-dark);
}

.button-secondary {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}

.button-warning {
    background: #fff7ed;
    color: var(--amber);
    border-color: #fed7aa;
}

.button-danger {
    background: #fff1f2;
    color: var(--red);
    border-color: #fecdd3;
}

.button-success {
    background: #ecfdf3;
    color: var(--green);
    border-color: #bbf7d0;
}

.button-blue {
    background: #eff6ff;
    color: var(--blue);
    border-color: #bfdbfe;
}

.button[aria-disabled="true"],
button:disabled {
    opacity: 0.48;
    pointer-events: none;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.toolbar form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.queue-panel {
    order: 1;
}

.summary-fold {
    order: 2;
}

.admin-management {
    order: 3;
}

.admin-fold {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.admin-fold > summary {
    min-height: 42px;
    padding: 10px 14px;
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
    list-style: none;
}

.admin-fold > summary::-webkit-details-marker {
    display: none;
}

.admin-fold > summary::after {
    content: "+";
    float: right;
    color: var(--muted);
}

.admin-fold[open] > summary::after {
    content: "-";
}

.admin-fold .stats-grid,
.admin-fold .toolbar {
    padding: 0 14px 14px;
}

.queue-filter {
    margin-bottom: 14px;
    box-shadow: none;
}

.admin-refresh-note {
    align-self: center;
}

.branch-panel {
    margin-bottom: 18px;
}

.branch-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.branch-card {
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 14px;
}

.branch-card strong {
    font-size: 16px;
}

.branch-card span {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.branch-form,
.admin-user-form {
    display: grid;
    grid-template-columns: minmax(160px, 1.2fr) minmax(160px, 1.5fr) minmax(130px, 1fr) auto;
    gap: 10px;
}

.admin-user-form {
    grid-template-columns: minmax(150px, 1.1fr) minmax(140px, 1fr) minmax(160px, 1fr) minmax(150px, 1fr) auto;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 920px;
}

table.queue-table {
    min-width: 620px;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
    background: #fbfcfe;
}

.queue-summary-row {
    cursor: pointer;
}

.queue-summary-row:hover,
.queue-summary-row.is-open {
    background: #fbfcfe;
}

.queue-summary-row:focus-visible {
    outline: 3px solid rgba(18, 121, 111, 0.18);
    outline-offset: -3px;
}

.queue-status-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

.queue-row-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.queue-detail-row td {
    padding-top: 0;
}

.queue-detail-card {
    display: grid;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 14px;
}

.queue-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.queue-detail-item {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.queue-detail-item span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.queue-detail-item strong {
    font-size: 15px;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.queue-detail-item small {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.queue-actions form {
    min-width: 0;
}

.guest-main {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.guest-main strong {
    font-size: 15px;
}

.guest-main span {
    color: var(--muted);
    font-size: 13px;
}

.queue-no {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    min-height: 34px;
    border-radius: 8px;
    background: #eef7f6;
    color: var(--teal-dark);
    font-size: 18px;
    letter-spacing: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 13px;
    font-weight: 750;
    white-space: nowrap;
}

.status-waiting {
    background: #fff7ed;
    color: #9a3412;
}

.status-notified {
    background: #eff6ff;
    color: #1d4ed8;
}

.status-ready {
    background: #fff1f2;
    color: #9f1239;
}

.status-seated {
    background: #ecfdf3;
    color: #166534;
}

.status-muted {
    background: #eef2f7;
    color: #475569;
}

.flash {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    background: #fff;
}

.flash.success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.flash.error {
    border-color: #fecdd3;
    background: #fff1f2;
    color: #9f1239;
}

.ticket {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border: 1px dashed #9aa7b8;
    border-radius: 8px;
    background: #fbfcfe;
}

.ticket strong {
    font-size: 32px;
    line-height: 1;
}

.queue-live-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.queue-live-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfe;
    padding: 16px;
}

.queue-live-item span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

.queue-live-item strong {
    display: block;
    margin-top: 8px;
    font-size: 34px;
    line-height: 1;
}

.qr-panel {
    text-align: center;
}

.qr-code-wrap img {
    width: min(360px, 100%);
    height: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

.login-shell {
    width: min(420px, calc(100% - 28px));
    margin: 8vh auto;
}

.install-section {
    border-top: 1px solid var(--line);
    padding-top: 18px;
    margin-top: 18px;
}

.hidden {
    display: none;
}

@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .branch-grid,
    .branch-form,
    .admin-user-form {
        grid-template-columns: 1fr;
    }

    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .page,
    .public-shell {
        width: min(100% - 16px, 620px);
        padding-top: 8px;
    }

    .topbar,
    .ticket {
        align-items: flex-start;
        flex-direction: column;
    }

    .admin-topbar {
        position: sticky;
        top: 0;
        z-index: 20;
        margin: 0 -8px 4px;
        padding: 8px;
        background: rgba(246, 248, 251, 0.96);
        border-bottom: 1px solid var(--line);
        backdrop-filter: blur(10px);
    }

    .admin-topbar .brand strong {
        font-size: 18px;
    }

    .admin-topbar .brand span {
        font-size: 12px;
    }

    .admin-topbar .actions {
        width: 100%;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .admin-topbar .button,
    .admin-topbar button {
        width: auto;
        min-height: 36px;
        flex: 0 0 auto;
        padding: 8px 10px;
        font-size: 13px;
    }

    .row,
    .queue-live-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .panel-body {
        padding: 18px;
    }

    .button,
    button {
        width: 100%;
    }

    .actions {
        flex-direction: column;
    }

    .queue-panel {
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .queue-panel-body {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 0;
    }

    .queue-panel .table-wrap,
    .queue-panel .empty {
        order: 1;
    }

    .queue-filter {
        order: 2;
        margin-bottom: 0;
    }

    .summary-fold {
        order: 2;
    }

    .admin-management {
        order: 3;
    }

    .queue-filter .toolbar {
        margin-bottom: 0;
    }

    .queue-filter .toolbar form,
    .queue-filter .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    table.queue-table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0 8px;
    }

    .queue-table thead {
        display: none;
    }

    .queue-table,
    .queue-table tbody {
        display: block;
        width: 100%;
    }

    .queue-table .queue-summary-row {
        display: grid;
        grid-template-columns: minmax(72px, 1.1fr) minmax(44px, 0.58fr) minmax(58px, 0.72fr) minmax(96px, 1fr);
        gap: 8px;
        align-items: center;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--panel);
        box-shadow: var(--shadow);
        padding: 10px;
    }

    .queue-table .queue-summary-row td {
        display: flex;
        min-width: 0;
        flex-direction: column;
        gap: 4px;
        border-bottom: 0;
        padding: 0;
    }

    .queue-table .queue-summary-row td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 800;
        letter-spacing: 0;
        text-transform: uppercase;
    }

    .queue-table .queue-summary-row td[data-label="No."]::before {
        content: "Queue no";
    }

    .queue-table .queue-detail-row {
        display: block;
        width: 100%;
        margin-top: -8px;
    }

    .queue-table .queue-detail-row.hidden {
        display: none;
    }

    .queue-table .queue-detail-row td {
        display: block;
        width: 100%;
        border-bottom: 0;
        padding: 0 0 8px;
    }

    .queue-detail-card {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        box-shadow: var(--shadow);
        padding: 12px;
    }

    .queue-detail-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .queue-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .queue-actions .button,
    .queue-actions button {
        width: 100%;
        min-height: 44px;
        white-space: normal;
    }

    .queue-status-cell {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .queue-no {
        min-width: 58px;
        min-height: 36px;
        font-size: 20px;
    }
}

@media print {
    body {
        background: #ffffff;
    }

    .print-hidden {
        display: none !important;
    }

    .public-shell {
        width: 100%;
        padding: 0;
    }

    .panel {
        border: 0;
        box-shadow: none;
    }

    .panel-body {
        padding: 0;
    }

    .qr-code-wrap img {
        border: 0;
    }
}
