@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&display=swap');

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

:root {
  --sidebar-w:      240px;
  --sidebar-bg:     #0f172a;
  --sidebar-hover:  #1e293b;
  --sidebar-active: #2563eb;
  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --border:         #e2e8f0;
  --text-primary:   #0f172a;
  --text-secondary: #64748b;
  --text-muted:     #94a3b8;
  --accent:         #2563eb;
  --accent-hover:   #1d4ed8;
  --danger:         #ef4444;
  --danger-hover:   #dc2626;
  --success:        #22c55e;
  --warning:        #f59e0b;
  --radius:         10px;
  --radius-lg:      14px;
  --shadow:         0 1px 4px rgba(0,0,0,0.08);
  --shadow-lg:      0 8px 32px rgba(0,0,0,0.12);
  --font:           'IBM Plex Sans', Arial, sans-serif;
}

body {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
}

/* ============================
   SIDEBAR
============================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 12px 16px;
  z-index: 100;
  overflow-y: auto;
}

.sidebar .logo {
  width: 80px;
  margin-bottom: 28px;
  border-radius: 10px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.18s, color 0.18s;
  margin-bottom: 2px;
}

.sidebar a:hover  { background: var(--sidebar-hover); color: #f1f5f9; }
.sidebar a.active { background: var(--sidebar-active); color: #fff; }

.sidebar .icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
  opacity: 0.75;
}

.sidebar a:hover .icon,
.sidebar a.active .icon { opacity: 1; }

/* ============================
   MAIN CONTENT
============================ */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  width: 100%;
  min-height: 100vh;
}

/* ============================
   TOPBAR
============================ */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 20px; font-weight: 600; color: var(--text-primary); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.usuario-info { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

.notif-btn {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s;
}

.notif-btn:hover { background: var(--surface-2); }

#notifBadge {
  position: absolute;
  top: -5px; right: -5px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.notif-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  max-height: 380px;
  overflow-y: auto;
}

.notif-dropdown.open { display: block; }

/* ============================
   BOTONES
============================ */
button {
  background: var(--accent);
  border: none;
  color: white;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  transition: background 0.18s, transform 0.1s;
}

button:hover   { background: var(--accent-hover); }
button:active  { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-logout {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 7px 14px;
  font-size: 13px;
}

.btn-logout:hover { background: var(--danger); color: white; }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover { background: var(--surface-2); }

.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }

