/* claude-web-ui — stile ispirato a Claude.ai */

:root {
  --bg: #faf9f5;
  --bg-sidebar: #f0eee6;
  --bg-input: #ffffff;
  --text: #3d3929;
  --text-dim: #8a8678;
  --accent: #c96442;
  --accent-dark: #b3542f;
  --border: #e3e0d4;
  --user-bubble: #f0eee6;
  --danger: #b91c1c;
  --radius: 14px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }

/* ---------- login ---------- */
#login-view {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box {
  width: 320px; text-align: center; padding: 36px 28px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 6px 30px rgba(60, 50, 30, .08);
}
.login-mark { font-size: 40px; color: var(--accent); }
.login-box h1 { font-family: Georgia, serif; font-weight: 500; margin: 8px 0 24px; }
.login-box input {
  width: 100%; padding: 11px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 10px; font: inherit; background: var(--bg);
}
.login-box button {
  width: 100%; padding: 11px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.login-box button:hover { background: var(--accent-dark); }
.login-error { color: var(--danger); min-height: 1.2em; font-size: .9em; }

/* ---------- layout ---------- */
#app-view { display: flex; height: 100vh; }

#sidebar {
  width: 264px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
}
#new-chat {
  margin: 14px 12px 8px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-input); color: var(--text);
  font-weight: 600; text-align: left;
}
#new-chat:hover { border-color: var(--accent); color: var(--accent); }
#conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; margin: 2px 0; border-radius: 9px; cursor: pointer;
  color: var(--text); font-size: .94em;
}
.conv-item:hover { background: rgba(0,0,0,.05); }
.conv-item.active { background: rgba(201,100,66,.12); }
.conv-item .conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del {
  border: 0; background: none; color: var(--text-dim); font-size: 1em; padding: 0 2px;
  visibility: hidden;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-item .conv-del:hover { color: var(--danger); }

/* FASE B — ricerca full-text nelle conversazioni */
#conv-search-wrap { position: relative; display: flex; align-items: center; margin: 0 12px 6px; }
#conv-search-wrap .icon {
  position: absolute; left: 10px; width: 15px; height: 15px;
  color: var(--text-dim); pointer-events: none;
}
#conv-search {
  width: 100%; padding: 8px 10px 8px 32px; font: inherit; font-size: .9em;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-input); color: var(--text); outline: none;
}
#conv-search:focus { border-color: var(--accent); }
#conv-search::placeholder { color: var(--text-dim); }
.search-head {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 12px; font-size: .8em; color: var(--text-dim);
}
.search-cancel { border: 0; background: none; color: var(--accent); font: inherit; padding: 0; }
.search-cancel:hover { text-decoration: underline; }
.search-empty { padding: 8px 12px; font-size: .85em; color: var(--text-dim); }
.conv-item.search-result { align-items: flex-start; }
.search-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.search-snip {
  font-size: .82em; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#sidebar-footer {
  padding: 10px 14px; font-size: .78em; color: var(--text-dim);
  border-top: 1px solid var(--border);
}

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 22px; border-bottom: 1px solid var(--border); background: var(--bg);
}
#conv-title { font-family: Georgia, serif; font-size: 1.05em; }
#l2-badge {
  background: var(--danger); color: #fff; font-size: .7em; font-weight: 700;
  letter-spacing: .06em; padding: 3px 9px; border-radius: 20px;
}

/* ---------- selettore progetto (topbar) ---------- */
#topbar-proj { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#project-select {
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text-dim); font-size: .82em; padding: 4px 6px; max-width: 240px;
}
#project-select.assigned { color: var(--accent); border-color: var(--accent); }
#project-info {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  color: var(--accent); font-size: .82em; padding: 3px 9px; line-height: 1;
}
#project-info:hover { background: rgba(201,100,66,.1); }
#project-all-wrap {
  font-size: .8em; color: var(--text-dim); display: flex; align-items: center; gap: 4px;
}

