:root {
    --bordeaux: #9d0032;
    --bordeaux-dark: #7a0027;
    --ink: #1d1d1f;
    --muted: #6b7077;
    --line: #e4e2de;
    --bg: #f7f6f4;
    --white: #ffffff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
}

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

/* ---- Topbar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    padding: 0 24px;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.brand img { height: 30px; display: block; }
.topnav { display: flex; align-items: center; gap: 4px; flex: 1; }
.topnav-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: 0;
    font: inherit;
    color: var(--ink);
    padding: 8px 12px;
    border-radius: 7px;
    cursor: pointer;
    white-space: nowrap;
}
.topnav-item:hover { background: #f1efec; text-decoration: none; }
.topnav-item.active { color: var(--bordeaux); font-weight: 600; }
.topnav-item.soon { color: #b3b0ab; cursor: default; }
.topnav-item.soon:hover { background: none; }
.soon-dot { color: var(--bordeaux); }
.caret { font-size: 10px; color: var(--muted); }

.topnav-dropdown { position: relative; }
.topnav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 9px;
    box-shadow: 0 12px 30px rgba(0,0,0,.10);
    padding: 6px;
    z-index: 60;
}
.topnav-dropdown:hover .topnav-menu { display: block; }
.topnav-menu a {
    display: block;
    color: var(--ink);
    padding: 8px 12px;
    border-radius: 6px;
}
.topnav-menu a:hover { background: #f1efec; text-decoration: none; }

.topbar-user { display: flex; align-items: center; gap: 14px; }
.user-name { color: var(--muted); font-size: 14px; }
.btn-logout {
    border: 1px solid var(--line);
    padding: 6px 14px;
    border-radius: 7px;
    color: var(--ink);
}
.btn-logout:hover { background: #f1efec; text-decoration: none; }

/* ---- Container ---- */
.container { max-width: none; margin: 0; padding: 28px 32px; }
h1 { font-size: 26px; margin: 0 0 4px; }
.muted { color: var(--muted); }

/* ---- Cards (dashboard) ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-top: 24px; }
.card {
    display: block;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    color: var(--ink);
}
a.card:hover { border-color: var(--bordeaux); box-shadow: 0 6px 18px rgba(157,0,50,.08); text-decoration: none; }
.card h3 { margin: 0 0 6px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card.disabled { opacity: .55; }

/* ---- Search bar ---- */
.search-bar { display: flex; gap: 10px; margin: 20px 0 24px; flex-wrap: wrap; }
.search-bar input[type=text] { flex: 1; min-width: 240px; }
input, select {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    color: var(--ink);
}
input:focus, select:focus { outline: 2px solid rgba(157,0,50,.25); border-color: var(--bordeaux); }

