/* DRAGON Executive CRM — tema scuro, mobile-first. */
:root {
  --bg: #0c0d10;
  --bg-2: #121419;
  --panel: #16191f;
  --panel-2: #1c2028;
  --line: #262b35;
  --line-2: #323947;
  --text: #e9ebf0;
  --muted: #8a93a6;
  --faint: #5d6576;
  --ember: #ff6b3d;
  --ember-2: #ff8f66;
  --ember-bg: rgba(255, 107, 61, 0.12);
  --gold: #e8b85a;
  --ok: #4cc38a;
  --warn: #f0b429;
  --bad: #ff5d6c;
  --info: #6aa6ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--ember-2); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.error { color: var(--bad); min-height: 1.4em; font-size: 0.9rem; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- marchio ---------- */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: 0.18em; font-size: 0.9rem; }
.brand small { font-weight: 500; letter-spacing: 0.04em; color: var(--muted); font-size: 0.8rem; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; display: inline-block;
  background: linear-gradient(135deg, var(--ember) 0%, #c2410c 100%);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.brand-lg { font-size: 1.2rem; flex-direction: column; gap: 6px; margin-bottom: 26px; }
.brand-lg .brand-mark { width: 40px; height: 40px; }

/* ---------- controlli ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; color: var(--muted); font-weight: 550; }
input, select, textarea {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 0.95rem; width: 100%; min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ember); outline: none; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 450; }
.check input { width: 18px; min-height: 18px; accent-color: var(--ember); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 999px;
  padding: 9px 16px; min-height: 40px; cursor: pointer; font-weight: 600; font-size: 0.9rem; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn-primary { background: var(--ember); border-color: var(--ember); color: #1a0d07; }
.btn-primary:hover { background: var(--ember-2); border-color: var(--ember-2); }
.btn-ghost { background: transparent; }
.btn-ok { background: rgba(76, 195, 138, 0.14); border-color: rgba(76, 195, 138, 0.5); color: var(--ok); }
.btn-bad { background: rgba(255, 93, 108, 0.1); border-color: rgba(255, 93, 108, 0.45); color: var(--bad); }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: progress; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); display: grid; place-items: center; cursor: pointer;
}
.icon-btn.user { font-weight: 700; font-size: 0.85rem; color: var(--ember-2); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ember); color: #1a0d07;
  font-size: 0.7rem; font-weight: 800; display: inline-grid; place-items: center;
}
.icon-btn .badge { position: absolute; top: -4px; right: -4px; }

/* ---------- accesso ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(255, 107, 61, 0.14), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 24px; box-shadow: var(--shadow); text-align: left; }
.login-card .brand-lg { align-items: center; text-align: center; }

/* ---------- struttura ---------- */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  align-items: center; padding: 10px 16px; background: rgba(12, 13, 16, 0.88);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; gap: 8px; }
.command {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 4px 4px 4px 14px; min-width: 0;
}
.command:focus-within { border-color: var(--ember); box-shadow: 0 0 0 4px var(--ember-bg); }
.command-label { font-size: 0.68rem; font-weight: 800; letter-spacing: 0.16em; color: var(--ember); }
.command input { border: 0; background: transparent; min-height: 34px; padding: 4px 0; }
.command input:focus { border: 0; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(6, 1fr);
  background: rgba(18, 20, 25, 0.96); border-top: 1px solid var(--line); backdrop-filter: blur(12px);
}
.nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 0.68rem; font-weight: 600; }
.nav a.active { color: var(--ember); }
.nav a .badge { position: absolute; top: 6px; left: calc(50% + 6px); }

.view { padding: 18px 16px 32px; max-width: 1280px; margin: 0 auto; outline: none; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ember); font-weight: 700; }

@media (max-width: 719px) {
  .topbar { grid-template-columns: auto 1fr; }
  .topbar .brand span:not(.brand-mark) { display: none; }
  .command { grid-column: 1 / -1; order: 3; }
  .command-label { display: none; }
}
@media (min-width: 1000px) {
  .shell { padding-bottom: 0; padding-left: 220px; }
  .topbar { grid-template-columns: 1fr auto; padding-left: 24px; }
  .topbar .brand { display: none; }
  .nav { top: 0; bottom: 0; right: auto; width: 220px; height: auto; grid-template-columns: 1fr;
    grid-auto-rows: 48px; align-content: start; padding: 72px 12px 12px; border-top: 0; border-right: 1px solid var(--line); }
  .nav::before { content: "DRAGON"; position: absolute; top: 22px; left: 26px; font-weight: 800; letter-spacing: 0.2em; font-size: 0.9rem; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; border-radius: 10px; font-size: 0.9rem; }
  .nav a.active { background: var(--ember-bg); }
  .nav a .badge { position: static; margin-left: auto; }
  .view { padding: 26px 28px 40px; }
}

