/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.brand-title { color: #f8fafc; font-size: 15px; font-weight: 700; line-height: 1.2; }
.brand-sub { color: var(--text-light); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: #94a3b8;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active { background: var(--primary); color: #fff; }

.sidebar-bottom {
  padding: 12px 10px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.btn-new {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  background: rgba(37,99,235,.25);
  border: 1px solid rgba(37,99,235,.4);
  border-radius: var(--radius);
  color: #93c5fd;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.btn-new svg { width: 15px; height: 15px; }
.btn-new:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Main ───────────────────────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

/* ── Page Header ────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.page-header-left { display: flex; align-items: center; gap: 12px; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--border); }
.btn-outline:hover { background: var(--primary-light); border-color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Filter Bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.search-box {
  position: relative;
}
.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #f8fafc;
  transition: all .15s;
}
.search-box input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.filters select,
.filters input[type="date"] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s;
}
.filters select:focus,
.filters input[type="date"]:focus { outline: none; border-color: var(--primary); }
.filter-sep { color: var(--border); font-size: 18px; }

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td { padding: 12px 14px; vertical-align: middle; }
.table-footer {
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.cell-ticket { font-weight: 700; font-size: 13px; color: var(--primary); font-family: monospace; letter-spacing: .02em; }
.cell-main { font-weight: 600; font-size: 13.5px; }
.cell-sub { font-size: 12px; color: var(--text-muted); display: block; margin-top: 1px; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-slate  { background: #f1f5f9; color: #475569; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }

/* ── States ─────────────────────────────────────────────────────────────────── */
.loading-state, .empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  gap: 12px;
}
.empty-state svg { width: 48px; height: 48px; opacity: .3; }
.empty-state p { font-size: 15px; }
.error-state { color: #dc2626; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-title svg { width: 14px; height: 14px; }

/* ── Detail View ────────────────────────────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.detail-ticket {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.detail-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } }

.info-list { display: flex; flex-direction: column; gap: 10px; }
.info-row { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.info-value { font-size: 14px; color: var(--text); }
.info-value.mono { font-family: monospace; font-size: 13.5px; }
.info-value.password { font-family: monospace; background: #f1f5f9; padding: 2px 8px; border-radius: 4px; display: inline-block; }

/* ── Form ───────────────────────────────────────────────────────────────────── */
.form-page { max-width: 780px; }
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}
.form-section-title svg { width: 15px; height: 15px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.form-group label .req { color: #ef4444; margin-left: 2px; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-group .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.form-group.full { grid-column: 1 / -1; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 20px;
}

/* ── Client search ──────────────────────────────────────────────────────────── */
.client-search-wrap { position: relative; }
.client-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}
.client-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s;
}
.client-dropdown-item:last-child { border-bottom: none; }
.client-dropdown-item:hover { background: var(--primary-light); }
.client-dropdown-item strong { display: block; font-size: 13.5px; }
.client-dropdown-item span { font-size: 12px; color: var(--text-muted); }
.client-dropdown-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

.selected-client-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 10px 14px;
  gap: 12px;
}
.selected-client-info strong { display: block; font-size: 14px; color: var(--text); }
.selected-client-info span { font-size: 12.5px; color: var(--text-muted); }

.or-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 12.5px;
}
.or-divider::before, .or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Back link ──────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
  transition: color .15s;
}
.back-link svg { width: 16px; height: 16px; }
.back-link:hover { color: var(--primary); }

/* ── Status select ──────────────────────────────────────────────────────────── */
.status-select-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Clients table ──────────────────────────────────────────────────────────── */
.client-repairs-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11.5px;
  font-weight: 700;
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: slideUp .2s ease;
  overflow: hidden;
}
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); line-height: 1; padding: 2px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Toasts ─────────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transform: translateX(110%);
  transition: transform .3s ease;
  max-width: 320px;
}
.toast.visible { transform: translateX(0); }
.toast-success { background: #16a34a; color: #fff; }
.toast-error   { background: #dc2626; color: #fff; }
.toast-info    { background: #2563eb; color: #fff; }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { width: 60px; min-width: 60px; }
  .brand-title, .brand-sub, .nav-link span, .sidebar-bottom { display: none; }
  .nav-link { justify-content: center; padding: 10px; }
  #main-content { padding: 16px; }
}

/* ── Preventivo ─────────────────────────────────────────────────────────────── */
.preventivo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.preventivo-table th {
  padding: 8px 10px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.preventivo-table td {
  padding: 6px 6px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.preventivo-table tbody tr:last-child td { border-bottom: none; }
.preventivo-table input,
.preventivo-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  transition: border-color .15s;
}
.preventivo-table input:focus,
.preventivo-table select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}
.preventivo-table .col-desc    { min-width: 160px; }
.preventivo-table .col-price   { width: 100px; }
.preventivo-table .col-gar     { width: 80px; }
.preventivo-table .col-note    { min-width: 110px; }
.preventivo-table .col-del     { width: 36px; text-align: center; }
.btn-del-riga {
  background: none;
  border: none;
  color: #f87171;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s;
}
.btn-del-riga:hover { background: #fee2e2; }
.preventivo-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 0;
  flex-wrap: wrap;
  gap: 10px;
}
.preventivo-totali {
  display: flex;
  gap: 20px;
  font-size: 13px;
}
.preventivo-totali span { color: var(--text-muted); }
.preventivo-totali strong { color: var(--text); }

/* View-only preventivo */
.preventivo-view {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.preventivo-view th {
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.preventivo-view td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.preventivo-view tbody tr:last-child td { border-bottom: none; }
.preventivo-view .tot-row td {
  font-weight: 700;
  background: #f8fafc;
  border-top: 2px solid var(--border);
}

/* Tecnici */
.tecnico-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.tecnico-card:last-child { border-bottom: none; }
.tecnico-card-info strong { font-size: 14px; }
.tecnico-card-info span { font-size: 12.5px; color: var(--text-muted); display: block; }
.tecnico-card-actions { display: flex; gap: 6px; }
.badge-inactive { background: #f3f4f6; color: #9ca3af; font-size: 11px; padding: 2px 7px; border-radius: 999px; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mt-4    { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.link    { color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--primary-dark); }
.mono    { font-family: monospace; }