/* ---------- raggruppamento sidebar per progetto ---------- */
.conv-group-head {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px;
  margin-top: 6px; font-size: .78em; font-weight: 700; letter-spacing: .03em;
  color: var(--text-dim); text-transform: uppercase; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.conv-group-head:hover { color: var(--accent); }
.conv-group-head .group-caret { font-size: .9em; width: 10px; flex-shrink: 0; }
.conv-group-head .group-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-group-head.orphan { color: var(--danger); }

/* ---------- overlay context.md (O3) ---------- */
#project-overlay {
  position: fixed; inset: 0; background: rgba(40,34,20,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.overlay-card {
  width: min(820px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 12px 50px rgba(60,50,30,.25); overflow: hidden;
}
.overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
#overlay-title { font-family: Georgia, serif; font-size: 1.05em; }
#overlay-close { border: 0; background: none; color: var(--text-dim); font-size: 1.1em; }
#overlay-close:hover { color: var(--danger); }
#overlay-body { padding: 18px 24px; overflow-y: auto; }

/* ---------- maschera quotazione (FASE F) ---------- */
#quote-overlay {
  position: fixed; inset: 0; background: rgba(40,34,20,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#quote-overlay .overlay-card { width: min(560px, 94vw); }
#quote-overlay .overlay-head span:first-child { font-family: Georgia, serif; font-size: 1.05em; }
#quote-close { border: 0; background: none; color: var(--text-dim); font-size: 1.1em; }
#quote-close:hover { color: var(--danger); }
#quote-body { padding: 18px 24px; overflow-y: auto; display: grid; gap: 14px; }
.quote-group:not([hidden]), .quote-scenario:not([hidden]) { display: grid; gap: 12px; }
.quote-scenario { margin-top: 2px; padding-top: 12px; border-top: 1px dashed var(--border); }
.quote-field:not([hidden]) { display: grid; grid-template-columns: 132px 1fr; align-items: center; gap: 10px; }
.quote-label { color: var(--text-dim); font-size: .9em; }
#quote-body input:not([type=checkbox]), #quote-body select {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); font-size: .9em; padding: 7px 9px;
}
#quote-body input:disabled { opacity: .5; }
.quote-sconto { display: flex; align-items: center; gap: 12px; }
.quote-sconto input[type=number] { max-width: 100px; }
.quote-inline { display: inline-flex; align-items: center; gap: 6px; font-size: .85em; color: var(--text-dim); white-space: nowrap; }
.quote-inline input { width: auto; }
#quote-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 24px; border-top: 1px solid var(--border);
}
#quote-cancel { border: 1px solid var(--border); background: var(--bg); color: var(--text-dim); border-radius: 10px; padding: 8px 16px; }
#quote-cancel:hover { color: var(--accent); border-color: var(--accent); }
#quote-submit { border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 16px; font-weight: 600; }
#quote-submit:disabled { opacity: .45; cursor: default; }
#quote-submit:not(:disabled):hover { background: var(--accent-dark); }

/* ---------- messaggi ---------- */
#messages {
  flex: 1; overflow-y: auto; padding: 26px 0 14px;
}
.msg { max-width: 760px; margin: 0 auto 18px; padding: 0 24px; }
.msg-user .msg-body {
  background: var(--user-bubble); border-radius: var(--radius);
  padding: 12px 16px; white-space: pre-wrap; overflow-wrap: break-word;
}
.msg-assistant .msg-body { line-height: 1.55; overflow-wrap: break-word; }
.msg-assistant .msg-body > :first-child { margin-top: 0; }
.msg-meta { font-size: .75em; color: var(--text-dim); margin-top: 5px; padding-left: 2px; }
.msg-tool {
  font-size: .8em; color: var(--text-dim); font-style: italic; margin: 4px 0;
}
.msg-error { color: var(--danger); font-size: .9em; }

.msg-body pre {
  background: #2d2a24; color: #eee8d8; padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; font-size: .88em;
}
.msg-body code { font-family: Consolas, "Cascadia Mono", monospace; }
.msg-body :not(pre) > code {
  background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 5px; font-size: .9em;
}
.msg-body table { border-collapse: collapse; margin: 10px 0; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 6px 10px; }
.msg-body th { background: var(--bg-sidebar); }
.msg-body a { color: var(--accent); }
.file-link {
  display: inline-block; background: rgba(201,100,66,.1); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 8px; padding: 4px 10px; margin: 3px 0;
  text-decoration: none; font-size: .9em;
}

/* ---------- composer ---------- */
#composer { padding: 0 24px 20px; position: relative; }
#composer-status {
  max-width: 760px; margin: 0 auto 6px; font-size: .8em; color: var(--text-dim);
  font-style: italic;
}
#composer-box {
  max-width: 760px; margin: 0 auto; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 3px 16px rgba(60,50,30,.06);
}
#input {
  width: 100%; border: 0; outline: none; resize: none; font: inherit;
  padding: 14px 16px 6px; background: transparent; color: var(--text);
  max-height: 220px;
}
#composer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px 10px;
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; }
#composer-bar select {
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text-dim); font-size: .82em; padding: 4px 6px;
}
#attach-btn, #skills-btn, #mic-btn, #quote-btn {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  color: var(--text-dim); font-size: .82em; padding: 4px 9px;
}
#attach-btn:hover, #skills-btn:hover, #mic-btn:not(:disabled):hover, #quote-btn:hover { color: var(--accent); border-color: var(--accent); }
/* display esplicito: batte l'UA hidden nell'interim di cache (stesso trucco del toggle notifiche, FASE A) */
#quote-btn { display: inline-flex; align-items: center; gap: 6px; }
#mic-btn:disabled { opacity: .45; cursor: default; }
/* stato "in ascolto" durante la dettatura (feature 5) */
#mic-btn.listening {
  border-color: var(--danger); background: rgba(185,28,28,.08);
  animation: mic-pulse 1.1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185,28,28,.45); }
  50% { box-shadow: 0 0 0 5px rgba(185,28,28,0); }
}
#mic-auto-toggle-wrap, #notify-toggle-wrap { font-size: .8em; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
#l2-toggle-wrap { font-size: .8em; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
#send-btn {
  border: 0; background: var(--accent); color: #fff; border-radius: 10px;
  padding: 8px 16px; font-weight: 600;
}
#send-btn:disabled { opacity: .45; cursor: default; }
#send-btn:not(:disabled):hover { background: var(--accent-dark); }
#stop-btn {
  border: 1px solid var(--danger); background: none; color: var(--danger);
  border-radius: 10px; padding: 7px 14px; font-weight: 600;
}

