/* ============================================================
   PORTALE MONITORAGGI - STUDIO CALASTRI SA
   Palette e tipografia ispirate a studiocalastri.ch
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300;400;500;600;700&family=Open+Sans:wght@300;400;600&display=swap');

:root {
    --color-red:             #CC0000;
    --color-red-hover:       #aa0000;
    --color-black:           #1a1a1a;
    --color-dark:            #2d2d2d;
    --color-muted:           #666666;
    --color-border:          #e0e0e0;
    --color-bg:              #f7f7f7;
    --color-white:           #ffffff;
    --color-section-bg:      #fafafa;
    --color-nav-sep:         #cccccc;
    --color-green:           #1b8a4d;
    --color-blue:            #1565c0;
    --color-amber:           #b07d00;

    --font-main:             'Raleway', 'Helvetica Neue', Arial, sans-serif;
    --font-body:             'Open Sans', 'Helvetica Neue', Arial, sans-serif;
    --font-mono:             'SF Mono', Consolas, 'Liberation Mono', monospace;
    --font-size-base:        15px;

    --letter-spacing-title:  0.15em;
    --letter-spacing-nav:    0.08em;
    --header-height:         90px;
    --max-width:             1280px;
    --border-radius:         3px;
    --shadow-card:           0 2px 8px rgba(0,0,0,0.07);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    background-color: var(--color-bg);
    color: var(--color-black);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

a {
    color: var(--color-red);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--color-red-hover); }

/* ============================================================ HEADER */
.site-header {
    position: sticky;
    top: 0;
    z-index: 200;
    background-color: var(--color-white);
    height: var(--header-height);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.site-header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    gap: 1rem;
}
.site-logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    flex-shrink: 0;
}
.site-logo img { height: 48px; width: auto; }
.site-logo-text { display: flex; flex-direction: column; line-height: 1.2; }
.site-logo-name {
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--color-black);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.site-logo-sub {
    font-size: 0.7rem;
    color: var(--color-muted);
    letter-spacing: 0.04em;
    margin-top: 1px;
}

