* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --text: #111827;
    --muted: #667085;
    --border: #d9dee8;
    --border-soft: #edf0f5;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --radius: 6px;
    --shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
}

a {
    color: var(--primary);
    text-decoration: none;
}

.topbar {
    min-height: 54px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    color: var(--text);
    font-size: 17px;
    font-weight: 800;
}

.nav {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
}

.container {
    width: min(1060px, calc(100% - 32px));
    margin: 28px auto;
}

.hero {
    margin-bottom: 20px;
}

.hero h1,
.card h1 {
    margin: 0 0 8px;
    font-size: 32px;
    line-height: 1.15;
}

.hero p,
.card p,
.muted {
    margin: 0;
    color: var(--muted);
}

.card,
.auth-card,
.ticket-card,
.notice {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card + .card,
.slots-card {
    margin-top: 22px;
}

.card h2 {
    margin: 0 0 22px;
    font-size: 26px;
    line-height: 1.2;
}

.card h3 {
    margin: 22px 0 10px;
    font-size: 20px;
}

.card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    display: block;
    margin: 0 0 5px;
    font-weight: 700;
    font-size: 14px;
}

input,
select {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

button,
.button {
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: var(--radius);
    background: var(--primary);
    color: #ffffff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.secondary {
    background: #e5e7eb;
    color: var(--text);
}

.secondary:hover {
    background: #d1d5db;
}

.danger {
    background: var(--danger);
}

.danger:hover {
    background: var(--danger-hover);
}

.inline-form {
    display: inline;
}

.link-button {
    height: auto;
    padding: 0;
    background: transparent;
    color: var(--primary);
}

.link-button:hover {
    background: transparent;
    color: var(--primary-hover);
}

.row {
    display: flex;
    gap: 12px;
    align-items: end;
}

.row input,
.row select {
    flex: 1;
}

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

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

.admin-grid .card {
    height: 100%;
    min-height: 130px;
    align-self: stretch;
}

.admin-grid .card + .card {
    margin-top: 0;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 2px 0;
    font-weight: 700;
}

.checkbox input {
    width: auto;
    height: auto;
}

.auth-card {
    max-width: 520px;
    margin: 60px auto;
}

.auth-card h1 {
    margin: 0 0 28px;
}

.auth-card input {
    margin-bottom: 14px;
}

.auth-card button {
    margin-top: 4px;
}

.ticket-filter-row {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 170px auto;
    gap: 14px;
    align-items: end;
}

.ticket-filter-row.only-category {
    grid-template-columns: 1fr;
}

.ticket-filter-category,
.ticket-filter-date,
.ticket-filter-button {
    min-width: 0;
}

.ticket-filter-button button {
    white-space: nowrap;
}

.slot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 14px;
}

.slot-button {
    width: 100%;
    min-height: 88px;
    height: auto;
    padding: 14px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--text);
    display: grid;
    align-content: center;
    gap: 8px;
}

.slot-button:hover {
    background: #eff6ff;
}

.slot-button span {
    display: block;
    font-size: 24px;
    line-height: 1;
    font-weight: 900;
    color: var(--primary);
}

.slot-button small {
    color: var(--muted);
    font-weight: 700;
}

.ticket-card {
    max-width: 520px;
    margin: 0 auto;
    text-align: center;
}

.ticket-number {
    margin: 16px 0 22px;
    font-size: 54px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: 3px;
    color: var(--primary-hover);
}

.summary {
    display: grid;
    text-align: left;
    margin: 20px 0;
}

.summary div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-soft);
}

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

.link-box {
    padding: 12px;
    border-radius: var(--radius);
    background: #f3f4f6;
    text-align: center;
    font-size: 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow-wrap: anywhere;
}

.qr-box {
    margin: 18px 0 10px;
    display: flex;
    justify-content: center;
}

.qr-box img {
    width: 160px;
    height: 160px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
}