/* ---------- allegati come chip (Fase 3) ---------- */
#attach-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 16px;
  padding: 3px 6px 3px 11px; font-size: .8em; color: var(--text); max-width: 100%;
}
.attach-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attach-chip .chip-del { border: 0; background: none; color: var(--text-dim); font-size: .9em; padding: 0 2px; line-height: 1; }
.attach-chip .chip-del:hover { color: var(--danger); }
/* FASE C — chip proposta di progetto (riusa .attach-chip); bottone accetta in accent */
#suggest-chip .chip-ok { border: 0; background: none; color: var(--accent); font-size: .95em; font-weight: 700; padding: 0 3px; line-height: 1; }
#suggest-chip .chip-ok:hover { color: var(--accent-dark); }
/* feedback drag-and-drop sul composer (Fase 3) */
#composer-box.dragover { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201,100,66,.2); }

/* ---------- menu skill + menu @-mention file (Fase 3) ---------- */
#skills-menu, #mention-menu {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  width: min(640px, 90vw); max-height: 320px; overflow-y: auto;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(60,50,30,.15); padding: 6px;
}
.skill-item { padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.skill-item:hover { background: var(--bg-sidebar); }
.skill-item .skill-name { font-weight: 600; color: var(--accent); }
.skill-item .skill-desc { font-size: .82em; color: var(--text-dim); }

/* cursore di battitura durante lo streaming */
.typing::after { content: "▍"; color: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ============================ Fase 2 — Canvas ============================ */

/* topbar: cluster destro (export + progetto) */
#topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
#topbar-proj { margin-left: 0; }
#export-wrap { position: relative; }
#export-btn {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  color: var(--text-dim); font-size: .82em; padding: 4px 10px;
}
#export-btn:hover { color: var(--accent); border-color: var(--accent); }
#export-menu {
  position: absolute; top: 110%; right: 0; z-index: 40; min-width: 180px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(60,50,30,.15); padding: 5px;
}
.export-item { padding: 8px 12px; border-radius: 7px; cursor: pointer; font-size: .9em; }
.export-item:hover { background: var(--bg-sidebar); color: var(--accent); }

/* split messaggi | canvas */
#main-split { flex: 1; display: flex; min-height: 0; overflow: hidden; }
#messages { flex: 1; }

/* toolbar hover sui messaggi assistente */
.msg-tools { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity .12s; }
.msg-assistant:hover .msg-tools { opacity: 1; }
.msg-tool-btn {
  border: 1px solid var(--border); background: var(--bg); border-radius: 7px;
  color: var(--text-dim); font-size: .76em; padding: 3px 9px;
}
.msg-tool-btn:hover { color: var(--accent); border-color: var(--accent); }

