/* ============================================================
   Viemmegi Newsletter — tema "Negozio Arredamento" (Betheme)
   Font e colori locali, nessuna dipendenza esterna.
   Palette estratta da negoziodarredamento.it:
     primary #4d4f51 · headings #444 · accent #0095eb
     page bg #f5f5f5 · card #fff · borders #eee · light btn #f7f7f7
   ============================================================ */

@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/opensans-400.woff2") format("woff2");
}
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/opensans-600.woff2") format("woff2");
}
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/opensans-700.woff2") format("woff2");
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/roboto-400.woff2") format("woff2");
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/roboto-500.woff2") format("woff2");
}
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/roboto-700.woff2") format("woff2");
}

:root {
  --primary: #4d4f51;
  --primary-dark: #34495e;
  --primary-darker: #2b2c2e;
  --accent: #0095eb;
  --ink: #4d4f51;
  --heading: #444444;
  --muted: #929292;
  --muted-2: #65666c;
  --bg: #f5f5f5;
  --card: #ffffff;
  --border: #eeeeee;
  --border-strong: #e0e0e0;
  --light: #f7f7f7;
  --ok: #1a9e5f;
  --ok-bg: #eaf7f0;
  --err: #d0362e;
  --err-bg: #fbeeec;
  --warn: #d98b16;
  --warn-bg: #fbf3e6;
  --radius: 3px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --font-body: "Open Sans", Arial, Tahoma, sans-serif;
  --font-head: "Roboto", "Open Sans", Arial, Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}
