:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --red: #b91c1c;
  --green: #15803d;
  --amber: #b45309;
  --radius: 12px;
}
* { 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: 15px; line-height: 1.5; }
a { color: var(--blue); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Bottoni */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font: 600 14px/1.2 inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { background: #991b1b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #0f172a, #1e3a8a); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .5); }
.login-sub { margin: 4px 0 24px; color: var(--muted); }
.login-card .btn { margin-top: 20px; padding: 12px; }
.error-text, .err-text { color: var(--red); }
.login .error-text { margin: 14px 0 0; text-align: center; }

/* Form */
label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; color: #334155; }
input, textarea { width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; }
input:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
textarea { resize: vertical; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 18px; cursor: pointer; }
.switch input { width: 18px; height: 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 10px 24px; background: #0f172a; color: #fff; }
.topbar .brand { color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar .muted { color: #94a3b8; }
.topbar .btn.ghost { color: #e2e8f0; border-color: #334155; }
.topbar .btn.ghost:hover { background: #1e293b; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-size: 18px; text-decoration: none; color: var(--blue); }
.brand.big { font-size: 26px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--blue); color: #fff; font-size: 15px; }
.brand.big .logo { width: 36px; height: 36px; font-size: 20px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; background: #1e3a8a; color: #bfdbfe; margin-left: 6px; }
.doc .tag, .grid .tag, h1 .tag { background: #eef2ff; color: var(--blue); }
.container { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }
.breadcrumb { font-size: 14px; color: var(--muted); margin-bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.breadcrumb a { text-decoration: none; }
.breadcrumb .sep { color: #cbd5e1; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head.section { margin-top: 32px; }
h1 { font-size: 26px; margin: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 18px; margin: 0 0 10px; }
h2.section { margin: 32px 0 14px; display: flex; align-items: center; gap: 10px; }
h3 { font-size: 16px; margin: 0; }
.h-code { font-size: 20px; background: #e2e8f0; padding: 2px 8px; border-radius: 6px; }
.count { font-size: 13px; font-weight: 700; background: #e2e8f0; color: #334155; padding: 2px 10px; border-radius: 999px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions.end { align-items: center; justify-content: flex-end; margin-left: auto; gap: 14px; }
.page-head h2 { margin: 0; }
.search { width: 280px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.error-card { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols .card { margin: 0; }
.cols .card h2 { margin-bottom: 4px; }

/* Messaggi */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--green); }
.flash.err { background: #fef2f2; border: 1px solid #fecaca; color: var(--red); }
.loading { padding: 40px 0; text-align: center; }

/* Griglie */
.table-card { padding: 0; overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8fafc; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.grid td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tr.link { cursor: pointer; }
.grid tr.link:hover td { background: #f8fafc; }
.grid .empty { text-align: center; color: var(--muted); padding: 30px; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { text-align: center; padding: 10px; }
.yes { color: var(--green); font-weight: 700; }
.no { color: var(--muted); }

/* Badge */
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.green { background: #dcfce7; color: var(--green); }
.badge.red { background: #fee2e2; color: var(--red); }
.badge.blue { background: #dbeafe; color: var(--blue); }
.badge.amber { background: #fef3c7; color: var(--amber); }
.badge.grey { background: #e2e8f0; color: #475569; }
h1 .badge { font-size: 13px; }

/* Chiave-valore */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 12px 0 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.kv.two { grid-template-columns: 170px 1fr; }
.hash { font-size: 12px; word-break: break-all; }
pre.sender { white-space: pre-wrap; word-break: break-word; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 6px 0 0; font: 14px/1.5 inherit; }
.secret-label { font-size: 13px; font-weight: 600; color: #334155; margin: 16px 0 6px; }
.secret { display: flex; gap: 10px; align-items: center; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.secret code { flex: 1; word-break: break-all; font-size: 13px; }
.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 12px; border-radius: 8px; }

/* Documenti */
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.preview { margin-top: 16px; }
.preview iframe { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 8px; background: #e2e8f0; }

/* Finestra di dialogo */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100% - 32px)); box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .45); }
dialog::backdrop { background: rgba(15, 23, 42, .55); }
dialog form { padding: 24px; }
dialog h3 { font-size: 18px; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; }
  .kv, .kv.two { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .search { width: 100%; }
  .actions { width: 100%; }
  .container { padding: 16px; }
  .topbar { padding: 10px 16px; }
  #whoami { display: none; }
}
