/* =============================================================================
   DistintaBase Pro — Foglio di stile
   Tema scuro professionale, mobile-first, completamente responsive.
   ========================================================================== */

/* ── Variabili tema ───────────────────────────────────────────────────────── */
:root {
    --bg:           #1a2332;   /* sfondo pagina            */
    --surface:      #1e2d40;   /* card / superfici         */
    --surface-2:    #243349;   /* superfici alternate      */
    --surface-3:    #2b3b54;   /* hover / input            */
    --border:       #324563;
    --accent:       #2563eb;   /* blu accento              */
    --accent-hover: #1d4ed8;
    --text:         #e2e8f0;
    --text-muted:   #94a3b8;
    --text-dim:     #64748b;
    --ok:           #22c55e;   /* utile positivo           */
    --ok-bg:        #14321f;
    --danger:       #ef4444;   /* utile negativo / errori  */
    --danger-bg:    #3b1d1d;
    --warning:      #f59e0b;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 10px 30px rgba(0, 0, 0, .3);
    --shadow-sm:    0 2px 8px rgba(0, 0, 0, .2);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ── Reset di base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0 0 .6rem; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }

/* ── Header / navigazione ─────────────────────────────────────────────────── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.app-header .inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: .75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.app-header .brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .5rem;
}
.app-header .brand .logo {
    width: 28px; height: 28px;
    background: var(--accent);
    border-radius: 7px;
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: .9rem;
}
.app-header nav {
    margin-left: auto;
    display: flex;
    gap: .25rem;
    flex-wrap: wrap;
}
.app-header nav a {
    color: var(--text-muted);
    padding: .45rem .8rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.app-header nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.app-header nav a.active { background: var(--accent); color: #fff; }

/* ── Layout pagina ────────────────────────────────────────────────────────── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.25rem 1rem 4rem;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

/* ── Breadcrumb ───────────────────────────────────────────────────────────── */
.breadcrumb {
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .sep { color: var(--text-dim); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

/* ── Card / griglia prodotti ──────────────────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 880px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    transition: transform .12s ease, border-color .12s ease;
    position: relative;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { margin-bottom: .35rem; }
.card .meta { color: var(--text-muted); font-size: .85rem; }
.card .note { color: var(--text-dim); font-size: .85rem; margin-top: .5rem; }
.card .card-actions {
    position: absolute; top: .65rem; right: .65rem;
    display: flex; gap: .35rem; opacity: 0; transition: opacity .12s ease;
}
.card:hover .card-actions { opacity: 1; }
@media (hover: none) { .card .card-actions { opacity: 1; } }

/* ── Pannelli / sezioni ───────────────────────────────────────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}
.panel h2 { font-size: 1.05rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); margin: 1.25rem 0 .6rem; }

/* ── Bottoni ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    font: inherit; font-weight: 600;
    padding: .6rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent); color: #fff;
    cursor: pointer;
    transition: background .12s ease, opacity .12s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #dc2626; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; }

/* Pulsanti icona (modifica/elimina) */
.icon-btn {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-size: .95rem;
    transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* ── Form ─────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 1rem; }
.field label {
    display: block; font-size: .85rem; font-weight: 600;
    color: var(--text-muted); margin-bottom: .35rem;
}
.field .hint { font-size: .78rem; color: var(--text-dim); margin-top: .25rem; }

input[type="text"], input[type="number"], input[type="password"],
select, textarea {
    width: 100%;
    font: inherit;
    padding: .6rem .75rem;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
}
textarea { resize: vertical; min-height: 70px; }
select { cursor: pointer; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 120px; }

/* ── Tabelle ──────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--surface-2);
    text-align: left;
    padding: .7rem .8rem;
    font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td { padding: .65rem .8rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr:hover { background: var(--surface-3); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .icon-btn { display: inline-grid; vertical-align: middle; }

/* Valori utile positivi/negativi */
.val-ok  { color: var(--ok);     font-weight: 600; }
.val-neg { color: var(--danger); font-weight: 600; }

/* Modifica inline tessuti */
table input { padding: .4rem .5rem; font-size: .9rem; }
td.editing { background: var(--surface-3); }

/* ── Layout articolo (due colonne desktop, una mobile) ────────────────────── */
.articolo-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
}
@media (min-width: 860px) {
    .articolo-layout { grid-template-columns: 1.2fr 1fr; }
    .articolo-layout .col-risultati { position: sticky; top: 80px; }
}

/* ── Scheda risultati ─────────────────────────────────────────────────────── */
.risultati {
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.risultati h2 { border: none; margin-bottom: 1rem; }
.ris-row {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: .55rem 0;
    border-bottom: 1px dashed var(--border);
    gap: 1rem;
}
.ris-row:last-child { border-bottom: none; }
.ris-row .label { color: var(--text-muted); font-size: .9rem; }
.ris-row .value { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.ris-row.highlight .value { font-size: 1.3rem; }
.ris-row.big { padding: .8rem 0; }

/* ── Modale ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(10, 15, 25, .65);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem; z-index: 100;
    opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%; max-width: 460px;
    max-height: 90vh; overflow-y: auto;
    transform: translateY(8px); transition: transform .15s ease;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; }
.modal-body { padding: 1.25rem; }
.modal-foot {
    padding: 1rem 1.25rem; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: .6rem;
}
.modal .close-x {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.4rem; cursor: pointer; line-height: 1; padding: 0;
}
.modal .close-x:hover { color: var(--text); }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-stack {
    position: fixed; bottom: 1.25rem; right: 1.25rem;
    display: flex; flex-direction: column; gap: .6rem;
    z-index: 200; max-width: calc(100vw - 2.5rem);
}
.toast {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: .8rem 1rem;
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: .9rem;
    min-width: 220px;
    animation: toast-in .2s ease;
}
.toast.success { border-left-color: var(--ok); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.fade-out { animation: toast-out .25s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ── Spinner / loading ────────────────────────────────────────────────────── */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(10, 15, 25, .45);
    display: none; align-items: center; justify-content: center;
    z-index: 150;
}
.loading-overlay.show { display: flex; }
.loading-overlay .spinner {
    width: 42px; height: 42px; border-width: 4px;
    border-color: rgba(255, 255, 255, .2); border-top-color: var(--accent);
}

/* ── Stati vuoti ──────────────────────────────────────────────────────────── */
.empty {
    text-align: center; padding: 3rem 1rem; color: var(--text-muted);
    border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { font-size: 2.5rem; margin-bottom: .5rem; opacity: .6; }

/* ── Badge / pill ─────────────────────────────────────────────────────────── */
.pill {
    display: inline-block; padding: .15rem .55rem; border-radius: 999px;
    background: var(--surface-3); color: var(--text-muted);
    font-size: .78rem; font-weight: 600;
}

/* ── Utilità ──────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.flex { display: flex; gap: .6rem; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.hidden { display: none !important; }

/* Anteprima tessuto (sola lettura, sotto la dropdown) */
.tessuto-preview {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .4rem .9rem;
    margin-top: -.3rem;
}
.tessuto-preview .ris-row { padding: .35rem 0; }
.tessuto-preview .ris-row .value { font-size: .95rem; }

/* Banner offline (PWA) */
.offline-banner {
    background: var(--warning); color: #1a1205; text-align: center;
    padding: .5rem 1rem; font-size: .88rem; font-weight: 600;
}
