/* ============================================================
   DOTLINE — Stylesheet
   Font: DM Sans + DM Mono
   Aesthetic: industrial-minimal, precision manufacturing
   ============================================================ */

/* ---- RESET & VARIABLES ----------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #1d3557;
  --brand-light:  #e8ecf1;
  --accent:       #2563eb;

  --ok:           #16a34a;
  --ok-bg:        #dcfce7;
  --warn:         #d97706;
  --warn-bg:      #fef3c7;
  --err:          #dc2626;
  --err-bg:       #fee2e2;
  --muted:        #64748b;

  --stato-attesa:      #94a3b8;
  --stato-lavorazione: #f59e0b;
  --stato-completato:  #22c55e;

  --bg:           #f1f4f8;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-dark:  #cbd5e1;
  --text:         #1e293b;
  --text-2:       #475569;
  --text-3:       #94a3b8;

  --sidebar-w:    220px;
  --topbar-h:     60px;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 12px rgba(0,0,0,.08);

  --font:         'DM Sans', system-ui, sans-serif;
  --font-mono:    'DM Mono', 'Courier New', monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---- TOPBAR ---------------------------------------------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-nome {
  font-size: .95rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -.01em;
}
.brand-tag {
  font-size: .75rem;
  color: var(--text-3);
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.notif-btn {
  position: relative;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .15s;
}
.notif-btn:hover { background: var(--bg); }
.notif-btn svg { width: 20px; height: 20px; }
.notif-badge {
  position: absolute;
  top: 4px; right: 4px;
  background: var(--err);
  color: #fff;
  font-size: .65rem;
  font-weight: 600;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; }
.user-nome { font-size: .85rem; font-weight: 500; line-height: 1.2; }
.user-ruolo { font-size: .75rem; color: var(--text-3); }

/* ---- LAYOUT ---------------------------------------------- */
.layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* ---- SIDEBAR --------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-2);
  transition: background .12s, color .12s;
  margin-bottom: 2px;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active {
  background: var(--brand-light);
  color: var(--brand);
}
.sidebar-spacer { flex: 1; }
.nav-logout { color: var(--muted); }
.nav-logout:hover { background: var(--err-bg); color: var(--err); }

.nav-badge {
  margin-left: auto;
  background: var(--err);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
}

/* ---- MAIN CONTENT ---------------------------------------- */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px;
  max-width: 1200px;
}

/* ---- PAGE HEADER ----------------------------------------- */
.page-header {
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.02em;
}
.page-header p {
  font-size: .875rem;
  color: var(--text-3);
  margin-top: 2px;
}
.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-header-row h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -.02em;
}

/* ---- SEARCH + FILTERS ------------------------------------ */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-3);
  pointer-events: none;
}
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--accent); }

/* ---- ORDINE CARD ----------------------------------------- */
.ordine-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}
.ordine-card:hover { box-shadow: var(--shadow); }

.ordine-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}
.ordine-toggle-icon {
  color: var(--text-3);
  transition: transform .2s;
  flex-shrink: 0;
}
.ordine-toggle-icon svg { width: 18px; height: 18px; }
.ordine-card.is-open .ordine-toggle-icon { transform: rotate(0deg); }
.ordine-card:not(.is-open) .ordine-toggle-icon { transform: rotate(-90deg); }

.ordine-codice {
  font-family: var(--font-mono);
  font-size: .85rem;
  font-weight: 500;
  color: var(--brand);
  white-space: nowrap;
}
.ordine-descrizione {
  font-size: .95rem;
  font-weight: 500;
  flex: 1;
}
.ordine-dates {
  display: flex;
  gap: 24px;
  flex-shrink: 0;
}
.ordine-date-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.ordine-date-label {
  font-size: .7rem;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ordine-date-val {
  font-size: .875rem;
  font-weight: 500;
}
.ordine-azienda-tag {
  font-size: .78rem;
  color: var(--text-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}

/* Status dot on order */
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-ok      { background: var(--ok); }
.dot-warning { background: var(--warn); }
.dot-error   { background: var(--err); }

/* ---- PROGRESS BAR ---------------------------------------- */
.progress-bar-wrap {
  padding: 0 20px;
  margin-bottom: 0;
}
.progress-bar {
  display: flex;
  height: 28px;
  overflow: hidden;
  font-size: .75rem;
  font-weight: 600;
  color: #fff;
}
.progress-bar .seg {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width .3s;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
.seg-attesa      { background: var(--stato-attesa); }
.seg-lavorazione { background: var(--stato-lavorazione); }
.seg-completato  { background: var(--stato-completato); }
.seg:first-child { border-radius: 4px 0 0 4px; }
.seg:last-child  { border-radius: 0 4px 4px 0; }
.seg:only-child  { border-radius: 4px; }

/* ---- COMPONENTI TABLE ------------------------------------ */
.componenti-panel {
  display: none;
  padding: 0 20px 20px;
}
.ordine-card.is-open .componenti-panel { display: block; }

.componenti-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: .875rem;
}
.componenti-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.componenti-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.componenti-table tr:last-child td { border-bottom: none; }
.componenti-table tr:hover td { background: var(--bg); }

.cod-cell {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-2);
}

/* Stato pill */
.stato-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
}
.stato-pill .dot { width: 7px; height: 7px; }
.stato-attesa      .dot { background: var(--stato-attesa); }
.stato-lavorazione .dot { background: var(--stato-lavorazione); }
.stato-completato  .dot { background: var(--stato-completato); }

