/* ------------------------------------------------------------------
   Demo statica piattaforma previsionale - foglio di stile unico
   Nessuna dipendenza esterna: apribile con doppio click (file://)
   ------------------------------------------------------------------ */

:root {
    --primary-50: #f0fbfa;
    --primary-100: #ccf0ec;
    --primary-200: #b8e9e4;
    --primary-300: #86dad4;
    --primary-500: #32a8a2;
    --primary-700: #2a7374;
    --primary-800: #2a5e60;
    --accent: #facc15;
    --accent-hover: #eab308;
    --accent-soft: #fffae6;
    --thead: #fff3d7;
    --bg: #f9fafb;
    --border: #e5e7eb;
    --text: #111827;
    --muted: #6b7280;
    --red: #dc2626;
    --green: #16a34a;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------------------------- Topbar ---------------------------- */

.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    z-index: 35;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: .02em;
    text-decoration: none;
}

.topbar .brand .mark {
    width: 30px; height: 30px;
    border-radius: 9px;
    background: var(--primary-700);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 15px;
}

.topbar .brand small {
    display: block;
    font-weight: 500;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0;
}

.topbar .right { display: flex; align-items: center; gap: 12px; }

.demo-pill {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: #854d0e;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
}

.avatar {
    width: 32px; height: 32px;
    border-radius: 999px;
    background: #e5e7eb;
    display: grid;
    place-items: center;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

/* ---------------------------- Sidebar ---------------------------- */

.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 112px;
    height: 100vh;
    padding-top: 68px;
    background: #fff;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 34;
}

.sidebar ul {
    list-style: none;
    margin: 0;
    padding: 8px 0 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.sidebar li { position: relative; }

.sidebar a {
    width: 64px; height: 64px;
    border: 1px solid var(--border);
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: #374151;
    text-decoration: none;
    transition: background .12s ease;
}

.sidebar a:hover { background: var(--accent-soft); }
.sidebar li.active a { background: var(--accent-soft); border-color: var(--accent); }
.sidebar .label {
    position: absolute;
    bottom: -18px;
    left: 0; right: 0;
    text-align: center;
    font-size: 11px;
    color: #4b5563;
}
.sidebar svg { width: 24px; height: 24px; }

/* ---------------------------- Layout ---------------------------- */

.content {
    margin-left: 112px;
    padding: 76px 20px 60px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 8px 16px;
    flex-wrap: wrap;
}

h1.page-title { font-size: 28px; font-weight: 600; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px;
    flex-wrap: wrap;
}

.card-head h2 { font-size: 18px; margin: 0; font-weight: 600; }
.card-body { padding: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .content { margin-left: 0; padding: 76px 12px 40px; }
    .sidebar { display: none; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------- Bottoni ---------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary { background: var(--primary-700); color: #fff; }
.btn-primary:hover { background: var(--primary-800); }
.btn-accent { background: var(--accent); color: #422006; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: #fff; color: #374151; border: 1px solid var(--border); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------------------------- Tabelle ---------------------------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

table.data thead th {
    background: var(--thead);
    text-align: left;
    font-weight: 600;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

table.data thead th .sort { opacity: .45; margin-left: 4px; }

table.data tbody td,
table.data tbody th {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f2f4;
    text-align: left;
    font-weight: 400;
}

table.data tbody tr:hover { background: #fcfcfd; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.compound { background: #fff7ed; }
table.data tbody tr.compound:hover { background: #ffedd5; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

table.grid-table {
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}
table.grid-table th, table.grid-table td {
    border: 1px solid var(--border);
    padding: 7px 10px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
table.grid-table th { background: #f3f4f6; font-weight: 600; text-align: center; }
table.grid-table thead tr.years th { color: #fff; }
table.grid-table thead tr.years th.y0 { background: #4b5563; }
table.grid-table thead tr.years th.y1 { background: #374151; }
table.grid-table thead tr.years th.y2 { background: #1f2937; }
table.grid-table td.code { background: var(--accent); font-weight: 600; text-align: left; }
table.grid-table td.desc { text-align: left; }
table.grid-table td.inv { background: #ede9fe; text-align: right; }
table.grid-table td.neg { background: #fca5a5; color: #7f1d1d; font-style: italic; }
table.grid-table td.hasorder { position: relative; }
table.grid-table td.hasorder::before {
    content: "";
    position: absolute;
    left: 0; bottom: 0;
    width: 8px; height: 100%;
    background: #004aff;
}

/* Tabella report previsionale */
table.report {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.report th, table.report td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
table.report thead th { background: #f3f4f6; font-weight: 600; white-space: nowrap; }
table.report tr.past td { color: #6b7280; }
table.report tr.current { background: #eff6ff; }
table.report tr.reorder-row { background: #fef2f2; }
table.report td.month { font-weight: 600; white-space: nowrap; }

.kv { width: auto; border-collapse: collapse; font-size: 13px; }
.kv th, .kv td { border: 1px solid var(--border); padding: 8px 14px; }
.kv th { background: var(--primary-100); text-align: left; font-weight: 600; }
.kv td { text-align: right; }

/* ---------------------------- Testo / badge ---------------------------- */

.muted { color: var(--muted); }
.null-value { color: #9ca3af; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }
.est { color: #a78bfa; font-weight: 600; }
.est-manual { color: #d97706; font-weight: 600; font-style: italic; }
.link { color: #ea580c; text-decoration: underline; cursor: pointer; }

.badge {
    display: inline-block;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}
.badge-teal { background: var(--primary-100); color: var(--primary-800); border-color: var(--primary-200); }
.badge-yellow { background: #fef9c3; color: #854d0e; border-color: #fde68a; }
.badge-red { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge-green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-gray { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }
.badge-blue { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* ---------------------------- KPI ---------------------------- */

.kpi {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
}
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.kpi .delta { font-size: 12px; margin-top: 4px; }

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

.filters {
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

input[type=text], input[type=date], input[type=number], select, textarea {
    font-family: inherit;
    font-size: 13px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    width: 100%;
}

input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-300); outline-offset: 0; }

.dropzone {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    background: #f9fafb;
    padding: 44px 20px;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
}
.dropzone:hover { background: #f3f4f6; }
.dropzone strong { color: var(--text); }

/* ---------------------------- Tabs ---------------------------- */

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
}
.tabs button {
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 14px 16px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.tabs button.active { color: var(--primary-700); border-bottom-color: var(--primary-700); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------------------- Legenda ---------------------------- */

.legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12px; color: #4b5563; padding: 12px 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------------------------- Toast demo ---------------------------- */

#toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: #111827;
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 100;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
    max-width: 320px;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ---------------------------- Nota demo ---------------------------- */

.demo-note {
    background: var(--accent-soft);
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 12px;
    color: #854d0e;
    margin-bottom: 16px;
}

.breadcrumb { font-size: 12px; color: var(--muted); padding: 0 8px 8px; }
.breadcrumb a { color: var(--primary-700); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.chart { width: 100%; height: auto; }
