/* AIristandros — interfaccia editor + vista cliente */

:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --panel-2: #fbfbfa;
  --ink: #1c1c1a;
  --ink-2: #56564f;
  --ink-3: #8a8a80;
  --line: #e2e2dc;
  --line-2: #cfcfc6;
  --accent: #b8562f;
  --accent-soft: #f4e6df;
  --ok: #3f7a4a;
  --warn: #a8791b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17171a;
    --panel: #1f1f23;
    --panel-2: #26262b;
    --ink: #ececea;
    --ink-2: #b3b3ad;
    --ink-3: #83837c;
    --line: #34343a;
    --line-2: #44444c;
    --accent: #e08a5f;
    --accent-soft: #3a2a22;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

.muted { color: var(--ink-3); }
.error { color: #b1372f; }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.right { margin-left: auto; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hidden { display: none !important; }

/* ---------- login ---------- */

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; width: min(340px, 92vw); display: flex; flex-direction: column; gap: 10px;
}
.brand { font-size: 22px; font-weight: 640; letter-spacing: -0.02em; }
.brand-ai { color: var(--accent); }

/* ---------- controlli ---------- */

input, select, textarea, button { font: inherit; color: inherit; }

input[type="text"], input[type="password"], input[type="url"], input[type="email"], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
textarea { resize: vertical; min-height: 64px; }

.btn {
  background: var(--panel); border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger:hover { border-color: #b1372f; color: #b1372f; }
.btn.icon { padding: 4px 8px; line-height: 1; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 9px;
  font-size: 11.5px; color: var(--ink-2); background: var(--panel-2);
}
.pill.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.pill.warn { border-color: var(--warn); color: var(--warn); }

/* ---------- layout app ---------- */

.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.side {
  border-right: 1px solid var(--line); background: var(--panel);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .brand { font-size: 17px; padding: 0 6px; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px;
  color: var(--ink-2); text-decoration: none; cursor: pointer;
}
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--ink-3); }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 0 10px; margin-top: 6px; }

.main { padding: 22px 26px 80px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 21px; margin: 0 0 2px; letter-spacing: -0.02em; }
.page-head p { margin: 0; color: var(--ink-3); font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card > h2 { font-size: 14px; margin: 0 0 12px; letter-spacing: -0.01em; }
.card.flat { padding: 0; overflow: hidden; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 560; padding: 8px 10px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
table.tbl td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.tight { width: 1%; white-space: nowrap; }

/* ---------- lista progetti ---------- */

.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.proj {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 6px; cursor: pointer;
}
.proj:hover { border-color: var(--line-2); }
.proj h3 { margin: 0; font-size: 15px; }
.proj .meta { font-size: 12px; color: var(--ink-3); }
.proj .acts { display: flex; gap: 6px; margin-top: 6px; }

/* ---------- pagine / fasce ---------- */

.split { display: grid; grid-template-columns: 236px 1fr; gap: 16px; align-items: start; }
.plist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.plist .it {
  padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; gap: 6px; align-items: center;
}
.plist .it:last-child { border-bottom: 0; }
.plist .it:hover { background: var(--panel-2); }
.plist .it.active { background: var(--accent-soft); color: var(--accent); font-weight: 560; }
.plist .it .k { font-size: 10px; text-transform: uppercase; color: var(--ink-3); letter-spacing: .05em; }

.section {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); margin-bottom: 10px;
}
.section > .sh {
  display: flex; gap: 8px; align-items: center; padding: 8px 10px;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}
.section > .sh .num {
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  min-width: 20px; text-align: right;
}
.section > .sb { padding: 10px; }
.comp-row { display: grid; grid-template-columns: 130px 1fr 1fr 40px; gap: 6px; margin-bottom: 5px; align-items: center; }

/* ---------- menu ad albero ---------- */

.mrow { display: grid; grid-template-columns: 1fr 1fr 120px 1fr auto; gap: 6px; align-items: center; margin-bottom: 5px; }
.mrow.lvl1 { padding-left: 26px; }
.mrow.lvl2 { padding-left: 52px; }

/* ---------- commenti ---------- */

.cmt { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); margin-bottom: 8px; }
.cmt.done { opacity: .55; }
.cmt .who { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.cmt .body { white-space: pre-wrap; }

/* ---------- toast ---------- */

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 50;
}
#toast.on { opacity: 1; }

/* ---------- vista pubblica cliente ---------- */

.pub { max-width: 940px; margin: 0 auto; padding: 32px 20px 90px; }
.pub-head { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 26px; }
.pub-head h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.025em; }
.pub-toc { position: sticky; top: 0; background: var(--bg); padding: 10px 0; border-bottom: 1px solid var(--line); z-index: 10; }
.pub-toc a { margin-right: 14px; font-size: 13px; text-decoration: none; }
.pub h2 { font-size: 18px; margin: 34px 0 10px; letter-spacing: -0.02em; }
.pub h3 { font-size: 15px; margin: 26px 0 8px; }
.wf {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel); margin-bottom: 22px;
}
.wf-band { border-bottom: 1px dashed var(--line-2); padding: 12px 14px; position: relative; }
.wf-band:last-child { border-bottom: 0; }
.wf-band .tag {
  font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3);
  display: block; margin-bottom: 5px;
}
.wf-band .t { font-weight: 560; }
.wf-band .n { color: var(--ink-3); font-size: 13px; }
.wf-band .cs { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.wf-band .c {
  border: 1px dashed var(--line-2); border-radius: 6px; padding: 2px 8px;
  font-size: 12px; color: var(--ink-2); background: var(--panel-2);
}
.cbtn { position: absolute; top: 8px; right: 8px; opacity: 0; transition: opacity .15s; }
.wf-band:hover .cbtn { opacity: 1; }

.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 22px; border-left: 1px solid var(--line); margin: 4px 0 4px 6px; }
.tree li { padding: 3px 0; }
.tree .lbl { font-weight: 560; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink);
  padding: 18px; width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.35); }

/* ---------- stampa / PDF della vista cliente ---------- */

@media print {
  :root { --bg: #fff; --panel: #fff; --panel-2: #fff; --ink: #000; --ink-2: #333; --ink-3: #666; --line: #ccc; --line-2: #999; }
  body { background: #fff; font-size: 10.5pt; }
  .pub { max-width: none; padding: 0; }
  .pub-toc, .cbtn, .btn, dialog, #toast, .card .stack { display: none !important; }
  .pub h2 { page-break-after: avoid; margin-top: 22pt; }
  .pub h3 { page-break-after: avoid; }
  .wf, .cmt, table.tbl { page-break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .split, .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .comp-row, .mrow { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
