/* ============================================================
   CerraControl — estilos
   ============================================================ */
:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: 0 0 250px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30;
}
.brand {
  height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,.08); color: #fff;
  font-weight: 700; font-size: 1.15rem; letter-spacing: -.02em;
}
.brand-icon { font-size: 1.4rem; }
.nav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.nav-label {
  display: block; padding: 16px 12px 6px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .1em; color: #64748b; font-weight: 700;
}
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin: 2px 0;
  border-radius: 8px; color: #cbd5e1; font-weight: 500; transition: .15s;
}
.nav-link span { width: 20px; text-align: center; font-size: 1.05rem; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.rol-badge { font-size: .75rem; color: #94a3b8; }

.main-wrap { flex: 1; margin-left: 250px; min-width: 0; }
.topbar {
  height: 64px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 1.1rem; font-weight: 600; margin: 0; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary-dark); display: grid; place-items: center; font-weight: 700;
}
.user-name { font-weight: 600; }
.menu-toggle { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; }
.content { padding: 24px; max-width: 1500px; margin: 0 auto; }
.sidebar-overlay { display: none; }

/* ---------- Tarjetas y tablas ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  background: #f8fafc; font-weight: 700; white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
td.small, th.small { font-size: .82rem; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.9rem; font-weight: 700; margin-top: 6px; letter-spacing: -.03em; }
.stat-icon { float: right; font-size: 1.5rem; opacity: .8; }
.stat-primary .stat-value { color: var(--primary); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-value { color: var(--danger); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; white-space: nowrap;
  background: #e2e8f0; color: #475569;
}
.badge-success, .badge-finalizada, .badge-cobrado, .badge-aceptado { background: var(--success-bg); color: #15803d; }
.badge-warning, .badge-pendiente, .badge-pendiente_cobro, .badge-en_curso, .badge-emitido { background: var(--warning-bg); color: #b45309; }
.badge-danger, .badge-cancelada, .badge-anulado, .badge-urgente { background: var(--danger-bg); color: #b91c1c; }
.badge-info, .badge-facturado { background: var(--info-bg); color: #1d4ed8; }
.badge-borrador, .badge-baja { background: #e2e8f0; color: #475569; }
.badge-normal { background: var(--info-bg); color: #1d4ed8; }

/* ---------- Formularios ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 7px;
  font: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12);
}
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-label label { margin: 0; }

.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filtros .form-group { margin: 0; min-width: 150px; flex: 1; }
.filtros .form-group label { font-size: .72rem; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 7px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: inherit; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; cursor: pointer; font: inherit; }
.btn-link:hover { text-decoration: underline; }
.acciones { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Alertas ---------- */
.alert {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 16px;
  display: flex; gap: 9px; align-items: center; font-weight: 500;
}
.alert-success { background: var(--success-bg); color: #15803d; }
.alert-error { background: var(--danger-bg); color: #b91c1c; }
.alert-info { background: var(--info-bg); color: #1d4ed8; }
.alert-warning { background: var(--warning-bg); color: #b45309; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-icon { font-size: 2.2rem; display: block; margin-bottom: 8px; }

/* ---------- Detalle ---------- */
.detalle { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 28px; }
.detalle-item { display: flex; justify-content: space-between; gap: 14px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.detalle-item dt { color: var(--muted); font-weight: 600; }
.detalle-item dd { margin: 0; text-align: right; font-weight: 500; }
.totales { margin-left: auto; width: 300px; }
.totales div { display: flex; justify-content: space-between; padding: 6px 0; }
.totales .total-final { border-top: 2px solid var(--text); font-size: 1.25rem; font-weight: 700; margin-top: 6px; padding-top: 10px; }

/* ---------- Líneas de documento ---------- */
.linea-row input, .linea-row select { padding: 7px 8px; font-size: .85rem; }
.linea-row td { padding: 7px 6px; }
.linea-subtotal { font-weight: 600; text-align: right; white-space: nowrap; }
.tabla-lineas th { font-size: .65rem; }

/* ---------- Login ---------- */
.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #0f766e 100%);
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 14px;
  padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.auth-brand { font-size: 1.3rem; font-weight: 800; color: var(--primary-dark); margin-bottom: 20px; }
.auth-card h2 { margin-bottom: 4px; }
.auth-card .muted { margin-top: 0; margin-bottom: 22px; }

/* ---------- Documento imprimible ---------- */
.doc-print { max-width: 800px; margin: 0 auto; background: #fff; padding: 40px; color: #000; }
.doc-print .doc-head { display: flex; justify-content: space-between; gap: 30px; border-bottom: 3px solid #0f766e; padding-bottom: 18px; margin-bottom: 24px; }
.doc-print .doc-head h1 { font-size: 1.8rem; color: #0f766e; text-transform: uppercase; letter-spacing: .05em; }
.doc-print .empresa-nombre { font-size: 1.3rem; font-weight: 800; }
.doc-print .bloques { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-bottom: 26px; }
.doc-print .bloque h3 { font-size: .75rem; text-transform: uppercase; color: #64748b; border-bottom: 1px solid #cbd5e1; padding-bottom: 4px; }
.doc-print table { margin-top: 10px; }
.doc-print th, .doc-print td { border: 1px solid #cbd5e1; padding: 8px 10px; }
.doc-print .doc-totales { width: 320px; margin-left: auto; margin-top: 18px; }
.doc-print .doc-totales td { border: 0; padding: 5px 8px; }
.doc-print .doc-totales .grand-total { font-size: 1.2rem; font-weight: 800; border-top: 2px solid #000; }
.doc-print .doc-pie { margin-top: 50px; padding-top: 14px; border-top: 1px solid #cbd5e1; font-size: .82rem; color: #475569; }
.barra-acciones { max-width: 800px; margin: 0 auto 16px; display: flex; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: block; }
  .grid-2, .grid-3, .grid-4, .stats, .detalle, .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .user-name { display: none; }
}
@media print {
  body { background: #fff; }
  .barra-acciones, .no-print { display: none !important; }
  .doc-print { padding: 0; max-width: none; }
  @page { margin: 15mm; }
}
