@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-soft: #f8fafc;
  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;

  --status-ready: #10b981;
  --status-pending: #f59e0b;
  --status-urgent: #ef4444;
  --status-info: #3b82f6;
  --status-purple: #8b5cf6;

  --sidebar-width: 252px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;

  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.06);
  --shadow-md: 0 8px 24px -6px rgb(15 23 42 / 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: #1e3a8a;
  --bg-main: #0b1220;
  --bg-card: #111a2e;
  --bg-soft: #0f172a;
  --sidebar-bg: #070d1a;
  --border: #1f2a44;
  --text-main: #e5e7eb;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
}

* { box-sizing: border-box; padding: 0; margin: 0; }

html, body {
  min-height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background-color: var(--bg-main);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }

/* ------------------------------------------------------------ Layout */
.app-container { display: flex; min-height: 100vh; }

.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.page { padding: var(--space-lg); flex: 1; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--space-md);
  padding: 12px var(--space-lg);
  background: color-mix(in srgb, var(--bg-card) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .crumb { font-weight: 600; font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar .search { position: relative; width: 320px; max-width: 40vw; }
.topbar .search input { padding-left: 34px; background: var(--bg-soft); }
.topbar .search span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .55; }
.icon-btn { width: 36px; height: 36px; border-radius: var(--radius-md); border: 1px solid var(--border); display: grid; place-items: center; background: var(--bg-card); }
.icon-btn:hover { background: var(--bg-soft); }
.menu-toggle { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-md); margin-bottom: var(--space-lg); flex-wrap: wrap; }
.page-head h1, .title-lg { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.title-lg { margin-bottom: var(--space-lg); }
.page-head p { color: var(--text-muted); margin-top: 2px; }
.actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  height: 100vh;
  position: fixed; left: 0; top: 0;
  display: flex; flex-direction: column;
  padding: var(--space-md) 12px;
  z-index: 100;
  overflow-y: auto;
  transition: transform .2s;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #60a5fa, #2563eb); display: grid; place-items: center; font-size: 19px; box-shadow: 0 6px 16px rgb(37 99 235 / .45); }
.brand b { font-size: 16px; letter-spacing: -.01em; display: block; line-height: 1.1; }
.brand small { font-size: 10px; opacity: .55; letter-spacing: 1.6px; text-transform: uppercase; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px; opacity: .45; padding: 14px 12px 6px; font-weight: 700; }
.sidebar-link { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-md); color: var(--sidebar-text); transition: background .15s; font-weight: 500; margin-bottom: 2px; }
.sidebar-link .ico { width: 22px; text-align: center; font-size: 16px; }
.sidebar-link:hover { background: var(--sidebar-hover); }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 6px 14px rgb(37 99 235 / .35); }
.sidebar-link .pill { margin-left: auto; font-size: 11px; font-weight: 700; background: #ef4444; color: #fff; border-radius: 20px; padding: 1px 7px; }
.sidebar-user { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--sidebar-hover); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #6366f1); display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.sidebar-user small { opacity: .55; display: block; font-size: 11px; text-transform: capitalize; }

/* ------------------------------------------------------------ Components */
.card { background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: var(--space-md); box-shadow: var(--shadow-sm); }
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: var(--space-md); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-md); gap: 8px; }
.card-head h2 { margin: 0; }

.grid { display: grid; gap: var(--space-md); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-main { grid-template-columns: 2fr 1fr; }
.mb { margin-bottom: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-md); }

.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { font-size: 12px; margin-top: 2px; color: var(--text-muted); }
.kpi .ico { position: absolute; right: 14px; top: 12px; font-size: 26px; opacity: .18; }
.up { color: var(--status-ready) !important; }
.down { color: var(--status-urgent) !important; }

.text-sm { font-size: 13px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.center { text-align: center; }
.bold { font-weight: 700; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* Buttons */
.btn, .btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-md); font-weight: 600; font-size: 13.5px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-main);
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: #d1fae5; color: #047857; border-color: #a7f3d0; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.link { color: var(--primary); font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--status-urgent); font-weight: 600; font-size: 13px; }

/* Forms */
.form-input, select.form-input, textarea.form-input {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-md);
  border: 1px solid var(--border); font-family: inherit; font-size: 14px;
  background: var(--bg-card); color: var(--text-main); outline: none;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