.btn-whatsapp { background: #16a34a; }
.btn-whatsapp:hover { background: #15803d; }

/* ============================
   SECTION HEADER
============================ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ============================
   DASHBOARD CARDS
============================ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(37,99,235,0.1); }

.card h3 {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.card p { font-size: 28px; font-weight: 600; color: var(--text-primary); }
.card.alerta p { color: var(--danger); }
.card.success p { color: #166534; }

.cards-sm {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.card-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-sm .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.card-sm .value       { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.card-sm .value.green { color: #166534; }
.card-sm .value.red   { color: #991b1b; }
.card-sm .value.blue  { color: #1e40af; }
.card-sm .value.amber { color: #92400e; }

/* ============================
   FORMULARIOS
============================ */
form {
  background: var(--surface);
  padding: 22px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  align-items: end;
}

form h2 {
  grid-column: 1 / -1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color 0.18s, box-shadow 0.18s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
input[type="hidden"] { display: none; }
form button[type="submit"] { height: 42px; align-self: end; }

/* ============================
   SEARCH BAR
============================ */
.search-bar {
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search-bar input  { max-width: 280px; }
.search-bar select { max-width: 180px; }

/* ============================
   MENSAJES
============================ */
.msg {
  display: none;
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
}

.msg-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.msg-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ============================
   TABLAS
============================ */
.table-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; min-width: 500px; }

thead th {
  background: var(--sidebar-bg);
  color: #e2e8f0;
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

tbody td {
  padding: 12px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody tr.stock-bajo td { color: var(--danger); }
tbody tr.stock-bajo { background: #fff5f5; }

/* ============================
   BOTONES EN TABLA
============================ */
td button {
  padding: 5px 10px;
  font-size: 12px;
  margin-right: 4px;
  border-radius: 6px;
  background: #0ea5e9;
}

td button:hover { background: #0284c7; }

td button:last-child {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

td button:last-child:hover { background: var(--danger); color: white; }
td select { padding: 5px 8px; font-size: 12px; width: auto; }

/* ============================
   BADGES
============================ */
.badge-estado {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.estado-pendiente   { background: #fef9c3; color: #854d0e; }
.estado-en-espera   { background: #ede9fe; color: #5b21b6; }
.estado-en-proceso  { background: #dbeafe; color: #1e40af; }
.estado-finalizada  { background: #dcfce7; color: #166534; }

.badge-prioridad {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.prioridad-normal  { background: #f1f5f9; color: #475569; }
.prioridad-urgente { background: #fff7ed; color: #c2410c; }
.prioridad-vip     { background: #fdf4ff; color: #86198f; }

.badge-rol {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.rol-admin      { background: #ede9fe; color: #5b21b6; }
.rol-secretaria { background: #dbeafe; color: #1e40af; }
.rol-mecanico   { background: #dcfce7; color: #166534; }

/* ============================
   MODALES
============================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 0;
  width: 100%;
  max-width: 560px;
  margin: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-box-lg { max-width: 920px; }
.modal-box-md { max-width: 680px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.modal-header h2 { font-size: 16px; font-weight: 600; color: var(--text-primary); margin: 0; }

.modal-scroll {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form { display: flex; flex-direction: column; gap: 12px; }

/* ============================
   TABS
============================ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 8px 16px;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, background 0.15s;
}

.tab-btn:hover  { color: var(--text-primary); background: var(--surface-2); }
.tab-btn.active { background: var(--surface); border-color: var(--border); color: var(--text-primary); font-weight: 500; }

.tab-panel        { display: none; }
.tab-panel.active { display: block; }

/* ============================
   RESUMEN ECONÓMICO
============================ */
.resumen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.resumen-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.resumen-card span   { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.resumen-card strong { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.ganancia            { color: #166534 !important; }

/* ============================
   MINI FORM
============================ */
.mini-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  background: var(--surface-2);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.mini-form input,
.mini-form select { margin: 0; }

/* ============================
   PERIODO TABS
============================ */
.periodo-tabs { display: flex; gap: 6px; margin-bottom: 14px; }

.periodo-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.periodo-btn:hover  { background: var(--surface-2); }
.periodo-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ============================
   DOS COLUMNAS
============================ */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ============================
   STATS
============================ */
.stats-section { margin-bottom: 28px; }

.stats-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ============================
   LOGIN
============================ */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  width: 100%;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.login-card p  { font-size: 13px; color: var(--text-secondary); margin-bottom: 24px; }

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  margin: 0;
}

.login-card button { width: 100%; padding: 11px; font-size: 15px; }

/* ============================
   IMPRESIÓN
============================ */
@media print {
  .sidebar, .topbar, .no-print, .modal-overlay { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 16px !important; }
  body { background: white; }
  .table-wrapper { box-shadow: none; border: 1px solid #ddd; }
}

/* ============================
   RESPONSIVE
============================ */
/* Botón hamburguesa y fondo oscuro (solo visibles en móvil) */
.menu-toggle {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 22px;
  line-height: 1.2;
  color: var(--text-primary);
  cursor: pointer;
}
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* Menú lateral deslizable (off-canvas) */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 250px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.35);
  }
  .sidebar.open  { transform: translateX(0); }
  .sidebar span  { display: inline; }
  .sidebar .logo { width: 64px; }

  .menu-toggle { display: inline-flex; align-items: center; }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 90;
  }

  .main-content { margin-left: 0; padding: 16px 12px; }

  /* Topbar compacta: controles a la izquierda, "Cerrar sesión" a la derecha,
     y el título baja a su propia línea para que nada se amontone */
  .topbar { flex-wrap: wrap; gap: 8px; justify-content: flex-start; margin-bottom: 18px; padding-bottom: 12px; }
  .topbar-right { margin-left: auto; }
  .topbar h1 { order: 5; flex-basis: 100%; font-size: 17px; margin-top: 2px; }
  .usuario-info { display: none; }
  .btn-back    { padding: 5px 10px; font-size: 12px; }
  .btn-logout  { padding: 5px 10px; font-size: 12px; }
  .menu-toggle { padding: 3px 10px; font-size: 20px; }

  form     { grid-template-columns: 1fr; padding: 16px; }
  .two-col { grid-template-columns: 1fr; }

  /* Modales casi a pantalla completa en móvil */
  .modal-overlay { padding: 10px; }
  .modal-box, .modal-box-lg, .modal-box-md { max-width: 100%; }

  /* Barra de búsqueda/filtros/acciones: apilar y ocupar todo el ancho */
  .section-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .section-header .search-bar { width: 100%; }
  .section-header input,
  .section-header select { max-width: 100% !important; width: 100%; }
  .section-header > div { width: 100%; }
  .section-header > div:last-child { display: flex; gap: 8px; }
  .section-header > div:last-child button { flex: 1; }
}

/* ============================
   ESTADO REPARADO
============================ */
.estado-reparado { background: #d1fae5; color: #065f46; }

/* ============================
   VALOR AMBER EN CARDS
============================ */
.card-sm .value.amber { color: #92400e; }

/* ============================
   SIDEBAR CON EMOJIS
============================ */
.sidebar a { gap: 12px; font-size: 14px; }
.sidebar a span { display: inline; }

/* ============================
   ESTADO BLOCK EN MODALES
============================ */
.estado-block { display: none; }
.estado-block.visible { display: block; }

/* Estados */
.estado-reparado { background: #d1fae5; color: #065f46; }
.estado-no-reparado { background: #fee2e2; color: #991b1b; }

/* Responsive mobile mejorado */
@media (max-width: 600px) {
  .modal-box { padding: 16px; }
  .modal-box-lg, .modal-box-md { max-width: 100%; margin: 10px; }
  .resumen-grid { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .cards-sm { grid-template-columns: repeat(2, 1fr); }
  thead th { font-size: 10px; padding: 8px 6px; }
  tbody td { font-size: 12px; padding: 8px 6px; }
}
/* ============================
   MENÚ AGRUPADO (colapsable)
============================ */
.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-bottom: 20px;
}
.sidebar-brand .logo { width: 64px; margin: 0; border-radius: 10px; }
.sidebar .brand-text {
  color: #e2e8f0;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  letter-spacing: .01em;
}
.sidebar .nav-ico { width: 24px; text-align: center; flex-shrink: 0; font-size: 16px; }
.sidebar .nav-label { flex: 1; text-align: left; }

/* Encabezado de grupo (botón que despliega) */
.nav-group { width: 100%; }
.nav-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  margin-bottom: 2px;
  transition: background .18s, color .18s;
}
.nav-group-head:hover { background: var(--sidebar-hover); color: #f1f5f9; }
.nav-caret { font-size: 11px; opacity: .7; transition: transform .2s; }
.nav-group.open > .nav-group-head .nav-caret { transform: rotate(180deg); }

/* Sub-ítems del grupo */
.nav-group-items { display: none; margin-bottom: 4px; }
.nav-group.open > .nav-group-items { display: block; }
.sidebar .nav-sub {
  display: block;
  padding: 9px 14px 9px 48px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 13.5px;
  border-radius: 8px;
  margin-bottom: 1px;
  transition: background .18s, color .18s;
}
.sidebar .nav-sub:hover { background: var(--sidebar-hover); color: #f1f5f9; }
.sidebar .nav-sub.active { background: var(--sidebar-active); color: #fff; }

/* Botón "Regresar" (inyectado en la topbar de todas las páginas) */
.btn-back {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  flex-shrink: 0;
}
.btn-back:hover { background: var(--surface-2); color: var(--text-primary); }
