:root {
    color-scheme: light;
    --bg: #f5f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9e0e7;
    --primary: #146c94;
    --primary-strong: #0b4d6a;
    --ok: #1f8a5b;
    --danger: #b42318;
    --warn: #a15c07;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
}

a {
    color: inherit;
}

code {
    background: #edf2f7;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 2px 5px;
}

.token-code {
    display: inline-block;
    max-width: 260px;
    overflow-wrap: anywhere;
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 9px;
    background: #fff;
}

input[type="file"] {
    padding: 7px;
}

label {
    display: grid;
    gap: 5px;
    color: #344054;
    font-weight: 700;
    font-size: 13px;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 12px 30px rgba(23, 32, 42, .08);
}

.auth-intro {
    margin: 0 0 14px;
    color: var(--muted);
}

.demo-credentials {
    display: grid;
    gap: 10px;
    margin: 0 0 18px;
}

.demo-credentials div {
    display: grid;
    gap: 5px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.demo-credentials strong {
    color: var(--primary-strong);
}

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

.back-site-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--primary-strong);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.auth-back-link {
    margin-bottom: 18px;
}

.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 10px 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 800;
    text-decoration: none;
    color: var(--primary-strong);
}

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

.topbar nav a {
    color: var(--muted);
    text-decoration: none;
}

.logout {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.logout button,
.button {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 12px;
    background: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 700;
}

.button.warn {
    background: #fff4e5;
    border-color: #f3c06b;
    color: var(--warn);
    font-weight: 700;
}

.button.danger {
    background: #fdecea;
    border-color: #f5b5ae;
    color: var(--danger);
    font-weight: 700;
}

.button.small {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 13px;
}

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

.hero {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 24px;
    align-items: end;
    margin-bottom: 28px;
}

.hero h1,
section h1,
section h2 {
    margin: 0 0 14px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

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

.stats article,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stats strong {
    display: block;
    font-size: 30px;
    color: var(--primary-strong);
}

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

.split {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    align-items: start;
}

.employees-list-page {
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 14px;
    height: calc(100vh - 112px);
    min-height: 560px;
}

.employee-detail-page {
    display: grid;
    gap: 16px;
}

.employee-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

.employee-detail-grid.single-column {
    grid-template-columns: minmax(320px, 520px);
}

.employee-form {
    gap: 12px;
}

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

.photo-field {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.photo-preview-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.photo-controls {
    display: grid;
    gap: 6px;
    align-content: start;
}

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

.photo-controls input[type="file"] {
    min-height: 34px;
    padding: 5px;
}

.span-2 {
    grid-column: 1 / -1;
}

.list-header {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.list-header h1 {
    margin: 0;
}

.employee-search {
    display: flex;
    gap: 8px;
    align-items: center;
    min-width: min(540px, 100%);
}

.employee-search input {
    min-width: 260px;
}

.logs-page {
    display: grid;
    gap: 14px;
}

.log-filters {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr)) auto auto;
    gap: 10px;
    align-items: end;
}

.employees-scroll {
    min-height: 0;
    overflow: auto;
}

.employees-scroll .table-wrap {
    min-height: 100%;
}

.stack {
    display: grid;
    gap: 12px;
}

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

.check input {
    width: auto;
    min-height: 0;
}

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

.inline-form select {
    width: auto;
    min-width: 150px;
}

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

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

.employee-photo-preview,
.employee-photo-placeholder,
.webcam-preview {
    width: 96px;
    height: 96px;
    border-radius: 8px;
    border: 1px solid var(--line);
    object-fit: cover;
    background: #edf2f7;
    color: var(--muted);
    display: grid;
    place-items: center;
    font-weight: 800;
}

.employee-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.employee-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    border: 1px solid var(--line);
}

.employee-avatar.placeholder {
    display: inline-grid;
    place-items: center;
    background: #edf2f7;
    color: var(--primary-strong);
    font-size: 13px;
    font-weight: 800;
}

.table-wrap {
    overflow-x: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

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

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

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    min-width: 76px;
    justify-content: center;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 800;
}

.badge.entrata {
    color: var(--ok);
    background: #e9f7ef;
}

.badge.uscita {
    color: var(--warn);
    background: #fff4e5;
}

.badge.rifiutato {
    color: var(--danger);
    background: #fdecea;
}

.alert {
    border-radius: 6px;
    padding: 10px 12px;
    border: 1px solid var(--line);
}

.alert.ok {
    color: var(--ok);
    background: #e9f7ef;
}

.alert.danger {
    color: var(--danger);
    background: #fdecea;
}

.empty {
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 16px;
    color: var(--muted);
}

.maintenance {
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 6px solid var(--warn);
    border-radius: 8px;
    padding: 28px;
}

.maintenance h1 {
    margin: 0 0 10px;
}

.maintenance p:last-child {
    margin-bottom: 0;
    color: var(--muted);
}

@media (max-width: 820px) {
    .topbar,
    .logout {
        align-items: flex-start;
        flex-direction: column;
    }

    .logout {
        margin-left: 0;
    }

    .hero,
    .split,
    .employees-list-page,
    .employee-detail-grid {
        grid-template-columns: 1fr;
        height: auto;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    .employee-form-grid {
        grid-template-columns: 1fr;
    }

    .photo-field,
    .span-2 {
        grid-column: auto;
        grid-row: auto;
    }

    .photo-field {
        grid-template-columns: 1fr;
    }

    .employees-scroll {
        max-height: 70vh;
    }

    .list-header,
    .employee-search,
    .log-filters {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }
}
