/* =================================================================
   FormDB — foglio di stile
   Ripresa della grafica di tools.yunikon.it (palette slate/sky,
   card arrotondate, etichette maiuscole spaziate).
   Nessuna dipendenza esterna: tutto locale.
   ============================================================== */

:root {
    --bg:          #f8fafc;
    --card:        #ffffff;
    --ink:         #020617;
    --ink-soft:    #1e293b;
    --muted:       #64748b;
    --muted-2:     #475569;
    --line:        #e2e8f0;
    --line-strong: #cbd5e1;
    --sky:         #0284c7;
    --sky-deep:    #0369a1;
    --sky-soft:    #f0f9ff;
    --sky-line:    #0ea5e9;
    --ok-bg:       #ecfdf5;
    --ok-ink:      #047857;
    --warn-bg:     #fffbeb;
    --warn-ink:    #b45309;
    --err-bg:      #fff1f2;
    --err-ink:     #be123c;
    --radius:      16px;
    --radius-sm:   12px;
    --shadow:      0 1px 2px rgba(0, 0, 0, .05);
    --font:        ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
                   "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--sky-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
    max-width: 1800px;
    margin: 0 auto;
    padding: 14px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ---------------- Card ---------------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 14px;
}

.card--flush { padding: 0; overflow: hidden; }

.eyebrow {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: var(--sky);
}

h1 {
    margin: 2px 0 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--ink);
}

h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ---------------- Testata ---------------- */

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

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand img { height: 40px; width: auto; display: block; }

.brand .divider {
    border-left: 1px solid var(--line);
    padding-left: 16px;
}

.session {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
}

.session strong { color: var(--ink-soft); font-weight: 600; }

/* ---------------- Contatori ---------------- */

/* Otto riquadri su una riga sola: testo e spazi si restringono con la
   finestra (clamp) invece di mandare a capo i riquadri. */
.stats {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 8px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 7px clamp(8px, 0.7vw, 12px);
    min-width: 0;
}

.stat .k {
    font-size: clamp(9px, 0.66vw, 11px);
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat .v {
    font-size: clamp(17px, 1.35vw, 23px);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -.02em;
    color: var(--ink);
}

.stat--hl { background: var(--sky-soft); border-color: var(--sky-line); }
.stat--hl .k, .stat--hl .v { color: var(--sky-deep); }

/* ---------------- Form / filtri ---------------- */

/* Sei colonne: tutti i filtri stanno in due righe. */
.filters {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px 10px;
    align-items: end;
}

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field--wide { grid-column: span 2; }

label {
    font-size: clamp(9px, 0.62vw, 10px);
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Intestazione della scheda filtri: bassa, non deve rubare spazio. */
.filters-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

input[type="text"],
input[type="date"],
input[type="email"],
input[type="password"],
input[type="search"],
select {
    height: 36px;
    width: 100%;
    padding: 0 10px;
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s, background-color .15s;
}

input:focus, select:focus {
    border-color: #38bdf8;
    background: #fff;
}

select { cursor: pointer; }

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

.btn {
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #fff;
    background: var(--ink);
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color .15s;
    white-space: nowrap;
}

.btn:hover { background: var(--sky); text-decoration: none; }

.btn--ghost {
    background: #fff;
    color: var(--ink-soft);
    border: 1px solid var(--line-strong);
}
.btn--ghost:hover { background: var(--sky-soft); color: var(--sky-deep); border-color: var(--sky-line); }

.btn--sky { background: var(--sky); }
.btn--sky:hover { background: var(--sky-deep); }

.btn--sm { height: 32px; padding: 0 12px; font-size: 11px; }

/* ---------------- Pill ---------------- */

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--muted-2);
    white-space: nowrap;
}

.pill--sky { background: var(--sky-soft); border-color: var(--sky-line); color: var(--sky-deep); }

/* ---------------- Tabella ---------------- */

.tablebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.tablewrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    background: #f1f5f9;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted-2);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    z-index: 1;
}

tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}

tbody tr.lead:hover { background: var(--sky-soft); }
tbody tr.lead { cursor: pointer; }

td.nowrap { white-space: nowrap; }
td.dim { color: var(--muted); }

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.msg {
    display: block;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted-2);
}

/* riga di dettaglio */
tr.detail > td {
    background: #f8fafc;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.kv {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px 20px;
}

.kv div { min-width: 0; }

.kv .k {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}

.kv .v { font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; }

.detail-msg {
    margin-top: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--ink-soft);
}

/* ---------------- Paginazione ---------------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 12px;
}

.pager .pages { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.pager a, .pager span.cur {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted-2);
    font-weight: 600;
    font-size: 12px;
}

.pager a:hover { background: var(--sky-soft); color: var(--sky-deep); border-color: var(--sky-line); text-decoration: none; }
.pager span.cur { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------------- Messaggi ---------------- */

.notice {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid;
}

.notice--err  { background: var(--err-bg);  color: var(--err-ink);  border-color: #fecdd3; }
.notice--ok   { background: var(--ok-bg);   color: var(--ok-ink);   border-color: #a7f3d0; }
.notice--warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #fde68a; }

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

/* ---------------- Login ---------------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(2, 6, 23, .06);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-card img { height: 44px; width: auto; align-self: flex-start; }

.login-foot {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .04em;
}

/* ---------------- Responsive ---------------- */

/* Sotto i 1040px otto riquadri diventerebbero illeggibili: si passa a 4. */
@media (max-width: 1040px) {
    .stats   { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

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

@media (max-width: 560px) {
    .filters { grid-template-columns: 1fr; }
    .field--wide { grid-column: auto; }
    .brand .divider { border: 0; padding-left: 0; }
    .wrap { padding: 14px 12px 32px; }
}

@media print {
    .card--filters, .pager, .session, .btn { display: none !important; }
    body { background: #fff; }
}

/* Colonne testuali lunghe: possono andare a capo per non allargare
   la tabella oltre lo schermo. */
td.soft {
    max-width: 190px;
    overflow-wrap: anywhere;
}
