/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; background: #f1f5f9; color: #1e293b; }
a { color: #3b82f6; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== LAYOUT ===== */
.app-wrapper { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 230px; min-height: 100vh;
  background: #0f172a;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  transition: transform .25s;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon { font-size: 28px; color: #3b82f6; }
.brand-name { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .3px; }
.brand-sub  { color: #64748b; font-size: 11px; margin-top: 1px; }
.sidebar-nav { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 18px; color: #94a3b8; font-size: 14px;
  border-left: 3px solid transparent; transition: all .15s;
}
.sidebar-nav li a:hover { color: #e2e8f0; background: rgba(255,255,255,.05); text-decoration: none; }
.sidebar-nav li a.active { color: #fff; background: rgba(59,130,246,.15); border-left-color: #3b82f6; }
.sidebar-nav li a i { font-size: 17px; }
.sidebar-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.07);
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: #3b82f6; color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { color: #e2e8f0; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: #64748b; font-size: 11px; }
.logout-btn { color: #64748b; font-size: 19px; transition: color .15s; }
.logout-btn:hover { color: #ef4444; text-decoration: none; }

/* ===== MAIN CONTENT ===== */
.main-content { margin-left: 230px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: #fff; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px; height: 56px;
}
.sidebar-toggle { background: none; border: none; font-size: 22px; cursor: pointer; color: #64748b; display: none; }
.page-title { font-size: 17px; font-weight: 700; color: #1e293b; flex: 1; }
.topbar-date { font-size: 13px; color: #94a3b8; }
.page-body { padding: 26px 28px; flex: 1; }

/* ===== STATS GRID ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat-card {
  background: #fff; border-radius: 12px;
  padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 21px; flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: #3b82f6; }
.stat-icon.green  { background: #f0fdf4; color: #22c55e; }
.stat-icon.orange { background: #fff7ed; color: #f97316; }
.stat-icon.red    { background: #fef2f2; color: #ef4444; }
.stat-icon.purple { background: #faf5ff; color: #a855f7; }
.stat-icon.teal   { background: #f0fdfa; color: #14b8a6; }
.stat-value { font-size: 26px; font-weight: 800; color: #1e293b; line-height: 1; }
.stat-label { font-size: 12px; color: #64748b; margin-top: 3px; }

/* ===== CARDS ===== */
.card { background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: none; }
.card-header {
  padding: 14px 20px; background: transparent;
  border-bottom: 1px solid #f1f5f9;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 14px; color: #334155;
}
.card-body { padding: 20px; }

/* ===== TABLES ===== */
.table-wrap { background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.table-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid #f1f5f9;
}
.table { margin: 0; font-size: 13.5px; }
.table thead th {
  background: #f8fafc; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: #64748b;
  border-bottom: 2px solid #e2e8f0; padding: 11px 14px; white-space: nowrap;
}
.table tbody td { padding: 11px 14px; vertical-align: middle; border-color: #f1f5f9; }
.table tbody tr:hover { background: #f8fafc; }
.table-footer { padding: 10px 18px; border-top: 1px solid #f1f5f9; font-size: 12px; color: #94a3b8; }

/* ===== BADGES ===== */
.badge-stato {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
}
.badge-aperta      { background: #e0f2fe; color: #0369a1; }
.badge-lavorazione { background: #fef9c3; color: #854d0e; }
.badge-attesa      { background: #fce7f3; color: #9d174d; }
.badge-completata  { background: #dcfce7; color: #166534; }
.badge-consegnata  { background: #f1f5f9; color: #475569; }

.badge-prio { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11.5px; font-weight: 600; }
.prio-normale { background: #f1f5f9; color: #475569; }
.prio-urgente { background: #fef3c7; color: #92400e; }
.prio-critica { background: #fee2e2; color: #991b1b; }

/* ===== BUTTONS ===== */
.btn-icon { padding: 5px 9px; font-size: 14px; line-height: 1; border-radius: 6px; }
.btn-sm { font-size: 12px; }

/* ===== FORMS ===== */
.form-section { background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 22px; }
.form-section-header {
  padding: 14px 20px; border-bottom: 1px solid #f1f5f9;
  font-weight: 700; font-size: 14px; color: #334155;
  display: flex; align-items: center; gap: 8px;
}
.form-section-body { padding: 20px; }
.form-label { font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.form-control, .form-select {
  font-size: 13.5px; border-color: #d1d5db; border-radius: 8px;
  padding: 8px 12px; transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ===== DETAIL SECTIONS ===== */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.detail-item {}
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #94a3b8; font-weight: 600; margin-bottom: 3px; }
.detail-value { font-size: 14px; color: #1e293b; font-weight: 500; }

/* ===== INTERVENTO CARD ===== */
.intervento-card {
  border: 1px solid #e2e8f0; border-radius: 10px;
  margin-bottom: 16px; overflow: hidden;
}
.intervento-header {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid #e2e8f0;
}
.intervento-title { font-weight: 700; font-size: 14px; color: #1e293b; flex: 1; }
.intervento-body { padding: 16px; }
.intervento-desc { font-size: 13.5px; color: #374151; margin-bottom: 14px; }
.intervento-meta { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12.5px; color: #64748b; margin-bottom: 14px; }
.intervento-meta span { display: flex; align-items: center; gap: 5px; }

/* ===== RICAMBI TABLE ===== */
.ricambi-table { font-size: 13px; width: 100%; border-collapse: collapse; }
.ricambi-table th { background: #f8fafc; padding: 7px 10px; text-align: left; font-size: 11px; text-transform: uppercase; color: #64748b; border-bottom: 1px solid #e2e8f0; }
.ricambi-table td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; }
.ricambi-table tr:last-child td { border-bottom: none; }

/* ===== COST SUMMARY ===== */
.cost-summary {
  background: #f8fafc; border-radius: 8px; padding: 16px;
  font-size: 13.5px;
}
.cost-row { display: flex; justify-content: space-between; padding: 4px 0; }
.cost-row.total { font-size: 16px; font-weight: 800; color: #1e293b; border-top: 2px solid #e2e8f0; margin-top: 8px; padding-top: 10px; }

/* ===== TIMELINE ===== */
.timeline { list-style: none; padding: 0; }
.timeline-item { display: flex; gap: 14px; padding-bottom: 18px; position: relative; }
.timeline-item::before { content: ''; position: absolute; left: 14px; top: 28px; bottom: 0; width: 2px; background: #e2e8f0; }
.timeline-item:last-child::before { display: none; }
.timeline-dot { width: 28px; height: 28px; border-radius: 50%; background: #e2e8f0; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; z-index: 1; }
.timeline-dot.blue   { background: #dbeafe; color: #2563eb; }
.timeline-dot.green  { background: #dcfce7; color: #16a34a; }
.timeline-dot.orange { background: #ffedd5; color: #ea580c; }
.timeline-content { flex: 1; }
.timeline-date { font-size: 11px; color: #94a3b8; }

/* ===== ALERTS ===== */
.alert { border-radius: 10px; border: none; font-size: 13.5px; }
.alert-success { background: #f0fdf4; color: #166534; }
.alert-danger  { background: #fef2f2; color: #991b1b; }
.alert-warning { background: #fefce8; color: #854d0e; }

/* ===== LOGIN PAGE ===== */
.login-wrapper {
  min-height: 100vh; background: #0f172a;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: #1e293b; border-radius: 16px;
  padding: 40px 36px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo i { font-size: 44px; color: #3b82f6; }
.login-logo h1 { color: #f1f5f9; font-size: 20px; font-weight: 800; margin-top: 10px; }
.login-logo p { color: #64748b; font-size: 13px; margin-top: 4px; }
.login-card .form-label { color: #94a3b8; }
.login-card .form-control {
  background: #0f172a; border-color: #334155; color: #f1f5f9;
  padding: 10px 14px; font-size: 14px;
}
.login-card .form-control:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.2); background: #0f172a; color: #f1f5f9; }
.login-card .form-control::placeholder { color: #475569; }

/* ===== MODALS ===== */
.modal-content { border-radius: 12px; border: none; }
.modal-header { border-bottom: 1px solid #f1f5f9; padding: 16px 20px; }
.modal-footer { border-top: 1px solid #f1f5f9; padding: 14px 20px; }
.modal-title { font-size: 15px; font-weight: 700; }

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-body { padding: 0 !important; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .page-body { padding: 18px 16px; }
  .topbar { padding: 0 16px; }
}