/* ---------- card e griglie ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.span-2 { grid-column: 1 / -1; }
@media (min-width: 1200px) { .span-2 { grid-column: span 2; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.card-head .count { margin-left: auto; font-size: 0.8rem; color: var(--faint); font-weight: 700; }
.empty { color: var(--faint); font-size: 0.9rem; padding: 6px 0; }

.hero {
  background: linear-gradient(140deg, rgba(255, 107, 61, 0.16), rgba(255, 107, 61, 0.02) 55%), var(--panel);
  border: 1px solid rgba(255, 107, 61, 0.28);
}
.hero p.summary { font-size: 1.02rem; line-height: 1.6; }
.origin { font-size: 0.72rem; color: var(--faint); margin-top: 10px; }

/* elenchi */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: flex-start; min-width: 0; }
.item:first-child { border-top: 0; padding-top: 2px; }
.item-main { min-width: 0; flex: 1; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 6px 10px; flex-wrap: wrap; margin-top: 2px; }
.item.clickable { cursor: pointer; }
.item.clickable:hover .item-title { color: var(--ember-2); }
.time { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); min-width: 46px; padding-top: 2px; }
.rank { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800;
  background: var(--ember-bg); color: var(--ember); flex: none; font-size: 0.85rem; }

.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 8px;
  font-size: 0.72rem; font-weight: 700; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.chip.critical, .chip.bad { color: var(--bad); border-color: rgba(255, 93, 108, 0.45); }
.chip.high, .chip.warn { color: var(--warn); border-color: rgba(240, 180, 41, 0.45); }
.chip.ok { color: var(--ok); border-color: rgba(76, 195, 138, 0.45); }
.chip.info { color: var(--info); border-color: rgba(106, 166, 255, 0.45); }
.chip.gold { color: var(--gold); border-color: rgba(232, 184, 90, 0.45); }
.chip.ember { color: var(--ember); border-color: rgba(255, 107, 61, 0.45); }

progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 3px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 3px; }
progress::-webkit-progress-value { background: var(--ember); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--ember); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tabs button { border: 1px solid var(--line-2); background: transparent; border-radius: 999px; padding: 6px 14px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.day { margin-bottom: 18px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.day-head h3 { text-transform: capitalize; }
.event { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); margin-bottom: 8px; border-left: 3px solid var(--info); }
.event.focus { border-left-color: var(--gold); }
.event.personal { border-left-color: var(--ok); }
.event.conflict { border-color: rgba(255, 93, 108, 0.5); border-left-color: var(--bad); }

.kpi-empty { border: 1px dashed var(--line-2); border-radius: var(--radius-sm); padding: 14px; color: var(--muted); font-size: 0.88rem; }

/* risultati HERMES */
.result-section { margin-top: 16px; }
.result-section h3 { font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.proposal { border: 1px solid rgba(255, 107, 61, 0.35); background: var(--ember-bg); border-radius: var(--radius-sm); padding: 12px; margin-top: 8px; }
.proposal p { font-size: 0.86rem; color: var(--muted); margin: 4px 0 10px; }
.draft { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; font-size: 0.9rem; margin-top: 6px; }
.steps { font-family: var(--mono); font-size: 0.75rem; color: var(--faint); }

/* finestra di dialogo */
.dialog { width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line-2);
  border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(5, 6, 8, 0.7); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 1; }
.dialog-head h2 { flex: 1; }
.dialog-body { padding: 16px 18px 20px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }

.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--line) 0%, var(--line-2) 50%, var(--line) 100%);
  background-size: 200% 100%; animation: sk 1.2s infinite linear; margin: 8px 0; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .toast { transition: none; } }

table.audit { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.audit td, table.audit th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap { overflow-x: auto; }