/* pannello Canvas */
#canvas-panel {
  width: 44%; min-width: 380px; flex-shrink: 0; display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--bg-input);
}
#canvas-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
#canvas-title {
  flex: 1; min-width: 120px; border: 1px solid transparent; background: transparent;
  font-family: Georgia, serif; font-size: 1em; color: var(--text); border-radius: 6px; padding: 4px 6px;
}
#canvas-title:hover, #canvas-title:focus { border-color: var(--border); background: var(--bg); outline: none; }
.canvas-type {
  font-size: .72em; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px;
}
#canvas-lock {
  flex-basis: 100%; font-size: .8em; color: var(--accent); font-style: italic;
}
#canvas-head-actions { display: flex; gap: 6px; }
#canvas-head-actions button {
  border: 1px solid var(--border); background: var(--bg); border-radius: 7px;
  color: var(--text-dim); font-size: .8em; padding: 4px 9px;
}
#canvas-head-actions button:hover { color: var(--accent); border-color: var(--accent); }
#canvas-preview-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(201,100,66,.08); }

#canvas-body { flex: 1; min-height: 0; display: flex; }
#canvas-text {
  flex: 1; width: 100%; border: 0; outline: none; resize: none;
  padding: 14px 16px; background: var(--bg-input); color: var(--text);
  font-family: Consolas, "Cascadia Mono", monospace; font-size: .9em; line-height: 1.5;
}
#canvas-text:read-only { background: var(--bg-sidebar); color: var(--text-dim); }
#canvas-preview { flex: 1; overflow: auto; padding: 16px 20px; }
.canvas-iframe { width: 100%; height: 100%; border: 0; background: #fff; }

#canvas-revise {
  display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border);
}
#canvas-revise-input {
  flex: 1; border: 1px solid var(--border); border-radius: 9px; background: var(--bg);
  font: inherit; font-size: .9em; padding: 8px 12px; color: var(--text);
}
#canvas-revise-btn {
  border: 0; background: var(--accent); color: #fff; border-radius: 9px;
  padding: 8px 14px; font-weight: 600; font-size: .9em;
}
#canvas-revise-btn:disabled { opacity: .45; cursor: default; }
#canvas-revise-btn:not(:disabled):hover { background: var(--accent-dark); }

/* diff (contenuto Canvas + file) */
#canvas-diff { border-bottom: 1px solid var(--border); padding: 8px 14px; max-height: 30%; overflow: auto; }
.diff-head, .file-diff summary { font-size: .8em; font-weight: 700; color: var(--text-dim); margin-bottom: 4px; }
.diff-body, .fd-body { font-family: Consolas, "Cascadia Mono", monospace; font-size: .82em; }
.diff-line { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0 4px; border-radius: 3px; }
.diff-line.add { background: rgba(34,139,34,.12); color: #166534; }
.diff-line.del { background: rgba(185,28,28,.10); color: #991b1b; }
.diff-line.ctx { color: var(--text-dim); }

.file-diff {
  max-width: 760px; margin: 8px auto 0; padding: 8px 24px; font-size: .9em;
}
.file-diff summary { cursor: pointer; }
.fd-file { font-size: .82em; color: var(--accent); margin: 8px 0 2px; word-break: break-all; }
.fd-body {
  background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; overflow-x: auto; max-height: 320px; overflow-y: auto;
}

/* ============================ Fase 4 — auditabilità ============================ */

/* 4.1 — log strumenti collassabile sotto la risposta */
.tool-log {
  max-width: 760px; margin: 4px auto 0; padding: 0 24px; font-size: .82em;
}
.tool-log summary {
  cursor: pointer; color: var(--text-dim); font-weight: 600;
  -webkit-user-select: none; user-select: none;
}
.tool-log summary:hover { color: var(--accent); }
.tool-row {
  display: flex; gap: 8px; padding: 3px 0 3px 14px; align-items: baseline;
  font-family: Consolas, "Cascadia Mono", monospace;
}
.tool-row .tool-name { color: var(--accent); flex-shrink: 0; }
.tool-row .tool-summary {
  color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 4.3 — barra occupazione contesto in topbar */
#context-meter { display: flex; align-items: center; gap: 7px; }
#context-bar {
  width: 64px; height: 6px; border-radius: 4px; background: var(--border); overflow: hidden;
}
#context-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#context-fill.high { background: var(--danger); }
#context-label { font-size: .76em; color: var(--text-dim); white-space: nowrap; }

/* O2 — costo cumulato giornaliero nel footer sidebar */
#sidebar-footer { display: flex; flex-direction: column; gap: 2px; }
#daily-cost { font-weight: 600; color: var(--accent); }
.footer-sub { color: var(--text-dim); }

/* FASE D — spia salute workspace nel footer + pannello */
.footer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#health-dot:not([hidden]) { display: inline-block; }
#health-dot {
  position: relative; width: 9px; height: 9px; padding: 0; border: 0; border-radius: 50%;
  background: var(--text-dim); flex: none;
}
#health-dot.warn { background: var(--accent); }
#health-overlay {
  position: fixed; inset: 0; background: rgba(40,34,20,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#health-overlay .overlay-card { width: min(520px, 94vw); }
#health-overlay .overlay-head span:first-child { font-family: Georgia, serif; font-size: 1.05em; }
#health-close { border: 0; background: none; color: var(--text-dim); font-size: 1.1em; }
#health-close:hover { color: var(--danger); }
#health-body { padding: 18px 24px; overflow-y: auto; display: grid; gap: 10px; }
.health-item { color: var(--text); line-height: 1.5; }
.health-empty { color: var(--text-dim); }

/* ============================ PLANCIA (P3) — vista schede ============================ */
/* z-index 65: sopra il Canvas mobile (60), sotto scrim/cassetto (69/70, spenti quando la
   plancia e' aperta perche' openPlancia chiude il cassetto). */

/* voce fissa in cima alla sidebar */
#plancia-btn {
  display: flex; align-items: center; gap: 8px;
  margin: 14px 12px 4px; padding: 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-input); color: var(--text);
  font-weight: 600; text-align: left;
}
#plancia-btn:hover { border-color: var(--accent); color: var(--accent); }
#plancia-btn .icon { width: 15px; height: 15px; }

