:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #f0eee9; --text: #1d2228; --muted: #6b7280;
  --border: #e3e0d9; --accent: #1f3a5f; --accent-text: #ffffff; --ai: #eef3f9; --ai-border: #c9d8ea;
  --ok: #2f7d4f; --warn: #a15c07; --err: #b42318; --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c; --surface: #1d2126; --surface-2: #252a30; --text: #e7e9ec; --muted: #9aa3ad;
    --border: #30363d; --accent: #7fa7d9; --accent-text: #0f1418; --ai: #1c2632; --ai-border: #2d4056;
    --ok: #5fbf85; --warn: #e0a24a; --err: #f07167;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 8px 0 4px; } h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); } .err { color: var(--err); margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; } .btn.ghost { border-color: transparent; background: none; }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.badge { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); margin-left: 6px; }
.badge.prod { display: none; } .badge.staging { background: var(--warn); color: #fff; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; text-align: center; padding: 28px; }

.app { display: grid; grid-template-rows: auto auto 1fr; height: 100%; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { font-size: 12px; color: var(--muted); }
main { overflow: hidden; min-height: 0; }
.tab { height: 100%; overflow-y: auto; padding: 16px; max-width: 1200px; margin: 0 auto; }

.chat-tab { display: flex; flex-direction: column; overflow: hidden; max-width: 860px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.msg.ai { background: var(--ai); border-color: var(--ai-border); }
.msg.system, .msg.release { align-self: center; max-width: 95%; background: none; border: 0; color: var(--muted);
  font-size: 13px; text-align: center; padding: 2px 8px; }
.msg.release { color: var(--warn); font-weight: 600; }
.msg .meta { font-size: 12px; opacity: .75; margin-bottom: 3px; }
.typing { font-size: 13px; color: var(--muted); padding: 4px 2px; }
.chat-form { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.chat-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.check input { width: auto; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.col { display: grid; gap: 12px; align-content: start; }
.form { display: grid; gap: 8px; } .form.row { grid-template-columns: 1fr 160px 150px auto; margin-bottom: 16px; }
.list { display: grid; gap: 8px; align-content: start; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  cursor: pointer; display: grid; gap: 4px; }
.item.sel { outline: 2px solid var(--accent); }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-title { font-weight: 600; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.approvata, .pill.in_produzione { background: #e3f1e8; color: var(--ok); }
.pill.in_sviluppo, .pill.in_verifica, .pill.da_approvare { background: #fbefdc; color: var(--warn); }
@media (prefers-color-scheme: dark) {
  .pill.approvata, .pill.in_produzione { background: #1f3a2a; } .pill.in_sviluppo, .pill.in_verifica, .pill.da_approvare { background: #3a2c17; }
}
.detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  position: sticky; top: 0; max-height: calc(100vh - 140px); overflow-y: auto; }
.detail .empty { margin: 0; }
.comment { border-top: 1px solid var(--border); padding: 10px 0; white-space: pre-wrap; }
.comment.ai { background: var(--ai); margin: 0 -14px; padding: 10px 14px; }
.comment .meta { font-size: 12px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

.task-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.task-col h2 { display: flex; justify-content: space-between; }
.task { display: flex; gap: 8px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.task input { width: auto; margin-top: 3px; } .task.fatta .t { text-decoration: line-through; color: var(--muted); }
.task .sub { font-size: 12px; color: var(--muted); }

/* markdown e documenti */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.msg.md, .comment.md { white-space: normal; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.1em 0 .45em; }
.md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; } .md h4 { font-size: 14px; color: var(--muted); }
.md p { margin: 0 0 .7em; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.4em; } .md li { margin: .15em 0; } .md li > ul, .md li > ol { margin: .2em 0 0; }
.md code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2);
  border-radius: 4px; padding: 1px 5px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  overflow-x: auto; margin: 0 0 .8em; white-space: pre; }
.md pre code { background: none; padding: 0; font-size: 12.5px; }
.md blockquote { margin: 0 0 .7em; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.md a, .doclink { color: var(--accent); text-decoration: underline; }
.msg.mine a { color: inherit; }
.md-table { overflow-x: auto; margin: 0 0 .8em; max-width: 100%; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.split.docs { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); }
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.doc-body { max-width: 760px; }

@media (max-width: 760px) {
  .split.docs { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; } .detail { position: static; max-height: none; }
  .form.row { grid-template-columns: 1fr 1fr; } .form.row input:first-child { grid-column: 1 / -1; }
  .msg { max-width: 92%; } #who { display: none; }
  .top { flex-wrap: wrap; padding: 8px 12px; } .brand { font-size: 14px; } .top-right { flex-wrap: wrap; }
  .tab { padding: 12px; } .chat-tab { min-width: 0; }
}