.qr-caption {
    margin-bottom: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

.notice {
    margin: 16px 0;
}

.notice.error {
    color: #991b1b;
    background: #fef2f2;
    border-color: #fecaca;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
}

.status-booked {
    background: #dbeafe;
    color: #1e40af;
}

.status-called {
    background: #fef3c7;
    color: #92400e;
}

.status-served {
    background: #dcfce7;
    color: #166534;
}

.status-missed {
    background: #fee2e2;
    color: #991b1b;
}

.status-cancelled {
    background: #e5e7eb;
    color: #374151;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 13px;
}

.operator-grid {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    margin-top: 18px;
}

.current-ticket {
    width: 360px;
    flex: 0 0 360px;
    text-align: center;
}

.operator-grid > .card:not(.current-ticket) {
    flex: 1;
    min-width: 0;
}

.operator-grid .card {
    margin-top: 0;
}

.current-ticket .muted {
    margin-bottom: 14px;
}

.operator-number {
    margin: 14px 0 18px;
    font-size: 52px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: 3px;
    color: var(--primary);
}

.operator-actions {
    display: grid;
    gap: 10px;
}

.operator-actions form,
.call-next-form {
    margin: 0;
}

.operator-actions button,
.big-button {
    width: 100%;
}

.big-button {
    height: 48px;
    margin-top: 14px;
    font-size: 16px;
}

.empty-state {
    margin: 16px 0;
    color: var(--muted);
}

.next-ticket-hint {
    margin-top: 12px;
    color: var(--muted);
}

.next-ticket-hint b {
    color: var(--text);
}

.search-card {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.search-result {
    margin-top: 18px;
}

.search-result .ticket-card {
    margin-top: 0;
}

.ticket-search-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 180px auto;
    gap: 14px;
    align-items: end;
}

.ticket-search-date {
    min-width: 0;
}

.ticket-search-button button {
    white-space: nowrap;
}

.confirm-card {
    max-width: 500px;
}

.confirm-time {
    margin: 18px 0 24px;
    font-size: 52px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--primary);
}

.confirm-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 18px;
}

.confirm-actions form {
    margin: 0;
}

.confirm-actions button,
.confirm-actions .button {
    width: 100%;
}

.footer {
    margin-top: 32px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

.footer a {
    color: var(--primary);
}

.table-form {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
    margin: 0 0 8px;
}

.table-form input {
    min-width: 160px;
}

.table-form button {
    white-space: nowrap;
}

td .table-form:last-child {
    margin-bottom: 0;
}

.users-create-form .form-grid {
    margin-bottom: 4px;
}

.users-create-form button {
    width: auto;
    min-width: 180px;
}

.users-table {
    table-layout: fixed;
}

.users-table th,
.users-table td {
    vertical-align: middle;
}

.user-password-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.user-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.user-actions form {
    margin: 0;
}

.user-actions button,
.user-password-form button {
    height: 38px;
    white-space: nowrap;
}

.user-password-form input {
    height: 38px;
}

@media (max-width: 900px) {
    .operator-grid {
        flex-direction: column;
    }

    .current-ticket,
    .operator-grid > .card:not(.current-ticket) {
        width: 100%;
        flex: none;
    }
}

@media (max-width: 720px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 16px;
    }

    .nav {
        flex-wrap: wrap;
        gap: 12px;
    }

    .container {
        width: min(100% - 24px, 1060px);
        margin: 20px auto;
    }

    .hero h1,
    .card h1 {
        font-size: 26px;
    }

    .row,
    .grid,
    .form-grid,
    .ticket-filter-row,
    .ticket-filter-row.only-category,
    .ticket-search-row {
        grid-template-columns: 1fr;
        flex-direction: column;
    }

    .row button,
    .ticket-filter-button button,
    .ticket-search-button button {
        width: 100%;
    }

    .ticket-number {
        font-size: 42px;
    }

    .summary div {
        flex-direction: column;
        gap: 4px;
    }
}

@media (max-width: 560px) {
    .confirm-actions {
        grid-template-columns: 1fr;
    }
}