.stato-attesa      { background: #f1f5f9; color: var(--text-2); }
.stato-lavorazione { background: var(--warn-bg); color: #92400e; }
.stato-completato  { background: var(--ok-bg); color: #166534; }

/* Warning indicator */
.warn-icon {
  display: inline-block;
  color: var(--warn);
  font-size: .75rem;
  font-weight: 600;
  margin-left: 6px;
}

/* ---- ORDINE DETAIL PAGE ---------------------------------- */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: 16px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-3); }
.info-val { font-weight: 500; }

.log-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.log-item:last-child { border-bottom: none; }
.log-ts {
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-3);
  white-space: nowrap;
  min-width: 120px;
}
.log-origine {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-3);
  border: 1px solid var(--border);
}

/* ---- SEZIONE ORDINI CONCLUSI ----------------------------- */
.section-conclusi {
  margin-top: 32px;
}
.section-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 0;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  margin-bottom: 16px;
}
.section-toggle-btn svg { width: 18px; height: 18px; transition: transform .2s; }
.section-toggle-btn.open svg { transform: rotate(90deg); }
#conclusi-content { display: none; }
#conclusi-content.visible { display: block; }

.load-more-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px dashed var(--border-dark);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-2);
  cursor: pointer;
  text-align: center;
  transition: background .15s;
}
.load-more-btn:hover { background: var(--bg); }
.load-more-btn:disabled { opacity: .5; cursor: default; }

/* ---- FORNITORE CLIENTI PAGE ------------------------------ */
.clienti-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.clienti-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.clienti-table th {
  background: var(--bg);
  padding: 12px 16px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.clienti-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.clienti-table tr:last-child td { border-bottom: none; }
.clienti-table tr:hover td { background: var(--bg); }

.badge-ruolo {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--brand-light);
  color: var(--brand);
}
.badge-ruolo.op { background: #ede9fe; color: #5b21b6; }
.badge-ruolo.sl { background: var(--bg); color: var(--muted); }

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.action-btn:hover { background: var(--bg); border-color: var(--border-dark); }
.action-btn.danger { color: var(--err); }
.action-btn.danger:hover { background: var(--err-bg); border-color: var(--err); }
.action-btn svg { width: 13px; height: 13px; }

/* ---- MODALI ---------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 480px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 20px;
}
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
}

/* ---- FORM ELEMENTI --------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.form-input,
.form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ---- BOTTONI --------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  text-decoration: none;
}
.btn:hover { opacity: .88; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--err); color: #fff; }
.btn svg { width: 16px; height: 16px; }

/* ---- LOGIN PAGE ------------------------------------------ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 400px;
  max-width: 100%;
  box-shadow: var(--shadow);
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-brand .nome {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--brand);
}
.login-brand .tagline {
  font-size: .8rem;
  color: var(--text-3);
}
.login-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 24px;
  text-align: center;
}
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 16px;
}
.alert-err  { background: var(--err-bg); color: var(--err); border-left: 3px solid var(--err); }
.alert-ok   { background: var(--ok-bg);  color: var(--ok);  border-left: 3px solid var(--ok); }
.alert-warn { background: var(--warn-bg);color: #92400e;    border-left: 3px solid var(--warn); }

/* ---- EMPTY STATE ----------------------------------------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}
.empty-state svg {
  width: 48px; height: 48px;
  opacity: .3;
  margin-bottom: 12px;
}
.empty-state p { font-size: .95rem; }

/* ---- PAGE FOOTER ----------------------------------------- */
.page-footer {
  margin-left: var(--sidebar-w);
  padding: 16px 32px;
  font-size: .75rem;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  background: var(--surface);
}

/* ---- SPINNER --------------------------------------------- */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- NOTIFICHE ------------------------------------------- */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: background .1s;
}
.notif-item.non-letta { border-left: 3px solid var(--accent); }
.notif-item.priorita-alta { border-left-color: var(--err); }
.notif-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.notif-icon svg { width: 16px; height: 16px; }
.notif-body { flex: 1; }
.notif-titolo { font-size: .875rem; font-weight: 500; }
.notif-msg { font-size: .82rem; color: var(--text-2); margin-top: 2px; }
.notif-ts { font-size: .75rem; color: var(--text-3); margin-top: 4px; }

/* ---- RESPONSIVE ------------------------------------------ */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .ordine-dates { display: none; }
}
@media (max-width: 720px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 20px 16px; }
  .page-footer { margin-left: 0; }
}
