:root {
  --bg: #f4f6fb;
  --surface: #fff;
  --border: #e5e9f2;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #4e73df;
  --primary-light: #eef2ff;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #1e2a3a; flex-shrink: 0; display: flex; flex-direction: column; padding: 1.2rem 0; }
.sidebar-brand { padding: .5rem 1.2rem 1.2rem; color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: -.3px; border-bottom: 1px solid #2d3f52; margin-bottom: .8rem; }
.sidebar-brand span { opacity: .6; font-size: .72rem; font-weight: 400; display: block; margin-top: .1rem; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem 1.2rem; color: #9db5cc; text-decoration: none; font-size: .85rem; border-radius: 0; transition: background .12s, color .12s; }
.sidebar nav a:hover, .sidebar nav a.active { background: #2d3f52; color: #fff; }
.sidebar nav a .icon { font-size: 1rem; opacity: .8; }
.sidebar-section { color: #4d6478; font-size: .68rem; font-weight: 600; letter-spacing: .08em; padding: .8rem 1.2rem .3rem; text-transform: uppercase; }
.main { flex: 1; overflow-y: auto; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: .8rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 1rem; font-weight: 600; }
.page { padding: 1.5rem; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem 1.4rem; }
.card + .card { margin-top: 1rem; }
.card-title { font-size: .82rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 1rem; }

/* KPI strip */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.2rem; }
.kpi-val { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.kpi-lbl { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }

/* App grid */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.app-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; cursor: pointer; text-decoration: none; color: inherit; border: 2px solid transparent; transition: border-color .15s, box-shadow .15s; display: block; }
.app-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); border-color: var(--primary); }
.app-card-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-dot.attiva    { background: #22c55e; }
.status-dot.manutenzione { background: #f59e0b; }
.status-dot.sviluppo  { background: #3b82f6; }
.status-dot.disattiva { background: #9ca3af; }
.app-name { font-weight: 700; font-size: .9rem; }
.app-meta { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.pending-badge { display: inline-block; background: #fee2e2; color: #dc2626; border-radius: 20px; padding: .1rem .5rem; font-size: .72rem; font-weight: 600; margin-top: .4rem; }
.pending-badge.zero { background: #f0fdf4; color: #16a34a; }
.health-badge { font-size: .7rem; font-weight: 600; padding: .1rem .4rem; border-radius: 20px; margin-left: auto; flex-shrink: 0; }
.health-badge.green  { background: #f0fdf4; color: #16a34a; }
.health-badge.red    { background: #fee2e2; color: #dc2626; }
.health-badge.orange { background: #fff7ed; color: #ea580c; }
.health-badge.gray   { background: #f3f4f6; color: #9ca3af; }

/* Activity feed */
.activity-list { display: flex; flex-direction: column; gap: .6rem; }
.activity-item { display: flex; gap: .75rem; align-items: flex-start; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: .35rem; flex-shrink: 0; }
.activity-body { flex: 1; }
.activity-app { font-weight: 600; font-size: .82rem; }
.activity-text { font-size: .82rem; color: var(--text-muted); }
.activity-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }

/* Instructions list */
.instr-list { display: flex; flex-direction: column; gap: .7rem; }
.instr-item { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); padding: .9rem 1.1rem; border-left: 4px solid #e5e9f2; cursor: pointer; text-decoration: none; color: inherit; display: block; transition: box-shadow .12s; }
.instr-item:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.instr-item.critica { border-left-color: #dc2626; }
.instr-item.alta    { border-left-color: #f59e0b; }
.instr-item.media   { border-left-color: #3b82f6; }
.instr-item.bassa   { border-left-color: #9ca3af; }
.instr-header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .3rem; }
.instr-text { font-size: .85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.instr-footer { display: flex; gap: .5rem; margin-top: .4rem; align-items: center; }
.instr-meta { font-size: .72rem; color: var(--text-muted); }

/* Badges */
.badge { display: inline-block; border-radius: 20px; padding: .15rem .55rem; font-size: .72rem; font-weight: 600; }
.badge-prio-critica { background: #fee2e2; color: #dc2626; }
.badge-prio-alta    { background: #fef3c7; color: #b45309; }
.badge-prio-media   { background: #dbeafe; color: #1d4ed8; }
.badge-prio-bassa   { background: #f3f4f6; color: #6b7280; }
.badge-stato-pending     { background: #fef3c7; color: #b45309; }
.badge-stato-in_progress { background: #dbeafe; color: #1d4ed8; }
.badge-stato-done        { background: #dcfce7; color: #16a34a; }
.badge-stato-rejected    { background: #f3f4f6; color: #6b7280; }
.badge-stato-needs_info  { background: #f3e8ff; color: #7c3aed; }
.badge-tipo { background: #f0f4ff; color: #4e73df; }
.badge-app  { background: #f3f4f6; color: #374151; }

/* Detail page */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }
.detail-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .3rem; }
.detail-value { font-size: .9rem; }
.detail-box { padding: 1rem; background: #f8fafc; border-radius: 8px; border: 1px solid var(--border); font-size: .88rem; line-height: 1.6; }
.meta-row { display: flex; justify-content: space-between; padding: .45rem 0; border-bottom: 1px solid var(--border); font-size: .84rem; }
.meta-row:last-child { border-bottom: none; }
.meta-key { color: var(--text-muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .3rem; padding: .45rem .9rem; border-radius: 8px; font-size: .82rem; font-weight: 500; cursor: pointer; border: 1px solid transparent; text-decoration: none; transition: opacity .15s; }
.btn:hover { opacity: .85; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-success   { background: #22c55e; color: #fff; }
.btn-warning   { background: #f59e0b; color: #fff; }
.btn-danger    { background: #ef4444; color: #fff; }
.btn-secondary { background: #f3f4f6; color: #374151; border-color: var(--border); }
.btn-sm { padding: .3rem .65rem; font-size: .76rem; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-control { width: 100%; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 8px; font-size: .85rem; background: var(--surface); color: var(--text); outline: none; }
.form-control:focus { border-color: var(--primary); }
textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { cursor: pointer; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 8px 40px rgba(0,0,0,.18); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 1.5rem; }
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.2rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; border-top: 1px solid var(--border); padding-top: 1rem; }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.2rem; }
.tab { padding: .55rem 1rem; font-size: .84rem; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; color: var(--text-muted); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #1e2a3a; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; font-size: .83rem; box-shadow: 0 4px 16px rgba(0,0,0,.2); animation: slideIn .2s ease; }
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Utils */
.flex { display: flex; } .gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8rem; }
.fw-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.section-title { font-size: .95rem; font-weight: 700; margin-bottom: .8rem; }
.breadcrumb { font-size: .8rem; color: var(--text-muted); margin-bottom: .8rem; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