.btn-primary {
    background: var(--bordeaux);
    color: #fff;
    border: 0;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:hover { background: var(--bordeaux-dark); }
.btn-oris { display: inline-block; text-decoration: none; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--white); width: max-content; max-width: 100%; margin: 0 auto; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.data thead th { background: #faf9f7; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #faf6f7; }

/* ---- Alert ---- */
.alert {
    background: #fdecef;
    border: 1px solid #f3c0cd;
    color: var(--bordeaux-dark);
    padding: 12px 16px;
    border-radius: 9px;
    margin-bottom: 18px;
}

/* ---- Login ---- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 16px 40px rgba(0,0,0,.06);
    text-align: center;
}
.login-logo { height: 34px; margin-bottom: 6px; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card .btn-primary { margin-top: 6px; }

/* ---- Icon button (ingranaggio pannello) ---- */
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px;
    color: var(--ink); background: var(--white);
}
.btn-icon:hover { background: #f1efec; color: var(--bordeaux); text-decoration: none; }

.alert.ok { background: #eef7ee; border-color: #c3e3c3; color: #246b24; }
.small { font-size: 12px; }

/* ---- Pannello di Controllo ---- */
.admin-head { display: flex; align-items: baseline; gap: 20px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-tabs { display: flex; gap: 6px; }
.admin-tabs a { padding: 7px 14px; border-radius: 8px; color: var(--ink); }
.admin-tabs a:hover { background: #f1efec; text-decoration: none; }
.admin-tabs a.active { background: var(--bordeaux); color: #fff; }
.admin-grid { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
@media (max-width: 800px) { .admin-grid { grid-template-columns: 1fr; } }
.admin-form { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.admin-form h3 { margin: 0 0 4px; }
.admin-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.admin-form label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.admin-form input[type=text] { width: 100%; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.perms { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.perms legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.row-actions { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.row-actions form { display: inline; }
button.link { background: none; border: 0; color: var(--bordeaux); cursor: pointer; font: inherit; padding: 0; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: #b3261e; }

/* ---- Calendario ---- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-datef { margin: 0; }
.cal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: start; }
.cal-col { background: var(--white); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cal-col-head { background: #faf9f7; padding: 10px 12px; font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.cal-appt { margin: 8px; padding: 8px 10px; border: 1px solid var(--line); border-left: 3px solid var(--bordeaux); border-radius: 8px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.cal-appt.is-block { opacity: .6; border-left-color: #c9c6c1; }
.cal-time { font-weight: 600; font-size: 12px; }
.cal-pat { font-weight: 500; }
.cal-type { font-size: 11px; opacity: .85; }

.badge-warn { display: inline-block; background: #fdecef; color: var(--bordeaux-dark); border: 1px solid #f3c0cd; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }

/* ---- Scheda paziente ---- */
.paz-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; max-width: 940px; margin: 0 auto; }
.paz-card { background: var(--white); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.paz-card h3 { margin: 0 0 14px; }
.paz-dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; font-size: 14px; }
.paz-dl dt { color: var(--muted); }
.paz-dl dd { margin: 0; }
.paz-card form { display: flex; flex-direction: column; gap: 12px; }
.paz-card form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.paz-card form input, .paz-card form textarea { width: 100%; }
.paz-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; color: var(--ink); }

.badge-ok { display: inline-block; background: #eef7ee; color: #246b24; border: 1px solid #c3e3c3; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.badge-warn + .badge-warn, .badge-warn + .badge-ok, .badge-ok + .badge-ok, .badge-ok + .badge-warn { margin-left: 4px; }
td.annot { white-space: nowrap; }

/* ---- Calendario MyAgenda (griglia oraria) ---- */
.cal2 { display: flex; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.cal2-gutter { flex: 0 0 54px; border-right: 1px solid var(--line); }
.cal2-col { flex: 1 0 150px; min-width: 150px; border-right: 1px solid var(--line); }
.cal2-col:last-child { border-right: 0; }
.cal2-colhead { height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 12px; border-bottom: 1px solid var(--line); padding: 0 6px; text-align: center; background: #faf9f7; position: sticky; top: 0; overflow: hidden; }
.cal2-opname { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal2-prod { font-size: 10px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.cal2-body { position: relative; }
.cal2-lines { background-image: linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px); background-repeat: repeat-y; }
.cal2-hour { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-50%); }
.cal2-appt { position: absolute; left: 3px; right: 3px; border-radius: 6px; border: 1px solid var(--line); border-left: 3px solid var(--bordeaux); padding: 1px 5px; font-size: 11px; line-height: 1.2; overflow: hidden; box-sizing: border-box; background: var(--white); cursor: default; }
.cal2-appt.is-block { opacity: .55; border-left-color: #c9c6c1; }
.cal2-time { font-weight: 600; margin-right: 4px; }

.scoperto-box { display: inline-flex; align-items: baseline; gap: 8px; background: #fdecef; border: 1px solid #f3c0cd; color: var(--bordeaux-dark); padding: 12px 18px; border-radius: 10px; margin: 4px 0 20px; }
.scoperto-val { font-size: 20px; font-weight: 700; }

table.data tbody tr.row-closed { background: #fdecef; }
table.data tbody tr.row-closed:hover { background: #fbe0e6; }
.badge-closed { display: inline-block; background: var(--bordeaux); color: #fff; border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; }

.giorni-field { display: flex; flex-direction: column; gap: 6px; }
.giorni-label { font-size: 13px; color: var(--muted); }
.giorni-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.giorno-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; font-size: 13px; cursor: pointer; user-select: none; }
.giorno-chip input { margin: 0; }
.giorno-chip:has(input:checked) { background: var(--bordeaux); color: #fff; border-color: var(--bordeaux); }

.cal2-imp { font-weight: 700; }
.cal2-daf { font-weight: 700; font-style: italic; opacity: 0.85; }
.disp-grid { border-collapse: collapse; width: 100%; }
.disp-grid th, .disp-grid td { padding: 6px 10px; text-align: center; border: 1px solid #e6e0d8; }
.disp-grid thead th { font-weight: 600; color: var(--muted); }
.disp-grid tbody th { text-align: left; font-weight: 600; }
.disp-grid .disp-yes { background: #e7f3e8; color: #1f7a32; font-weight: 700; }
.disp-grid .disp-no { color: #c0b9ae; }
.disp-edit { border-collapse: collapse; }
.disp-edit th, .disp-edit td { padding: 4px 14px; text-align: center; border: 1px solid #e6e0d8; }
.disp-edit tbody th { text-align: left; font-weight: 600; }
.disp-edit thead th { font-weight: 600; color: var(--muted); }

/* ---- Cruscotto ---- */
.crus-kpi { display: flex; gap: 16px; margin: 18px 0; flex-wrap: wrap; }
.kpi-card { flex: 1; min-width: 220px; padding: 18px 22px; border-radius: 14px; color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.kpi-prod { background: linear-gradient(135deg, #9d0032, #c41c4e); }
.kpi-fatt { background: linear-gradient(135deg, #147a5a, #1ea579); }
.kpi-label { display: block; font-size: 13px; opacity: .92; }
.kpi-val { display: block; font-size: 30px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.crus-chart { background: #fff; border: 1px solid #ece6de; border-radius: 14px; padding: 18px; margin-bottom: 22px; }
.crus-table { border-collapse: collapse; width: 100%; max-width: 560px; }
.crus-table th, .crus-table td { padding: 7px 14px; border-bottom: 1px solid #f0ece6; }
.crus-table thead th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 2px solid #e6e0d8; }
.crus-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.crus-table tbody tr:nth-child(even) { background: #faf8f5; }
.crus-table tfoot th { border-top: 2px solid #e6e0d8; font-weight: 700; }

/* ---- Calendario MyAgenda refinement ---- */
.cal2-col { flex: 1 0 120px; min-width: 120px; }
.cal2-appt { border: 1px solid rgba(0,0,0,.14); border-left-width: 1px; }
.cal2-ophead { display: flex; align-items: center; justify-content: center; gap: 4px; max-width: 100%; }
.cal2-avatar { width: 13px; height: 13px; flex: 0 0 auto; opacity: .55; }

/* tabelle: piena larghezza, colonne allineate (override del centrato) */
.table-wrap { width: 100%; max-width: 100%; margin: 0; }

.cell-note { color: var(--ink); max-width: 340px; white-space: normal; font-size: 13px; }

/* header tabelle sticky (sempre visibile nello scroll, sotto la topbar 60px) */
.table-wrap { overflow: visible; }
table.data thead th { position: sticky; top: 60px; z-index: 5; }

.ins-filter { width: 100%; max-width: 420px; margin: 0 0 16px; }