::selection { background: var(--accent); color: #fff; }
h1, h2, h3, h4, h5, h6 { font-family: var(--font-head); color: var(--heading); font-weight: 700; line-height: 1.25; }
a { color: var(--primary); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--primary-dark); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 0.8rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 0.4rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.center { text-align: center; }
.inline-form { display: inline; }

/* topbar — barra scura stile Action_bar/footer Viemmegi */
.topbar { background: var(--primary); color: #fff; padding: 0.75rem 1.25rem; box-shadow: var(--shadow); }
.topbar-inner { display: flex; align-items: center; gap: 0.9rem; max-width: 1240px; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 0.6rem; color: #fff; font-weight: 700; font-family: var(--font-head); font-size: 1.05rem; }
.brand:hover { color: #fff; }
.brand img { height: 34px; width: auto; background: #fff; border-radius: var(--radius); padding: 2px 6px; display: block; }
.brand-text { letter-spacing: 0.5px; }
.brand-sub { color: rgba(255, 255, 255, 0.65); border-left: 1px solid rgba(255, 255, 255, 0.2); padding-left: 0.9rem; font-size: 0.85rem; }
.topbar-right { margin-left: auto; display: flex; gap: 0.7rem; align-items: center; }
.chip { background: rgba(255, 255, 255, 0.12); border-radius: 999px; padding: 0.25rem 0.8rem; font-size: 0.8rem; color: #fff; }

/* layout */
.layout { display: flex; max-width: 1240px; margin: 0 auto; min-height: calc(100vh - 150px); align-items: stretch; }
.sidebar { width: 220px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border); padding: 1rem 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a { display: flex; align-items: center; gap: 0.4rem; padding: 0.62rem 1.35rem; color: var(--ink); font-size: 0.92rem; border-left: 3px solid transparent; transition: all 0.15s ease; }
.sidebar li a:hover { background: var(--light); color: var(--primary); }
.sidebar li a.active { background: var(--light); color: var(--primary); font-weight: 600; border-left-color: var(--primary); }
.sidebar li.sep { border-top: 1px solid var(--border); margin: 0.6rem 1rem; }
.content { flex: 1; padding: 1.5rem; min-width: 0; }

/* cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.35rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.card > h2 { padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 1.1rem; }
@media (max-width: 900px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
}

.stat { font-size: 2.1rem; font-weight: 700; color: var(--primary); font-family: var(--font-head); line-height: 1; }
.stat-label { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.6px; margin-top: 0.35rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; gap: 1rem; flex-wrap: wrap; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* buttons — stile Betheme (pochissimo arrotondati, sobri) */
.btn { display: inline-block; padding: 0.5rem 1rem; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--light); color: var(--primary); cursor: pointer; font-size: 0.88rem; font-family: var(--font-head); font-weight: 500; transition: all 0.2s ease; }
.btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-darker); color: #fff; border-color: var(--primary-darker); }
.btn-danger { border-color: var(--err); color: var(--err); background: #fff; }
.btn-danger:hover { background: var(--err); color: #fff; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.4); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.15); color: #fff; border-color: rgba(255, 255, 255, 0.7); }
.btn-block { display: block; width: 100%; }
.btn-small { padding: 0.28rem 0.6rem; font-size: 0.8rem; }

/* forms */
label { display: block; margin: 0.65rem 0 0.28rem; font-weight: 600; font-size: 0.8rem; font-family: var(--font-head); text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted-2); }
input, select, textarea { padding: 0.5rem 0.65rem; border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: 0.9rem; font-family: var(--font-body); color: var(--ink); background: #fff; transition: border-color 0.15s ease, box-shadow 0.15s ease; }
input:not([type=checkbox]):not([type=radio]) { width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); vertical-align: middle; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0, 149, 235, 0.18); }
textarea { resize: vertical; }
fieldset.box { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 1rem; margin-bottom: 0.9rem; }
legend { font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--primary); padding: 0 0.5rem; font-family: var(--font-head); }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 0.55rem 0.65rem; text-align: left; vertical-align: top; }
.table th { background: var(--primary); color: #fff; font-family: var(--font-head); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.4px; border-bottom: none; }
.table tbody tr:nth-child(even) { background: #fafafa; }
.table tbody tr:hover { background: var(--light); }
.table-scroll { display: block; overflow-x: auto; white-space: nowrap; }
.table-scroll textarea, .table-scroll input { white-space: normal; }

/* tabella "Recupero Falliti": a larghezza fissa, niente scroll orizzontale, testi a capo */
.rec-table { table-layout: fixed; width: 100%; }
.rec-table th, .rec-table td { overflow-wrap: anywhere; word-break: break-word; vertical-align: top; }
.rec-table .rec-msg { white-space: pre-wrap; line-height: 1.45; }
.rec-actions { display: flex; flex-direction: column; gap: 0.3rem; align-items: stretch; }
.rec-actions .btn { white-space: normal; }
.kv { border-collapse: collapse; width: 100%; }
.kv td { padding: 0.4rem 0; border-bottom: 1px dashed var(--border); }

/* pills / stati */
.pill { display: inline-block; padding: 0.12rem 0.6rem; border-radius: 999px; font-size: 0.74rem; font-weight: 700; font-family: var(--font-head); letter-spacing: 0.3px; text-transform: uppercase; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

/* flash */
.flash { padding: 0.8rem 1.1rem; border-radius: var(--radius); margin-bottom: 1.1rem; border-left: 4px solid; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-left-color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); border-left-color: var(--err); }

/* semaforo */
.semaforo { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.semaforo-item { display: flex; align-items: center; gap: 0.5rem; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 0.4rem 1rem; box-shadow: var(--shadow); }
.semaforo-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.semaforo-item.on .dot { background: var(--ok); }
.semaforo-item.off .dot { background: var(--err); }
.semaforo-item.danger { border-color: var(--err); background: var(--err-bg); }

/* auth — hero di sfondo come header del sito */
.auth-body { background: linear-gradient(rgba(77, 79, 81, 0.86), rgba(43, 44, 46, 0.92)), url("/static/img/hero.jpg") center/cover no-repeat #4d4f51; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }
.auth-card { position: relative; background: #fff; border-radius: var(--radius); padding: 2.2rem 2rem; width: 100%; max-width: 430px; box-shadow: var(--shadow-lg); border-top: 4px solid var(--primary); }
.auth-card .auth-logo { display: block; margin: 0 auto 1rem; height: 46px; width: auto; }
.auth-card h1 { margin-bottom: 0.3rem; text-align: center; }
.tabs { display: flex; gap: 0.5rem; margin: 1.2rem 0; border-bottom: 1px solid var(--border); }
.tab { flex: 1; padding: 0.55rem; border: none; border-bottom: 2px solid transparent; background: #fff; color: var(--muted); cursor: pointer; font-family: var(--font-head); font-weight: 500; font-size: 0.9rem; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.qr-img { max-width: 220px; display: block; margin: 0 auto; cursor: zoom-in; }

/* lightbox QR: click sull'immagine → popup grande per inquadrare */
.qr-modal { position: fixed; inset: 0; background: rgba(43, 44, 46, 0.86); display: none; align-items: center; justify-content: center; z-index: 9999; padding: 1.5rem; }
.qr-modal.open { display: flex; }
.qr-modal-box { background: #fff; border-radius: var(--radius); padding: 1.5rem; text-align: center; max-width: 92vw; box-shadow: var(--shadow-lg); }
.qr-modal-box img { width: min(70vh, 460px); max-width: 100%; height: auto; image-rendering: pixelated; }
.qr-modal-title { font-family: var(--font-head); font-weight: 700; color: var(--heading); margin: 0 0 1rem; }
.qr-modal-hint { color: var(--muted); font-size: 0.85rem; margin: 1rem 0; }
.qr-modal-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.settings-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.2rem; }

.footer { text-align: center; color: var(--muted); font-size: 0.78rem; padding: 1.3rem; border-top: 1px solid var(--border); background: var(--card); }

/* ============ Griglia "come Google" (anagrafiche) ============ */
.grid-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 220px); background: var(--card); box-shadow: var(--shadow); }
.grid-table { border-collapse: separate; border-spacing: 0; font-size: 0.82rem; }
.grid-table th, .grid-table td { border-right: 1px solid var(--border); border-bottom: 1px solid #f0f0f0; padding: 0.35rem 0.5rem; white-space: nowrap; vertical-align: top; text-align: left; }
.grid-table thead th { position: sticky; top: 0; z-index: 3; background: var(--primary); color: #fff; font-family: var(--font-head); font-weight: 500; font-size: 0.76rem; }
.grid-table thead th.g-derived { background: #6b6d70; }
.grid-table .g-sticky { position: sticky; left: 0; z-index: 2; background: #fafafa; box-shadow: 1px 0 0 var(--border); }
.grid-table thead .g-sticky { z-index: 4; background: var(--primary-dark); }
.grid-table tbody tr:nth-child(even) td { background: #fbfbfb; }
.grid-table tbody tr:nth-child(even) .g-sticky { background: #f3f3f3; }
.g-cell { cursor: text; min-width: 90px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.g-cell:hover { background: #fff7e6; box-shadow: inset 0 0 0 1px #f0c36d; }
.g-cell.g-derived { cursor: not-allowed; color: var(--muted); background: #f4f4f4 !important; box-shadow: inset 0 0 0 1px #e6e6e6; }
.g-cell input[type="checkbox"] { display: inline-block; margin: 0; cursor: pointer; }
.g-cell.g-bool { text-align: center; font-weight: 700; font-size: 1.1rem; color: var(--ok); }
.g-cell input, .g-cell select, .g-cell textarea { min-width: 120px; width: 100%; box-shadow: 0 0 0 2px rgba(0,149,235,0.25); }
.g-cell.saved { box-shadow: inset 0 0 0 2px var(--ok) !important; }
.g-cell.err { box-shadow: inset 0 0 0 2px var(--err) !important; }
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 3.4rem; color: var(--primary); }
