:root {
  --bg: #101311;
  --panel: #171b18;
  --panel-raised: #1d221e;
  --line: #303730;
  --text: #f1f3ed;
  --muted: #9ba69d;
  --accent: #d8ff67;
  --accent-ink: #172000;
  --danger: #ff786e;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.login-shell::before { content: ""; position: absolute; width: 520px; height: 520px; border: 1px solid var(--line); border-radius: 50%; transform: translate(-42%, -45%); }
.login-mark { position: absolute; right: 7vw; bottom: -12vw; color: #181d19; font-size: min(48vw, 680px); font-weight: 900; line-height: .8; user-select: none; }
.login-card { width: min(100%, 420px); padding: 32px; background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--line); border-radius: var(--radius); z-index: 1; box-shadow: 0 24px 80px #0008; }
.login-card h1 { font-size: 30px; margin: 6px 0 10px; letter-spacing: -.04em; }
.login-card .muted { margin-bottom: 28px; }
label { display: grid; gap: 7px; margin: 14px 0; color: var(--muted); font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; color: var(--text); background: #111512; border: 1px solid var(--line); border-radius: 7px; padding: 11px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #d8ff6718; }
textarea { min-height: 88px; resize: vertical; }

.app { min-height: 100vh; display: grid; grid-template-columns: 232px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #121613; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 750; padding: 4px 8px 26px; }
.brand span { display: grid; place-items: center; width: 30px; height: 30px; color: var(--accent-ink); background: var(--accent); border-radius: 7px; font-weight: 900; }
nav { display: grid; gap: 4px; }
.nav-link { color: var(--muted); text-decoration: none; padding: 10px 12px; border-radius: 7px; font-size: 14px; }
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--panel-raised); }
.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #86db74; box-shadow: 0 0 0 3px #86db7420; }
.text-button { display: block; margin-top: 14px; padding: 0; border: 0; color: var(--muted); background: none; }
.text-button:hover { color: var(--text); }

main { min-width: 0; }
.topbar { min-height: 94px; padding: 20px 32px; display: flex; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.025em; }
.topbar .primary { margin-left: auto; }
.eyebrow { margin: 0; color: var(--accent); font: 700 10px/1.4 ui-monospace, SFMono-Regular, monospace; text-transform: uppercase; letter-spacing: .14em; }
.muted { color: var(--muted); }
.content { padding: 28px 32px 60px; }
.content-header { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 18px; }
.content-header p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.stat strong { display: block; margin-bottom: 4px; font-size: 26px; letter-spacing: -.04em; }
.stat span { color: var(--muted); font-size: 12px; }
.entity-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.entity-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.entity-row:last-child { border-bottom: 0; }
.entity-row:hover { background: var(--panel-raised); }
.entity-row h3 { margin: 0 0 5px; font-size: 14px; }
.entity-row p { margin: 0; color: var(--muted); font-size: 12px; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.primary, .secondary, .danger, .icon-button { border: 1px solid transparent; border-radius: 7px; padding: 9px 13px; font-size: 13px; font-weight: 700; }
.primary { color: var(--accent-ink); background: var(--accent); }
.primary:hover { background: #e4ff94; }
.secondary, .icon-button { color: var(--text); background: transparent; border-color: var(--line); }
.secondary:hover, .icon-button:hover { background: var(--panel-raised); }
.danger { color: var(--danger); background: transparent; border-color: #ff786e45; }
.danger:hover { background: #ff786e12; }
.empty { padding: 54px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 7px; color: var(--text); }
.back-link { display: inline-block; margin-bottom: 20px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--accent); }
.section-block { margin-bottom: 24px; }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.section-heading h2 { margin: 0; font-size: 14px; }
.badge { padding: 3px 7px; color: var(--muted); background: #0e110f; border: 1px solid var(--line); border-radius: 999px; font-size: 10px; }
.unavailable { opacity: .58; }
.menu-button { display: none; }

dialog { width: min(92vw, 600px); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 30px 100px #000b; }
dialog::backdrop { background: #050705bf; backdrop-filter: blur(3px); }
dialog form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 18px; }
.dialog-header h2 { margin: 4px 0 0; font-size: 20px; }
.icon-button { padding: 6px 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 12px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 10; padding: 12px 16px; color: var(--bg); background: var(--text); border-radius: 7px; font-size: 13px; font-weight: 700; box-shadow: 0 12px 40px #0008; }
.skeleton { height: 68px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, var(--panel), var(--panel-raised), var(--panel)); background-size: 200% 100%; animation: load 1.2s infinite; }
@keyframes load { to { background-position: -200% 0; } }

@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { position: fixed; z-index: 5; width: 232px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 20px 0 50px #0009; }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: block; padding: 7px 9px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 6px; }
  .topbar { min-height: 78px; padding: 15px 18px; gap: 12px; }
  .topbar h1 { font-size: 18px; }
  .topbar .primary { padding: 8px 10px; }
  .content { padding: 22px 18px 50px; }
  .stats { grid-template-columns: 1fr; }
  .entity-row { align-items: start; grid-template-columns: 1fr; }
  .row-actions { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}

/* Gestionale: tabs, reminder, toggle */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--border, #2a2f3a); }
.tab { background: none; border: none; color: var(--muted, #8a93a6); padding: 10px 14px; cursor: pointer; font-size: 14px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text, #e8ecf3); border-bottom-color: var(--accent, #4f8cff); }
.reminder-bar { background: rgba(255, 180, 60, .12); border: 1px solid rgba(255, 180, 60, .4); color: #ffcf8a; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.toggle { min-width: 46px; padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border, #2a2f3a); background: #2a2f3a; color: #8a93a6; cursor: pointer; font-size: 12px; }
.toggle.on { background: rgba(60, 200, 120, .18); border-color: rgba(60, 200, 120, .5); color: #7ce3a8; }
.entity-row .meta { color: var(--muted, #8a93a6); font-size: 13px; margin-top: 2px; }
.entity-row .sub { color: var(--muted, #8a93a6); font-size: 12px; }
.text-button.danger { color: #ff8a8a; }

/* Login Google */
.login-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted, #8a93a6); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border, #2a2f3a); }
#google-signin { display: flex; justify-content: center; margin-top: 4px; }

/* Badge trial */
.badge.trial { background: rgba(79, 140, 255, .18); border-color: rgba(79, 140, 255, .5); color: #9dc0ff; }

/* Gestionale: toolbar ricerca + filtri */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.search-input { flex: 1 1 280px; min-width: 220px; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border, #2a2f3a); background: var(--panel, #161a22); color: var(--text, #e8ecf3); font-size: 14px; }
.search-input:focus { outline: none; border-color: var(--accent, #4f8cff); }
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn { padding: 7px 12px; border-radius: 20px; border: 1px solid var(--border, #2a2f3a); background: transparent; color: var(--muted, #8a93a6); cursor: pointer; font-size: 13px; }
.filter-btn.active { background: var(--accent, #4f8cff); border-color: var(--accent, #4f8cff); color: #fff; }

/* Tabella clienti leggibile: colonne dimensionate */
.clienti-table { table-layout: fixed; width: 100%; border-collapse: collapse; }
.clienti-table th, .clienti-table td { padding: 10px 12px; vertical-align: top; text-align: left; overflow-wrap: break-word; }
.clienti-table .col-rs { width: 24%; }
.clienti-table .col-contatti { width: 24%; }
.clienti-table .col-rist { width: 14%; }
.clienti-table .col-stato { width: 10%; }
.clienti-table .col-az { width: 28%; }
.clienti-table .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.clienti-table .row-actions button { padding: 5px 9px; font-size: 12px; white-space: nowrap; }
.clienti-table small { color: var(--muted, #8a93a6); }
.clienti-table .prov { color: var(--accent, #4f8cff); font-weight: 600; }
.clienti-table .row-off td { opacity: .55; }