#plancia-overlay {
  position: fixed; inset: 0; background: rgba(40,34,20,.4);
  display: flex; align-items: center; justify-content: center; z-index: 65;
}
.plancia-card {
  width: min(1120px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 12px 50px rgba(60,50,30,.25); overflow: hidden;
}
.plancia-head {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg-input);
}
.plancia-title { font-family: Georgia, serif; font-size: 1.1em; }
#plancia-cassetto-wrap {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  font-size: .82em; color: var(--text-dim); white-space: nowrap;
}
#plancia-close { border: 0; background: none; color: var(--text-dim); font-size: 1.2em; padding: 0 4px; }
#plancia-close:hover { color: var(--danger); }
#plancia-skipped {
  padding: 8px 20px; font-size: .82em; color: var(--accent);
  border-bottom: 1px solid var(--border); background: rgba(201,100,66,.06); cursor: help;
}
#plancia-body { padding: 16px 20px 22px; overflow-y: auto; }
.plancia-empty { color: var(--text-dim); padding: 20px 2px; }

.plancia-group-head {
  font-size: .78em; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim); margin: 14px 2px 8px;
}
.plancia-group-head:first-child { margin-top: 0; }
.plancia-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
}

.plancia-card-item {
  display: flex; flex-direction: column; gap: 7px; min-width: 0; /* min-width:0: le righe nowrap non allargano la traccia grid oltre il contenitore */
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px 15px;
}
.pc-head { display: flex; align-items: center; gap: 8px; }
.pc-title {
  flex: 1; min-width: 0; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pc-badge {
  flex-shrink: 0; background: var(--accent); color: #fff; font-size: .66em; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; padding: 2px 7px; border-radius: 20px;
}
.pc-meta { font-size: .78em; color: var(--text-dim); text-transform: capitalize; }
.pc-warn { font-size: .84em; color: var(--accent); font-style: italic; }

/* barra avanzamento (esecuzione) */
.pc-bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.pc-bar-fill { height: 100%; background: var(--accent); }
.pc-bar-label { font-size: .76em; color: var(--text-dim); }

/* semaforo salute (presidio) */
.pc-salute { display: flex; align-items: center; gap: 7px; font-size: .86em; color: var(--text); text-transform: capitalize; }
.pc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--text-dim); }
.pc-dot.a-rischio { background: var(--accent); }
.pc-dot.fuori-rotta { background: var(--danger); }

