:root {
    --bg: #fafafa;
    --bg-card: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --danger: #dc2626;
    --success: #059669;
    --warn: #b45309;
    --border: #e5e7eb;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    --sidebar-w: 220px;
    --header-h: 56px;
    --radius: 6px;
}

* { box-sizing: border-box; }

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

.app-header {
    height: var(--header-h);
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 0 20px;
    background: #111827;
    color: #fff;
}
.app-header .brand { font-weight: 700; font-size: 18px; letter-spacing: 0.5px; }
.app-header .subtitle { color: #9ca3af; font-size: 12px; }

.app-shell { display: flex; min-height: calc(100vh - var(--header-h)); }

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.sidebar-nav { list-style: none; margin: 0; padding: 12px 0; }
.sidebar-nav li a {
    display: block;
    padding: 10px 20px;
    color: var(--text);
    text-decoration: none;
}
.sidebar-nav li a:hover { background: #f3f4f6; }
.sidebar-nav li a.active { background: #eff6ff; color: var(--primary); font-weight: 600; border-left: 3px solid var(--primary); }
.sidebar-foot { padding: 14px 20px; color: var(--text-muted); font-size: 12px; }

.main { flex: 1; padding: 24px 28px; max-width: 1100px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-head .actions { display: flex; gap: 8px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 8px; }

.hint { color: var(--text-muted); font-size: 13px; margin: 4px 0 16px; }
.hint.warn { color: var(--warn); }
.empty { color: var(--text-muted); }

.flash {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.btn {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }

.grid { width: 100%; border-collapse: collapse; background: var(--bg-card); box-shadow: var(--shadow-md); border-radius: var(--radius); overflow: hidden; }
.grid th, .grid td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid th { background: #f9fafb; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }
.grid tr:last-child td { border-bottom: none; }
.row-muted { opacity: 0.55; }
.row-silent { background: #fffbeb; }
.cell-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.cell-rationale { max-width: 320px; color: var(--text-muted); }

.score { display: inline-block; min-width: 34px; text-align: center; padding: 4px 6px; border-radius: var(--radius); font-weight: 700; color: #fff; }
.score-hi { background: var(--success); }
.score-mid { background: var(--warn); }
.score-lo { background: var(--danger); }
.score-na { background: #9ca3af; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.tag-ramo { background: #e5e7eb; color: #374151; }
.tag-silent { background: #fef3c7; color: var(--warn); }
.tag-attivo { background: #ecfdf5; color: var(--success); }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 12px; padding: 12px 14px; }
legend { font-weight: 600; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

textarea { width: 100%; font-family: inherit; font-size: 14px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); resize: vertical; }
.weights { display: flex; gap: 24px; }
.weights label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.weights input { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); width: 120px; }
.rami { display: flex; flex-direction: column; gap: 12px; }
.ramo { flex-wrap: wrap; align-items: flex-end; }
.ramo input[type="text"] { width: 220px; }
.ramo-key { align-self: center; min-width: 90px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.form-actions { margin-top: 8px; }

a { color: var(--primary); }