label.lbl { font-size: 12px; font-weight: 700; display: block; margin-bottom: 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.form-grid { display: grid; gap: var(--space-md); grid-template-columns: repeat(2, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.filters { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: end; }
.filters > div { min-width: 140px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 14px; color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; text-align: left; font-weight: 700; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg-soft); }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
td.empty { text-align: center; color: var(--text-muted); padding: 32px; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #047857; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
[data-theme="dark"] .badge-gray { background: #1e293b; color: #cbd5e1; }
[data-theme="dark"] .badge-blue { background: #1e3a8a; color: #bfdbfe; }
[data-theme="dark"] .badge-green { background: #064e3b; color: #a7f3d0; }
[data-theme="dark"] .badge-amber { background: #78350f; color: #fde68a; }
[data-theme="dark"] .badge-red { background: #7f1d1d; color: #fecaca; }
[data-theme="dark"] .badge-purple { background: #4c1d95; color: #ddd6fe; }

/* Alerts / flash */
.alert { padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: var(--space-md); font-weight: 500; border: 1px solid; }
.alert-ok { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-warn { background: #fef3c7; color: #92400e; border-color: #fde68a; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-md); overflow-x: auto; }
.tab { padding: 10px 16px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text-main); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal { width: 560px; max-width: 100%; max-height: 92vh; overflow-y: auto; padding: var(--space-lg); }
.modal h2 { font-size: 18px; margin-bottom: var(--space-md); }
.modal-actions { display: flex; gap: var(--space-sm); margin-top: var(--space-lg); justify-content: flex-end; }

/* Charts (CSS only, sin librerías) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .bar { width: 100%; max-width: 38px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #60a5fa, var(--primary)); min-height: 3px; transition: opacity .15s; }
.bars .col:hover .bar { opacity: .8; }
.bars .lbl2 { font-size: 10.5px; color: var(--text-muted); margin-top: 6px; white-space: nowrap; }
.bars .val { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; white-space: nowrap; }
.hbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.hbar .name { width: 150px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { flex: 1; height: 10px; background: var(--bg-main); border-radius: 10px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 10px; background: linear-gradient(90deg, #60a5fa, var(--primary)); }
.hbar .amt { width: 110px; text-align: right; font-weight: 700; font-size: 13px; }

/* Kanban */
.kanban { display: flex; gap: var(--space-md); overflow-x: auto; padding-bottom: var(--space-md); align-items: flex-start; }
.k-col { min-width: 270px; width: 270px; background: color-mix(in srgb, var(--border) 55%, transparent); border-radius: var(--radius-lg); padding: 10px; }
.k-col.over { outline: 2px dashed var(--primary); }
.k-col h3 { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; }
.k-card { cursor: grab; margin-bottom: 8px; padding: 12px; }
.k-card.dragging { opacity: .4; }

/* Factura imprimible */
.invoice { max-width: 860px; margin: 0 auto; padding: 36px; background: #fff; color: #0f172a; }
.invoice table th { color: #475569; }
.invoice td, .invoice th { border-bottom: 1px solid #e2e8f0; }
.stamp { display: inline-block; border: 3px solid #b91c1c; color: #b91c1c; font-weight: 800; padding: 4px 16px; transform: rotate(-8deg); font-size: 22px; letter-spacing: 3px; border-radius: 6px; }

/* Login */
.login-bg { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #1d4ed8 0, transparent 45%), radial-gradient(circle at 80% 80%, #7c3aed 0, transparent 40%), #0b1220; }

@media (max-width: 1100px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-main, .grid-cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: grid; }
  .grid-cols-4, .grid-cols-2, .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .topbar .search { display: none; }
  .page { padding: var(--space-md); }
}

@media print {
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page { padding: 0 !important; }
  body { background: #fff !important; }
  .invoice { padding: 0; max-width: none; box-shadow: none; border: none; }
  .card { box-shadow: none; }
}

/* ------------------------------------------------------------ Inspección gráfica del vehículo */
.insp-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr); gap: var(--space-md); align-items: start; }
#vehiculoSvg { width: 100%; height: auto; display: block; background: var(--bg-soft); border-radius: var(--radius-md); border: 1px solid var(--border); }
#vehiculoSvg .base { fill: var(--bg-card); stroke: #94a3b8; stroke-width: 1.5; }
#vehiculoSvg .vlabel { font: 600 13px Inter, sans-serif; fill: var(--text-muted); }
.zona { fill: rgba(148, 163, 184, .18); stroke: #64748b; stroke-width: 1.1; cursor: pointer; transition: fill .12s, stroke-width .12s; }
.zona:hover, .zona.hover { fill: color-mix(in srgb, var(--primary) 35%, transparent); }
.zona.sel { stroke: var(--text-main); stroke-width: 2.6; }
.zona.marcada { stroke: var(--text-main); }
g.zona { fill: none; stroke: none; }
g.zona .llanta { fill: #475569; stroke: #1e293b; stroke-width: 1.2; transition: fill .12s; }
g.zona .eje { fill: #cbd5e1; pointer-events: none; }
g.zona:hover .llanta, g.zona.hover .llanta { stroke: var(--primary); stroke-width: 2.4; }
g.zona.sel .llanta { stroke: #fff; stroke-width: 2.6; }
.insp-lectura .zona { cursor: default; }
.insp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg-card); font-size: 12.5px; font-weight: 600; }
.chip:hover { background: var(--bg-soft); }
.chip.sel { outline: 2px solid var(--text-main); }
.insp-tipos { display: flex; flex-wrap: wrap; gap: 6px; }
.insp-tipos .tipo { padding: 5px 10px; border-radius: 20px; border: 2px solid var(--c); background: transparent; font-size: 12.5px; font-weight: 700; }
.insp-tipos .tipo.activo { background: var(--c); color: #fff; }
.insp-lista { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.insp-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-card); font-size: 13px; }
.insp-item .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; flex-shrink: 0; }
@media (max-width: 1100px) { .insp-grid { grid-template-columns: 1fr; } }
@media print { .insp-lista { max-height: none; } .zona:hover { fill: rgba(148, 163, 184, .18); } }
.insp-lectura .insp-grid { grid-template-columns: 1fr; }