.site-nav ul {
    list-style: none;
    display: flex;
    align-items: stretch;
    height: var(--header-height);
}
.site-nav li {
    display: flex;
    align-items: center;
    border-left: 1px solid var(--color-nav-sep);
}
.site-nav li:last-child { border-right: 1px solid var(--color-nav-sep); }
.site-nav a {
    display: flex;
    align-items: center;
    padding: 0 1.1rem;
    height: 100%;
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--color-black);
    letter-spacing: var(--letter-spacing-nav);
    text-transform: uppercase;
    white-space: nowrap;
    transition: background 0.15s;
}
.site-nav a:hover { background: #f0f0f0; }
.site-nav a.active { background: var(--color-red); color: var(--color-white) !important; }

.user-info { display: flex; align-items: center; gap: 0.75rem; }
.user-badge {
    padding: 0.2rem 0.6rem;
    background: var(--color-bg);
    border-radius: 2px;
    font-family: var(--font-main);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.user-badge-admin { background: #fde8e8; color: var(--color-red); }
.user-badge-writer { background: #e3f0fb; color: var(--color-blue); }
.user-badge-viewer { background: #f0f0f0; color: var(--color-muted); }

/* ============================================================ LAYOUT */
.page-wrapper {
    max-width: var(--max-width);
    margin: 2rem auto 3rem auto;
    padding: 0 2rem;
    width: 100%;
}
.page-header {
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 1rem;
    display: flex;
    align-items: end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-title {
    font-family: var(--font-main);
    font-size: 1.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-title);
    color: var(--color-black);
    margin-bottom: 0.25rem;
}
.page-subtitle { font-size: 0.875rem; color: var(--color-muted); letter-spacing: 0.03em; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.section-title {
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--color-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    position: relative;
}
.section-title::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 32px; height: 2px;
    background: var(--color-red);
}

/* ============================================================ CARD */
.card {
    background: var(--color-white);
    border-radius: var(--border-radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-card);
    border-top: 3px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-top-color: var(--color-red); }
.card h2 {
    font-family: var(--font-main);
    font-size: 0.92rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
    color: var(--color-black);
}

/* ============================================================ GRIGLIE */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 720px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
.grid-cover-info {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px) { .grid-cover-info { grid-template-columns: 1fr; } }

/* ============================================================ PULSANTI */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: var(--font-main);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.55rem 1.1rem;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary {
    background: var(--color-red);
    color: var(--color-white);
    border-color: var(--color-red);
}
.btn-primary:hover {
    background: var(--color-red-hover);
    border-color: var(--color-red-hover);
    color: var(--color-white);
}
.btn-ghost {
    background: transparent;
    border-color: var(--color-border);
    color: var(--color-black);
}
.btn-ghost:hover { background: #f0f0f0; border-color: #bbb; color: var(--color-black); }
.btn-danger {
    background: transparent;
    border-color: var(--color-red);
    color: var(--color-red);
}
.btn-danger:hover { background: var(--color-red); color: var(--color-white); }
.btn-sm { font-size: 0.72rem; padding: 0.3rem 0.7rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================ FORM */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-family: var(--font-main);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-muted);
    margin-bottom: 0.35rem;
}
.form-input,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="file"],
input[type="datetime-local"],
input[type="color"],
textarea,
select {
    width: 100%;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--color-black);
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 0.55rem 0.75rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
input:focus, textarea:focus, select:focus, .form-input:focus {
    border-color: var(--color-red);
    box-shadow: 0 0 0 3px rgba(204,0,0,0.08);
}
textarea, textarea.form-input { resize: vertical; min-height: 80px; }
.form-help { font-size: 0.75rem; color: var(--color-muted); margin-top: 0.25rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1.25rem; }
.form-check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}
.form-check input[type="checkbox"] { width: auto; }

/* ============================================================ FLASH */
.flash-container {
    max-width: var(--max-width);
    margin: 1rem auto 0 auto;
    padding: 0 2rem;
}
.flash {
    padding: 0.7rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    border-left: 3px solid;
    background: var(--color-white);
}
.flash-success { background: #e6f4ea; color: #2e7d32; border-color: #2e7d32; }
.flash-error   { background: #fde8e8; color: var(--color-red); border-color: var(--color-red); }
.flash-info    { background: #e3f0fb; color: #1565c0; border-color: #1565c0; }
.flash-warning { background: #fff7e0; color: #b07d00; border-color: #b07d00; }

/* ============================================================ TABELLE */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table th, .table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}
.table th {
    font-family: var(--font-main);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-muted);
    background: #f7f7f7;
}
.table tr:hover td { background: #fafafa; }
.table .num,
.table th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.table th.grp {
    text-align: center;
    background: #efefef;
    border-bottom: 2px solid var(--color-border);
}
.table th.grp-zero { color: var(--color-red); background: #fde8e8; }
.table th.grp-prev { color: var(--color-blue); background: #e3f0fb; }
.table td.delta { font-weight: 600; }
.table td.delta-mod { color: var(--color-black); }
.table tr.row-missing td { background: #fff7e0; color: var(--color-amber); }

/* Soglie di tolleranza: applicate alle delta vs zero */
.table td.sev-ok        { color: var(--color-black); }
.table td.sev-attention { color: #d97706; background: #fff7ed; }
.table td.sev-alarm     { color: var(--color-red); background: #fee2e2; font-weight: 700; }

/* Pill di stato severita' (riepilogo punti monitorati) */
.pill-ok2       { background: #e6f4ea; color: var(--color-green); }
.pill-attention { background: #fff7ed; color: #d97706; }
.pill-alarm     { background: #fee2e2; color: var(--color-red); }

.data-table tbody tr td:first-child { font-family: var(--font-mono); }

table.kv {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
table.kv th, table.kv td {
    padding: 0.45rem 0.5rem;
    border-bottom: 1px dashed var(--color-border);
    text-align: left;
}
table.kv th {
    width: 32%;
    font-weight: 600;
    color: var(--color-muted);
    font-family: var(--font-main);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* ============================================================ LOGIN */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a1a 0%, #3d3d3d 100%);
    padding: 2rem;
}
.login-box {
    background: var(--color-white);
    border-radius: var(--border-radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 420px;
    width: 100%;
    padding: 2.5rem 2.5rem;
    border-top: 4px solid var(--color-red);
}
.login-logo { text-align: center; margin-bottom: 1.25rem; }
.login-logo img { max-height: 56px; width: auto; }
.login-title {
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    text-align: center;
    margin-bottom: 0.25rem;
}
.login-subtitle {
    text-align: center;
    color: var(--color-muted);
    font-size: 0.8rem;
    margin-bottom: 1.75rem;
}
.login-defaults {
    margin-top: 1.25rem;
    padding: 0.85rem 1rem;
    background: var(--color-bg);
    border-radius: var(--border-radius);
    font-size: 0.72rem;
    color: var(--color-muted);
}
.login-defaults strong { color: var(--color-black); }
.login-defaults code {
    background: var(--color-white);
    padding: 0.1rem 0.35rem;
    border-radius: 2px;
    font-size: 0.7rem;
}

/* ============================================================ PROJECT GRID */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}
.project-card {
    background: var(--color-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    text-decoration: none;
    color: var(--color-black);
    transition: all 0.2s;
    border-top: 3px solid transparent;
    display: flex;
    flex-direction: column;
}
.project-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border-top-color: var(--color-red);
    color: var(--color-black);
    transform: translateY(-2px);
}
.project-card-thumb {
    width: 100%;
    height: 160px;
    background: var(--color-bg);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-muted);
    font-family: var(--font-main);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.project-card-body {
    padding: 1rem 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.project-card-name {
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.35rem;
}
.project-card-loc {
    font-size: 0.78rem;
    color: var(--color-muted);
    margin-bottom: 0.5rem;
}
.project-card-desc {
    font-size: 0.83rem;
    color: var(--color-muted);
    margin-bottom: 0.75rem;
    flex: 1;
}
.project-card-stats {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.72rem;
    color: var(--color-muted);
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}
.project-card-stat strong { color: var(--color-red); font-family: var(--font-main); font-size: 0.9rem; }

.project-cover-large {
    width: 100%;
    height: 100%;
    min-height: 220px;
    background: var(--color-bg);
    background-size: cover;
    background-position: center;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-card);
}
.project-cover-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-muted);
    font-family: var(--font-main);
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.empty-state { text-align: center; padding: 3rem 2rem; color: var(--color-muted); }
.empty-state h3 {
    font-family: var(--font-main);
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
    color: var(--color-black);
}
.empty-state p { margin-bottom: 1rem; }

/* ============================================================ PILLS */
.pill {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    font-family: var(--font-main);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    vertical-align: middle;
    margin-left: 0.25rem;
}
.pill-ok    { background: #e6f4ea; color: var(--color-green); }
.pill-warn  { background: #fff7e0; color: var(--color-amber); }
.pill-zero  { background: var(--color-red); color: var(--color-white); }
.pill-src   { background: #f0f0f0; color: var(--color-muted); }
.pill-new   { background: #e3f0fb; color: var(--color-blue); }

/* ============================================================ MODAL */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--color-white);
    border-radius: var(--border-radius);
    border-top: 3px solid var(--color-red);
    padding: 1.5rem;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-content h3 {
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
}

/* ============================================================ CHARTS */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.chart-grid > div {
    position: relative;
    height: 280px;
    border-radius: var(--border-radius);
    transition: box-shadow 0.15s;
}
.chart-grid > div:hover {
    box-shadow: 0 0 0 2px rgba(204,0,0,0.15);
}
.chart-zoom-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 10;
    width: 26px;
    height: 26px;
    border: 1px solid var(--color-border);
    background: rgba(255,255,255,0.9);
    color: var(--color-muted);
    border-radius: var(--border-radius);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.chart-zoom-btn:hover {
    background: var(--color-red);
    color: var(--color-white);
    border-color: var(--color-red);
}
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }

/* Modal fullscreen per i grafici */
.chart-fs-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 2000;
    align-items: stretch;
    justify-content: stretch;
    padding: 2rem;
}
.chart-fs-modal.show { display: flex; }
.chart-fs-content {
    background: var(--color-white);
    border-radius: var(--border-radius);
    border-top: 4px solid var(--color-red);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.chart-fs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}
.chart-fs-header h3 {
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin: 0;
}
.chart-fs-close {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 600;
}
.chart-fs-close:hover { background: var(--color-red); color: var(--color-white); border-color: var(--color-red); }
.chart-fs-body {
    flex: 1;
    padding: 1rem;
    position: relative;
    overflow: hidden;
}

/* Mappa Leaflet */
.points-map-card { padding: 0; overflow: hidden; }
.points-map { width: 100%; height: 480px; background: var(--color-bg); }
.map-attrib { font-size: 0.7rem; color: var(--color-muted); padding: 0.5rem 1rem; }
.leaflet-tooltip.point-tip {
    background: rgba(255,255,255,0.97);
    border: 1px solid var(--color-red);
    color: var(--color-black);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.env { font-size: 0.78rem; color: var(--color-muted); }

/* Gruppi (sotto-monitoraggi) */
.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem;
}
.group-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background: var(--color-white);
    text-decoration: none;
    color: var(--color-black);
    transition: all 0.15s;
}
.group-card:hover {
    border-color: var(--color-red);
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    color: var(--color-black);
}
.group-card-dot {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
}
.group-card-body { flex: 1; min-width: 0; }
.group-card-body strong {
    font-family: var(--font-main);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.group-card-desc {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.group-card-meta {
    font-size: 0.7rem;
    color: var(--color-red);
    font-family: var(--font-main);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 2px;
}

/* ============================================================ FOOTER */
.site-footer {
    background: var(--color-white);
    color: var(--color-muted);
    text-align: center;
    padding: 1.25rem 2rem;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    border-top: 1px solid var(--color-border);
    margin-top: 2rem;
}
.site-footer a { color: var(--color-red); }

/* Stampa */
@media print {
    .site-header, .site-footer, .page-actions, .btn { display: none !important; }
    .card { box-shadow: none; border: 1px solid var(--color-border); }
}
