* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  height: 100%;
}
#app { min-height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--accent); }

/* ---------- Theme variable sets (dark, exchange-style) ---------- */
:root, [data-theme="renovation"] {
  --accent: #F0B90B; --accent-strong: #F8D33A; --accent-soft: #2B2607; --accent-text: #F0B90B;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="electrical"] {
  --accent: #F5D90A; --accent-strong: #FCEB5A; --accent-soft: #2E2A05; --accent-text: #F5D90A;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="plumbing"] {
  --accent: #2E9BF0; --accent-strong: #63B5F5; --accent-soft: #0D2436; --accent-text: #2E9BF0;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="assembly"] {
  --accent: #0ECB81; --accent-strong: #4FDDA3; --accent-soft: #0D2B1F; --accent-text: #0ECB81;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="industry"] {
  --accent: #8A97A6; --accent-strong: #AEB8C4; --accent-soft: #1F242B; --accent-text: #C4CCD4;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="paint"] {
  --accent: #D9483A; --accent-strong: #E8705F; --accent-soft: #301410; --accent-text: #E8705F;
  --page-bg: #0B0E11; --surface: #181A20; --surface-alt: #1E2329;
  --border: #2B3139; --text-primary: #EAECEF; --text-secondary: #848E9C; --text-muted: #5E6673;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0B0E11; --sidebar-text: #EAECEF; --on-accent: #0B0E11; --font-heading: Georgia, "Times New Roman", serif;
}
[data-theme="cardstyle"] {
  --accent: #E8720C; --accent-strong: #F58A2E; --accent-soft: #2B1706; --accent-text: #F58A2E;
  --page-bg: #0A0A0A; --surface: #141414; --surface-alt: #1A1A1A;
  --border: #2A2A2A; --text-primary: #F5F5F5; --text-secondary: #999999; --text-muted: #666666;
  --danger: #F6465D; --success: #0ECB81; --sidebar-bg: #0A0A0A; --sidebar-text: #F5F5F5; --on-accent: #0A0A0A;
  --font-heading: Impact, "Arial Narrow", sans-serif;
}
[data-theme="shirt"] {
  --accent: #2B1F14; --accent-strong: #4A3F2C; --accent-soft: #EDE0C0; --accent-text: #2B1F14;
  --page-bg: #E8DFC8; --surface: #FAF5E8; --surface-alt: #EFE6CC;
  --border: #C9BC98; --text-primary: #2B1F14; --text-secondary: #6B5F45; --text-muted: #A99B7C;
  --danger: #A32D2D; --success: #3B6D11; --sidebar-bg: #2B1F14; --sidebar-text: #E8DFC8; --on-accent: #E8DFC8;
  --font-heading: Georgia, "Times New Roman", serif;
}

/* ---------- Login ---------- */
.login-screen {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: var(--sidebar-bg);
}
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: 16px;
  padding: 28px 24px; text-align: center;
}
.login-card .brand { font-size: 22px; font-weight: 700; font-family: var(--font-heading); color: var(--accent); margin-bottom: 4px; }
.login-card .brand-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 11px 12px; margin-bottom: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-alt); color: var(--text-primary);
}
.login-card button.primary {
  width: 100%; padding: 12px; border-radius: 10px; border: none;
  background: var(--accent); color: var(--on-accent); font-weight: 600; margin-top: 6px; cursor: pointer;
}
.login-error { color: var(--danger); font-size: 13px; margin: -4px 0 10px; text-align: left; }
.login-hint { font-size: 12px; color: var(--text-muted); margin-top: 16px; text-align: left; line-height: 1.5; }

/* ---------- App shell ---------- */
.shell { flex: 1; display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex-shrink: 0;
  position: fixed; top: 0; left: 0; bottom: 0; overflow-y: auto; z-index: 500;
  transition: transform .2s ease;
}
.sidebar .brand-row { padding: 18px 16px 10px; font-weight: 700; font-size: 16px; font-family: var(--font-heading); display: flex; align-items: center; gap: 10px; }
.hazard-stripe { height: 5px; background-image: repeating-linear-gradient(45deg, var(--accent), var(--accent) 6px, var(--sidebar-bg) 6px, var(--sidebar-bg) 12px); }
.nav-list { list-style: none; margin: 0; padding: 4px 8px; flex: 1; }
.nav-list li { margin-bottom: 2px; }
.nav-list a {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 8px;
  color: var(--sidebar-text); text-decoration: none; font-size: 14px; opacity: .8;
}
.nav-list a i { font-size: 18px; width: 20px; }
.nav-list a.active, .nav-list a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.sidebar .logout-row { padding: 10px 16px 18px; }
.sidebar .logout-row a { display: flex; gap: 10px; align-items: center; color: var(--sidebar-text); opacity: .75; text-decoration: none; font-size: 14px; }

