:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --text: #17191c;
    --muted: #616872;
    --border: #dde0e5;
    --accent: #2457d6;
    --accent-text: #ffffff;
    --in: #13804a;
    --in-soft: #e3f4ea;
    --out: #c2362f;
    --out-soft: #fbe6e4;
    --warn: #a35c00;
    --warn-soft: #fdf0dc;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111316;
        --surface: #1a1d21;
        --surface-2: #23272c;
        --text: #eceef1;
        --muted: #9aa2ad;
        --border: #30353b;
        --accent: #6b93ff;
        --accent-text: #0d1117;
        --in: #3cc27c;
        --in-soft: #16301f;
        --out: #f06a5f;
        --out-soft: #3a1c1a;
        --warn: #f0a646;
        --warn-soft: #362812;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: var(--accent); }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; }
.wrap-wide { max-width: 1180px; }

/* Header */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 0; margin-bottom: 8px;
}
.brand { font-weight: 700; letter-spacing: -.01em; text-decoration: none; color: var(--text); }
.who { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }

.nav { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 18px; }
.nav a {
    padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 15px;
}
.nav a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.badge {
    display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px;
    background: var(--out); color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 700;
}

/* Card */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

h1 { font-size: 22px; margin: 8px 0 16px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.tabular { font-variant-numeric: tabular-nums; }

/* Form */
label { display: block; font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=search], select, textarea {
    width: 100%; padding: 11px 12px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .btn:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 120px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; font: inherit; font-weight: 600; border-radius: 10px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-decoration: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-in { background: var(--in); border-color: var(--in); color: #fff; }
.btn-out { background: var(--out); border-color: var(--out); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.btn-link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; }
.inline { display: inline; }

/* Messaggi */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 500; }
.flash-success { background: var(--in-soft); color: var(--in); }
.flash-error { background: var(--out-soft); color: var(--out); }
.flash-info { background: var(--surface-2); color: var(--text); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill-in, .pill-approved { background: var(--in-soft); color: var(--in); }
.pill-out, .pill-rejected, .pill-revoked { background: var(--out-soft); color: var(--out); }
.pill-pending, .pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-muted { background: var(--surface-2); color: var(--muted); }

/* Timbratura */
.clock { text-align: center; margin: 18px 0 6px; }
.clock-time { font-size: 56px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.clock-date { color: var(--muted); text-transform: capitalize; }

.state { text-align: center; margin: 14px 0 22px; }

.punch-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.punch-btn {
    aspect-ratio: 1 / 1; max-height: 220px; width: 100%;
    border: 0; border-radius: 22px; cursor: pointer; color: #fff;
    font: 800 46px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: .02em;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    transition: transform .08s ease, opacity .2s ease;
    -webkit-tap-highlight-color: transparent;
}
.punch-btn span { font-size: 15px; font-weight: 600; opacity: .9; letter-spacing: 0; }
.punch-btn:active:not(:disabled) { transform: scale(.97); }
.punch-btn.in { background: var(--in); }
.punch-btn.out { background: var(--out); }
.punch-btn:disabled { opacity: .22; cursor: not-allowed; }
.punch-btn.busy { opacity: .6; }

.today { margin-top: 22px; }
.today-list { list-style: none; padding: 0; margin: 0; }
.today-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.today-list li:last-child { border-bottom: 0; }

.links { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 18px; }

/* Giornata */
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0 16px; }
.day-nav .title { text-align: center; }
.day-nav .title strong { display: block; font-size: 18px; text-transform: capitalize; }
.day-nav input[type=date] { width: auto; padding: 4px 8px; font-size: 14px; }

.expense-list { list-style: none; margin: 0 0 14px; padding: 0; }
.expense-list li { padding: 9px 0; border-bottom: 1px solid var(--border); }
.expense-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.expense-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.expense-list .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.expense-total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 4px; }

.danger-zone { border-color: var(--out); }
.danger-zone h2 { color: var(--out); }

/* Allegati */
.attachments { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.attachments li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.att-link { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; }
.att-link:hover .att-name { text-decoration: underline; }
.att-thumb, .att-icon {
    width: 40px; height: 40px; flex: 0 0 40px; border-radius: 8px; object-fit: cover;
    background: var(--surface-2); border: 1px solid var(--border);
}
.att-icon { display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: var(--muted); }
.att-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-name small { display: block; color: var(--muted); font-size: 12px; }
td .attachments { margin-top: 4px; }
td .att-thumb, td .att-icon { width: 32px; height: 32px; flex-basis: 32px; }

.file-pick { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-weight: 500; cursor: pointer; }
.file-pick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick-btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px;
    border: 1px dashed var(--border); background: var(--surface-2); font-size: 14px; font-weight: 600;
}
.file-pick input:focus-visible + .file-pick-btn { outline: 2px solid var(--accent); outline-offset: 1px; }
.file-pick-names { flex: 1 1 160px; overflow-wrap: anywhere; }

/* Attesa dispositivo */
.waiting { text-align: center; padding: 28px 18px; }
.spinner {
    width: 44px; height: 44px; margin: 0 auto 16px; border-radius: 50%;
    border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabelle admin */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.note-cell { max-width: 320px; white-space: pre-line; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 28px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 14px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin: 0; flex: 1 1 150px; }

.session { white-space: nowrap; }
.session form { display: inline; }
.x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 14px; }
.x:hover { color: var(--out); }

@media (max-width: 420px) {
    .clock-time { font-size: 46px; }
    .punch-btn { font-size: 38px; }
}
