:root {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --ink: #0F172A;
  --ink-soft: #334155;
  --muted: #64748B;
  --line: #E5E9F0;
  --nav: #0F172A;
  --nav-2: #1E293B;

  --accent: #F26B21;
  --accent-hover: #DB5A12;
  --accent-soft: #FFF1E8;

  --ok: #15803D;      --ok-soft: #E8F7EE;
  --warn: #B45309;    --warn-soft: #FEF3E2;
  --danger: #B91C1C;  --danger-soft: #FDECEC;
  --info: #1D4ED8;    --info-soft: #EAF1FE;

  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 6px 20px rgba(15,23,42,.05);
  --shadow-pop: 0 20px 50px rgba(15,23,42,.25);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============ Layout ============ */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ============ Sidebar ============ */
.sidebar {
  width: 252px;
  background: var(--nav);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .marca { display: flex; align-items: center; gap: 12px; padding: 4px 8px 20px; }
.logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #FF8A3D, #F26B21);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; color: #fff; flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(242,107,33,.35);
}
.sidebar .marca b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.sidebar .marca small { display: block; font-size: 11.5px; color: #94A3B8; margin-top: 1px; }

.nav-titulo {
  font-size: 10.5px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase;
  color: #64748B; padding: 16px 12px 6px;
}
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  color: #CBD5E1; text-decoration: none;
  padding: 10px 12px; margin: 2px 0;
  font-size: 14px; font-weight: 500;
  border-radius: 10px;
  transition: background .15s, color .15s;
}
.sidebar nav a i { font-size: 19px; color: #94A3B8; transition: color .15s; }
.sidebar nav a:hover { background: var(--nav-2); color: #fff; }
.sidebar nav a:hover i { color: #fff; }
.sidebar nav a.activo { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(242,107,33,.3); }
.sidebar nav a.activo i { color: #fff; }

.usuario-box {
  margin-top: auto; padding: 12px; border-radius: 12px; background: var(--nav-2);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #334155; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.usuario-box .datos { flex: 1; min-width: 0; }
.usuario-box .datos b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usuario-box .datos small { color: #94A3B8; font-size: 11.5px; text-transform: capitalize; }
.usuario-box .salir { background: none; border: none; color: #94A3B8; cursor: pointer; font-size: 19px; padding: 6px; border-radius: 8px; }
.usuario-box .salir:hover { color: #fff; background: #334155; }

/* ============ Topbar (móvil) ============ */
.topbar {
  display: none; align-items: center; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 12px 16px; position: sticky; top: 0; z-index: 20;
}
.topbar .menu-btn { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--ink); padding: 4px; display: flex; }
.topbar .logo { width: 30px; height: 30px; font-size: 17px; border-radius: 9px; box-shadow: none; }
.topbar b { font-size: 15px; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 30; }

/* ============ Contenido ============ */
.contenido { flex: 1; padding: 32px 36px 48px; max-width: 1280px; width: 100%; }
.contenido h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin: 0 0 4px; }
.contenido .subt { color: var(--muted); margin: 0 0 26px; font-size: 14.5px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ============ Tarjetas métricas ============ */
.card {
  background: var(--surface); border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
}
.card .ico {
  width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; margin-bottom: 10px; background: var(--surface-2); color: var(--ink-soft);
}
.card .ico.naranja { background: var(--accent-soft); color: var(--accent); }
.card .ico.verde { background: var(--ok-soft); color: var(--ok); }
.card .ico.rojo { background: var(--danger-soft); color: var(--danger); }
.card .ico.ambar { background: var(--warn-soft); color: var(--warn); }
.card .ico.azul { background: var(--info-soft); color: var(--info); }
.card h3 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.card .num { font-size: 30px; font-weight: 700; letter-spacing: -1px; font-family: var(--font); line-height: 1.15; }
.card .num.accent { color: var(--accent); }
.card .num.warn { color: var(--warn); }
.card .num.danger { color: var(--danger); }
.card .nota { font-size: 12.5px; color: var(--muted); }

/* ============ Paneles ============ */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-header h2 { font-size: 16.5px; font-weight: 600; margin: 0; letter-spacing: -.2px; }
.acciones-barra { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.acciones-barra select { width: auto; min-width: 190px; padding: 8px 12px; }

/* ============ Tablas ============ */
.tabla-wrap { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .6px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
th:first-child { border-radius: 10px 0 0 10px; }
th:last-child { border-radius: 0 10px 10px 0; }
td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
td .acciones { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.codigo {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft);
  background: var(--surface-2); padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line);
}
.sub { display: block; font-size: 12.5px; color: var(--muted); }

/* ============ Badges ============ */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.disponible, .badge.devuelto, .badge.activo, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.prestado, .badge.asignado, .badge.info { background: var(--accent-soft); color: var(--accent-hover); }
.badge.mantenimiento, .badge.taller, .badge.warn, .badge.bajo { background: var(--warn-soft); color: var(--warn); }
.badge.dañado, .badge.dano, .badge.vencido, .badge.perdido, .badge.baja, .badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ============ Barras de stock ============ */
.stock { min-width: 150px; }
.stock .fila { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; gap: 10px; }
.stock .fila b { font-weight: 600; }
.stock .fila span { color: var(--muted); font-size: 12px; }
.barra { height: 8px; background: #EDF0F5; border-radius: 99px; overflow: hidden; }
.barra > span { display: block; height: 100%; border-radius: 99px; background: var(--ok); transition: width .4s; }
.barra > span.warn { background: #F59E0B; }
.barra > span.danger { background: #EF4444; }

/* ============ Botones ============ */
button, .btn {
  font-family: var(--font); font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, box-shadow .15s, transform .05s; white-space: nowrap;
}
button:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(242,107,33,.28); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secundario { background: var(--surface); border-color: var(--line); color: var(--ink-soft); }
.btn-secundario:hover { background: var(--surface-2); border-color: #CBD5E1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }

/* ============ Formularios ============ */
input, select, textarea {
  font-family: var(--font); font-size: 14.5px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 10px; width: 100%;
  background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(242,107,33,.15);
}
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }
.campo { margin-bottom: 16px; }
.fila-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ============ Modal ============ */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 20px; padding: 28px;
  width: 460px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-pop);
}
.modal h2 { margin: 0 0 6px; font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
.modal .ayuda { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; }
.modal .acciones { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ============ Alertas / vacío ============ */
.vacio { text-align: center; color: var(--muted); padding: 36px 10px; font-size: 14px; }
.vacio i { display: block; font-size: 34px; margin-bottom: 8px; color: #CBD5E1; }
.alerta { padding: 12px 16px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px; font-weight: 500; }
.alerta.danger { background: var(--danger-soft); color: var(--danger); }
.alerta.warn { background: var(--warn-soft); color: var(--warn); }
.alerta.ok { background: var(--ok-soft); color: var(--ok); }

/* ============ Login ============ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #1E3A5F 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 110%, #7C2D12 0%, transparent 55%), var(--nav);
}
.login-card { background: var(--surface); border-radius: 22px; padding: 40px 36px; width: 400px; max-width: 100%; box-shadow: var(--shadow-pop); }
.login-card .logo { margin-bottom: 20px; width: 48px; height: 48px; font-size: 26px; }
.login-card h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.5px; }
.login-card .subt { color: var(--muted); font-size: 14px; margin: 0 0 26px; }

/* ============ Responsive ============ */
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .25s;
  }
  .sidebar.abierto { transform: translateX(0); }
  .overlay.abierto { display: block; }
  .topbar { display: flex; }
  .contenido { padding: 22px 16px 40px; }
  .contenido h1 { font-size: 22px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .fila-campos { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr 1fr; } .card { padding: 14px; } .card .num { font-size: 24px; } }