.pc-next { font-size: .88em; color: var(--text); line-height: 1.4; }
.pc-next.derived { color: var(--text-dim); }
.pc-wait { font-size: .82em; color: var(--text-dim); line-height: 1.4; }
.pc-deadline { font-size: .8em; color: var(--text-dim); }
.pc-deadline.soon { color: var(--accent); }
.pc-deadline.past { color: var(--danger); font-weight: 600; }
.pc-log { font-size: .78em; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-updated { font-size: .76em; color: var(--text-dim); }
.pc-updated.stale { color: var(--accent); }

.pc-actions { margin-top: 3px; }
.pc-open {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  color: var(--text-dim); font-size: .82em; padding: 5px 12px;
}
.pc-open:hover { color: var(--accent); border-color: var(--accent); }

/* editing P4: campi cliccabili, input inline, assegnazione archetipo, avviso locale */
#plancia-msg {
  padding: 8px 20px; font-size: .82em; color: var(--accent);
  border-bottom: 1px solid var(--border); background: rgba(201,100,66,.06);
}
.pc-editable { cursor: pointer; border-radius: 4px; }
.pc-editable:hover { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.pc-arche { text-transform: none; }
.pc-ph { color: var(--text-dim); font-style: italic; opacity: .8; }
.pc-edit-input {
  width: 100%; box-sizing: border-box; font: inherit; font-size: .88em;
  padding: 4px 7px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
.pc-edit-input:focus { outline: none; }
.pc-assign { display: flex; gap: 7px; }
.pc-assign button {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  color: var(--text-dim); font-size: .82em; padding: 4px 12px; cursor: pointer;
}
.pc-assign button:hover { color: var(--accent); border-color: var(--accent); }

/* ===== PLANCIA (P5) — switch viste + tabella densa + registro attese ===== */
.plancia-views { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.plancia-views button {
  border: 0; background: none; color: var(--text-dim); font: inherit; font-size: .8em;
  padding: 4px 12px; border-radius: 6px; cursor: pointer;
}
.plancia-views button:hover { color: var(--text); }
.plancia-views button.active { background: var(--bg-input); color: var(--text); box-shadow: 0 1px 2px rgba(60,50,30,.12); }

/* tabella densa: scorre in orizzontale DENTRO il wrap, mai la pagina */
.plancia-table-wrap { overflow-x: auto; }
.plancia-table { border-collapse: collapse; width: 100%; font-size: .82em; }
.plancia-table th, .plancia-table td {
  text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap;
}
.plancia-table th {
  position: sticky; top: 0; background: var(--bg); color: var(--text-dim);
  font-weight: 700; font-size: .92em; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; -webkit-user-select: none; user-select: none;
}
.plancia-table th:hover { color: var(--text); }
.plancia-table th.sort-asc::after { content: ' ▲'; font-size: .8em; color: var(--accent); }
.plancia-table th.sort-desc::after { content: ' ▼'; font-size: .8em; color: var(--accent); }
.plancia-table tbody tr:hover { background: var(--bg-input); }
.plancia-table .pt-title { font-weight: 600; color: var(--text); }
.plancia-table .pt-ro { color: var(--text-dim); }        /* stato / last_updated: sola lettura (D3) */
.plancia-table .pt-ro.stale { color: var(--accent); }
.plancia-table .pt-na { color: var(--text-dim); }         /* salute non applicabile (esecuzione) */
.plancia-table .pt-text { white-space: normal; }          /* i testi liberi possono andare a capo nella cella */
.plancia-table .pt-past { color: var(--danger); font-weight: 600; }
.plancia-table .pt-soon { color: var(--accent); }
.plancia-table td .pc-salute { font-size: 1em; }

/* registro attese: elenco ordinato per eta' */
.plancia-attese-note { font-size: .78em; color: var(--text-dim); font-style: italic; margin-bottom: 12px; }
.plancia-attese { display: flex; flex-direction: column; gap: 8px; }
.pa-item { background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px; }
.pa-head { display: flex; align-items: baseline; gap: 10px; }
.pa-title { font-weight: 600; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pa-stato { font-size: .76em; color: var(--text-dim); text-transform: capitalize; flex-shrink: 0; }
.pa-eta { font-size: .78em; color: var(--accent); flex-shrink: 0; white-space: nowrap; }
.pa-wait { display: inline-block; margin-top: 5px; font-size: .86em; color: var(--text); line-height: 1.4; }

/* fallback responsive: sotto 900px il Canvas va in overlay a tutta larghezza */
@media (max-width: 900px) {
  #canvas-panel {
    position: fixed; inset: 0; width: 100%; min-width: 0; z-index: 60;
  }
}

/* ============================ Restyling 2026-07 — estetica + mobile ============================ */
/* Scala z-index dell'app: export-menu 40 · pannelli mobile (opzioni/topbar) 45 ·
   project-overlay 50 · canvas mobile 60 · scrim cassetto 69 · cassetto sidebar 70. */

/* ---------- icone SVG monocromatiche ---------- */
.icon {
  width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -3px;
}

/* ---------- scrollbar sottili (via l'effetto Windows) ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---------- micro-interazioni e focus visibile ---------- */
button, select, .conv-item, .skill-item, .export-item {
  transition: color .12s, border-color .12s, background-color .12s, box-shadow .12s;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#input:focus-visible, #canvas-text:focus-visible, #canvas-title:focus-visible { outline: none; }

/* ---------- tipografia messaggi ---------- */
.msg-assistant .msg-body { line-height: 1.6; }
.msg-body h1, .msg-body h2, .msg-body h3 { font-family: Georgia, serif; font-weight: 600; }

/* ---------- sidebar: ritmo visivo ---------- */
.conv-item { padding: 10px 12px; }
.conv-item.active { box-shadow: inset 3px 0 0 var(--accent); }

/* ---------- composer: decongestione desktop ---------- */
#composer-bar { flex-wrap: wrap; row-gap: 6px; }
.bar-left { flex-wrap: wrap; row-gap: 6px; min-width: 0; }
/* desktop: i due gruppi sono trasparenti al layout (un solo nodo per controllo, mai cloni) */
.bar-options, .bar-essentials { display: contents; }
#composer-bar select { max-width: 170px; }
#mic-auto-toggle-wrap, #notify-toggle-wrap, #l2-toggle-wrap, #project-all-wrap { white-space: nowrap; }
#attach-btn, #mic-btn, #options-btn { line-height: 1; padding: 5px 9px; }

/* elementi solo-mobile: spenti su desktop (l'attributo hidden li copre col CSS vecchio in cache) */
#options-btn, #menu-btn, #topbar-menu-btn, #drawer-scrim { display: none; }
.conv-ren { display: none; }

/* =============================== layout mobile =============================== */
/* Stessa query di MOBILE_MQ in app.js (unica fonte di verita', decisione 1 del piano). */
@media (max-width: 768px), (pointer: coarse) and (max-height: 500px) {

  #app-view { height: 100vh; height: 100dvh; }
  #login-view { height: 100vh; height: 100dvh; }

  /* --- cassetto sidebar --- */
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
    width: min(85vw, 320px);
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(40,34,20,.25);
  }
  body.drawer-open #sidebar { transform: translateX(0); }
  #drawer-scrim {
    position: fixed; inset: 0; z-index: 69;
    background: rgba(40,34,20,.45);
  }
  body.drawer-open #drawer-scrim { display: block; }
  body.drawer-open { overflow: hidden; }

  /* --- topbar --- */
  #topbar { padding: 8px 10px; gap: 8px; position: relative; }
  #menu-btn, #topbar-menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px; border: 0; background: none;
    color: var(--text); border-radius: 10px; flex-shrink: 0; padding: 0;
  }
  #menu-btn:active, #topbar-menu-btn:active { background: rgba(0,0,0,.06); }
  #conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #l2-badge { flex-shrink: 0; }
  #topbar-right {
    display: none;
    position: absolute; top: calc(100% + 4px); right: 8px; z-index: 45;
    flex-direction: column; align-items: stretch; gap: 14px;
    background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 8px 30px rgba(60,50,30,.15); padding: 14px; margin-left: 0;
    width: min(320px, calc(100vw - 16px));
  }
  body.tbmenu-open #topbar-right { display: flex; }
  #topbar-proj { flex-wrap: wrap; min-width: 0; }
  #project-select { max-width: none; flex: 1 1 0; min-width: 0; width: 100%; padding: 9px 8px; font-size: .95em; }
  /* FASE C — chip proposta a piena larghezza nella tendina, tap target >=44px */
  #suggest-chip { width: 100%; padding: 4px 6px 4px 11px; }
  #suggest-chip .chip-ok, #suggest-chip .chip-del {
    display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px;
  }
  #export-btn { padding: 10px 12px; font-size: .95em; text-align: left; }
  #export-menu { position: static; margin-top: 6px; box-shadow: none; }
  #context-meter { justify-content: flex-start; }

  /* --- messaggi --- */
  #messages { padding: 16px 0 10px; }
  .msg { padding: 0 14px; margin-bottom: 16px; }
  .tool-log, .file-diff { padding: 0 14px; }
  .msg-tools { opacity: 1; } /* niente hover su touch */
  .msg-tool-btn { padding: 6px 11px; font-size: .82em; }

  /* --- composer --- */
  #composer { padding: 0 10px 10px; }
  #input { font-size: 16px; max-height: 200px; max-height: 30dvh; }
  #composer-box { position: relative; }
  .bar-essentials { display: flex; gap: 8px; }
  #options-btn { display: inline-flex; }
  #attach-btn, #mic-btn, #options-btn {
    align-items: center; justify-content: center; display: inline-flex;
    min-width: 44px; min-height: 44px; border-radius: 12px;
  }
  .icon { width: 18px; height: 18px; }
  #send-btn { min-height: 44px; padding: 10px 20px; border-radius: 12px; }
  #stop-btn { min-height: 44px; }

  /* pannello opzioni sopra il composer */
  .bar-options {
    display: none;
    position: absolute; bottom: calc(100% + 8px); left: 0; right: 0; z-index: 45;
    flex-direction: column; align-items: stretch; gap: 14px;
    background: var(--bg-input); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: 0 10px 34px rgba(60,50,30,.18); padding: 16px;
  }
  #composer-box.options-open .bar-options { display: flex; }
  #composer-bar .bar-options select { width: 100%; max-width: none; padding: 10px; font-size: .95em; }
  #skills-btn, #quote-btn { padding: 10px; font-size: .95em; }
  #quote-btn { justify-content: center; min-height: 44px; }
  #mic-auto-toggle-wrap, #notify-toggle-wrap, #l2-toggle-wrap { font-size: .95em; gap: 8px; min-height: 28px; }
  #mic-auto-toggle-wrap input, #notify-toggle-wrap input, #l2-toggle-wrap input { width: 18px; height: 18px; }

  /* --- lista chat: azioni touch sempre visibili sull'item attivo --- */
  .conv-item { padding: 12px; }
  .conv-item .conv-del { visibility: hidden; padding: 6px 10px; font-size: 1.05em; }
  .conv-ren {
    display: inline-block; visibility: hidden; border: 0; background: none;
    color: var(--text-dim); padding: 6px 10px; font-size: 1em;
  }
  .conv-item.active .conv-del, .conv-item.active .conv-ren { visibility: visible; }
  .conv-ren:hover { color: var(--accent); }

  /* --- overlay progetti e canvas --- */
  .overlay-card { width: 96vw; max-height: 92vh; max-height: 92dvh; }
  #overlay-body { padding: 14px 16px; }
  #canvas-head { padding: 10px; }
  #canvas-revise { padding: 10px; }

  /* --- maschera quotazione mobile: no zoom (16px), target touch ≥44px --- */
  #quote-overlay .overlay-card { width: 96vw; }
  #quote-body { padding: 14px 16px; }
  .quote-field:not([hidden]) { grid-template-columns: 1fr; gap: 5px; }
  #quote-body input:not([type=checkbox]), #quote-body select { font-size: 16px; padding: 10px; }
  .quote-sconto input[type=number] { max-width: 120px; }
  #quote-foot { padding: 12px 16px; }
  #quote-cancel, #quote-submit { min-height: 44px; }
  #quote-close { min-width: 44px; min-height: 44px; }

  /* menu skill / @-file a tutta larghezza */
  #skills-menu, #mention-menu { width: calc(100vw - 20px); max-height: 42vh; }

  /* ricerca (FASE B): 16px = no zoom, campo e azioni comodi al tocco */
  #conv-search { font-size: 16px; padding: 12px 12px 12px 36px; }
  #conv-search-wrap .icon { left: 12px; }
  .search-head { padding: 10px 12px; font-size: .85em; }
  .search-cancel { padding: 4px 6px; }

  #sidebar-footer { padding-bottom: 14px; }

  /* salute workspace (FASE D): bottone 44×44 (target touch), pallino disegnato via ::before */
  #health-dot { width: 44px; height: 44px; background: none !important; }
  #health-dot::before { content: ""; position: absolute; inset: 0; margin: auto; width: 11px; height: 11px; border-radius: 50%; background: var(--text-dim); }
  #health-dot.warn::before { background: var(--accent); }
  #health-overlay .overlay-card { width: 96vw; }
  #health-body { padding: 14px 16px; }
  #health-close { min-width: 44px; min-height: 44px; }

  /* PLANCIA mobile: card a colonna singola, target touch >=44px */
  #plancia-btn { padding: 12px; }
  .plancia-card { width: 96vw; max-height: 92vh; max-height: 92dvh; }
  .plancia-head { padding: 12px 14px; flex-wrap: wrap; gap: 10px; } /* switch + toggle + ✕ vanno a capo su schermo stretto */
  #plancia-close { min-width: 44px; min-height: 44px; }
  #plancia-body { padding: 14px 16px 18px; }
  .plancia-grid { grid-template-columns: 1fr; }
  .pc-open { min-height: 44px; padding: 8px 16px; }
  /* input inline: font-size 16px per non far zoomare iOS (come #input); target comodi */
  .pc-edit-input { font-size: 16px; padding: 9px 10px; }
  .pc-editable { padding: 3px 2px; min-height: 32px; }
  .pc-assign button { min-height: 44px; padding: 8px 16px; }
  /* P5: switch viste tappabile; tabella con celle piu' comode (scorre nel suo wrap, mai la pagina) */
  .plancia-views button { padding: 9px 14px; }
  .plancia-table th, .plancia-table td { padding: 9px 12px; }
}