.main-col { flex: 1; margin-left: 220px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: none; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--sidebar-bg); color: var(--sidebar-text); position: sticky; top: 0; z-index: 30;
}
.topbar button.menu-btn {
  background: var(--accent); border: none; color: var(--on-accent); border-radius: 8px;
  width: 32px; height: 32px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
}
.topbar .tb-title { font-weight: 700; font-size: 15px; font-family: var(--font-heading); line-height: 1; }
.brand-icon { flex-shrink: 0; width: 26px; height: 26px; }
.tb-stripe { display: none; }
@media (max-width: 860px) { .tb-stripe { display: block; } }
.content { flex: 1; padding: 20px; max-width: 900px; width: 100%; margin: 0 auto; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 490; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .main-col { margin-left: 0; }
  .topbar { display: flex; }
}

/* ---------- Generic UI ---------- */
h1.page-title { font-family: var(--font-heading); font-size: 22px; font-weight: 700; margin: 0 0 4px; }
p.page-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.card.accent-card { border-left: 3px solid var(--accent); }
.card h3 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }
.stat { background: var(--surface-alt); border-radius: 10px; padding: 12px 14px; }
.stat-icon {
  width: 24px; height: 24px; border-radius: 6px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}
.stat-icon i { font-size: 14px; color: var(--accent-strong); }
.stat .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat .value { font-family: var(--font-heading); font-size: 22px; font-weight: 700; }
label.field-label { display: block; font-size: 12px; color: var(--text-secondary); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-primary);
}
textarea { resize: vertical; min-height: 60px; }
button.btn {
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-primary); cursor: pointer; font-size: 14px; font-weight: 500;
}
button.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
button.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.site-row { transition: transform .1s ease, border-color .15s ease; }
.site-row:active { transform: scale(0.98); border-color: var(--border-strong, var(--border)); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge.pending { background: var(--accent-soft); color: var(--accent-text); }
.badge.approved { background: rgba(14,203,129,0.15); color: var(--success); }
.badge.rejected { background: rgba(246,70,93,0.15); color: var(--danger); }
table.simple { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.simple th { text-align: left; color: var(--text-secondary); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.simple td { padding: 8px; border-bottom: 1px solid var(--border); }
.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); font-size: 13.5px; }
.theme-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; }
.theme-swatch {
  border: 2px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}
.theme-swatch.active { border-color: var(--accent); }
.dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.chat-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 12px; }
.chat-row.mine { justify-content: flex-end; }
.chat-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0;
}
.chat-msg { max-width: 76%; }
.chat-msg .who { font-size: 11px; color: var(--text-secondary); margin-bottom: 3px; }
.chat-msg.mine .who { text-align: right; }
.chat-msg .bubble { background: var(--surface-alt); border-radius: 14px; padding: 9px 13px; font-size: 14px; line-height: 1.4; }
.chat-msg.mine .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 4px; }
.chat-msg:not(.mine) .bubble { border-bottom-left-radius: 4px; }
.chat-box { display: flex; flex-direction: column; height: 420px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 4px 2px; margin-bottom: 8px; }
.chat-input-row { display: flex; gap: 6px; align-items: center; }
.chat-input-row .btn-sm { padding: 8px 9px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar-bg); color: var(--sidebar-text); padding: 10px 18px; border-radius: 30px;
  font-size: 13.5px; z-index: 100; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.seg-control {
  display: flex; flex-wrap: wrap; gap: 2px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 3px;
}
.seg-item {
  flex: 1 1 auto; text-align: center; font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary); border-radius: 8px; padding: 7px 10px;
  cursor: pointer; border: none; background: transparent; white-space: nowrap;
}
.seg-item.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* --- Stile 1: sottolineate --- */
[data-ui-style="underline"] .seg-control { gap: 18px; background: transparent; border: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0; }
[data-ui-style="underline"] .seg-item { flex: 0 0 auto; padding: 0 0 8px; border-radius: 0; border-bottom: 2px solid transparent; }
[data-ui-style="underline"] .seg-item.active { background: transparent; color: var(--accent); border-bottom-color: var(--accent); }

/* --- Stile 2: barra segmentata (default) --- */
[data-ui-style="segmented"] .seg-control { gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
[data-ui-style="segmented"] .seg-item { border-radius: 8px; padding: 7px 10px; }
[data-ui-style="segmented"] .seg-item.active { background: var(--accent); color: var(--on-accent); }

/* --- Stile 3: chip squadrati --- */
[data-ui-style="chips"] .seg-control { gap: 8px; background: transparent; border: none; padding: 0; }
[data-ui-style="chips"] .seg-item { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 14px; }
[data-ui-style="chips"] .seg-item.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* --- Stile 4: menu a tendina --- */
[data-ui-style="dropdown"] .seg-control { flex-direction: column; gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0; overflow: hidden; }
[data-ui-style="dropdown"] .seg-item { display: none; text-align: left; border-radius: 0; padding: 10px 12px; }
[data-ui-style="dropdown"] .seg-item.active { display: flex; align-items: center; justify-content: space-between; color: var(--text-primary); }
[data-ui-style="dropdown"] .seg-item.active::after { content: "▾"; font-size: 13px; color: var(--text-secondary); }
[data-ui-style="dropdown"] .seg-control.expanded .seg-item { display: flex; align-items: center; border-top: 1px solid var(--border); }
[data-ui-style="dropdown"] .seg-control.expanded .seg-item:first-child { border-top: none; }
[data-ui-style="dropdown"] .seg-control.expanded .seg-item.active::after { content: ""; }
