/* Design tokens - modo oscuro SaaS */
:root {
  --bg: #0b1020;
  --bg-card: #111a33;
  --muted: #9aa7c7;
  --text: #e8eeff;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #64748b;
  --brand: #7dd3fc;
  --danger: #fecaca;
  --ok: #bbf7d0;
  --warn: #fde68a;
  --border: rgba(255,255,255,.1);
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,.2);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg), #070a14);
  color: var(--text);
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.topbar {
  position: sticky; top: 0;
  background: rgba(11,16,32,.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.brand { font-weight: 700; letter-spacing: .3px; color: var(--brand); font-size: 1.1rem; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius);
  display: inline-flex; align-items: center; gap: 6px;
}
.nav a:hover { color: var(--text); background: rgba(255,255,255,.06); }

.nav__logout {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
}
.nav__logout:hover { color: var(--text); background: rgba(255,255,255,.06); }

/* Card reutilizable */
.card {
  background: rgba(17,26,51,.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card-section { margin-bottom: 18px; }
.card-section:last-child { margin-bottom: 0; }

/* Form sections - bloques agrupados */
.form-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.form-section__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin: 0 0 10px;
}
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: span 1; } }

/* Campos compactos */
label { display: block; color: var(--muted); font-size: 12px; margin: 0 0 4px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1226;
  color: var(--text);
  font-size: 13px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.field-error { font-size: 11px; color: var(--danger); margin-top: 2px; }

/* Grid 12 columnas */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px 14px; }
.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-12 { grid-column: span 12; }
@media (max-width: 900px) { .col-4, .col-6 { grid-column: span 12; } }

/* Títulos */
.h1 { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.h2 { font-size: 16px; font-weight: 700; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 13px; }

/* Botones */
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1730;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: rgba(255,255,255,.2); }
.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn--primary:hover { background: var(--primary-hover); }
.btn--danger {
  background: rgba(127,29,29,.5);
  border-color: rgba(254,202,202,.3);
  color: var(--danger);
}
.btn--sm { padding: 4px 8px; font-size: 12px; }
.btn--icon { padding: 6px 10px; }

/* Tabla compacta */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; background: rgba(0,0,0,.15); }
.table td { vertical-align: middle; }
.table input, .table select { padding: 6px 8px; min-width: 0; }
.table .input-num { width: 80px; text-align: right; }
.table .input-price { width: 90px; text-align: right; }

/* Totales destacados */
.total-block { padding: 12px 14px; border-radius: var(--radius); background: rgba(0,0,0,.2); border: 1px solid var(--border); }
.total-block .total-label { font-size: 12px; color: var(--muted); }
.total-block .total-value { font-size: 22px; font-weight: 700; color: var(--brand); }
.total-block .total-value small { font-size: 14px; font-weight: 500; color: var(--muted); }

/* Badges estados */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge--success { border-color: rgba(187,247,208,.3); color: var(--ok); }
.badge--warn { border-color: rgba(253,230,138,.3); color: var(--warn); }
.badge--danger { border-color: rgba(254,202,202,.3); color: var(--danger); }
.pill { display: inline-block; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.pill--danger { color: #b42318; border-color: #fecdca; background: #fef3f2; font-weight: 600; }
.pill--success { color: #067647; border-color: #abefc6; background: #ecfdf3; font-weight: 600; }

/* Mensajes */
.messages { display: grid; gap: 8px; margin-bottom: 12px; }
.message { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: rgba(255,255,255,.04); }
.message--success { border-color: rgba(187,247,208,.25); background: rgba(187,247,208,.06); }
.message--error { border-color: rgba(254,202,202,.25); background: rgba(254,202,202,.06); }
.message--warning { border-color: rgba(253,230,138,.25); background: rgba(253,230,138,.06); }

/* Iconos inline (Heroicons-style 20px) */
.icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.icon--sm { width: 14px; height: 14px; }

/* Layout con sidebar (empresa en contexto) */
.app-layout {
  display: flex;
  align-items: flex-start;
  gap: 0;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  min-height: calc(100vh - 56px);
  transition: max-width 0.25s ease;
}
.app-layout.is-sidebar-collapsed,
html.is-sidebar-collapsed .app-layout {
  max-width: none;
  width: 100%;
}
.app-main {
  flex: 1;
  min-width: 0;
  padding-left: 16px;
  transition: padding-left 0.25s ease;
}
.app-layout.is-sidebar-collapsed .app-main,
html.is-sidebar-collapsed .app-main {
  padding-left: 0;
  width: 100%;
  max-width: 100%;
  flex: 1 1 100%;
}
.erp-sidebar {
  width: 220px;
  min-width: 220px;
  flex: 0 0 220px;
  flex-shrink: 0;
  background: rgba(17, 26, 51, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 10px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 88px);
  overflow-x: hidden;
  overflow-y: auto;
  transition: width 0.25s ease, min-width 0.25s ease, flex-basis 0.25s ease, opacity 0.2s ease, padding 0.25s ease, border-color 0.25s ease;
}
.app-layout.is-sidebar-collapsed .erp-sidebar,
html.is-sidebar-collapsed .erp-sidebar {
  display: none;
  width: 0;
  min-width: 0;
  max-width: 0;
  flex: 0 0 0;
  padding: 0;
  margin: 0;
  border-width: 0;
  overflow: hidden;
}
.erp-sidebar__toggle {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.erp-sidebar__toggle:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(148, 163, 184, 0.35);
}
.erp-sidebar-float-open {
  position: fixed;
  left: 12px;
  top: 72px;
  z-index: 60;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(17, 26, 51, 0.95);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.erp-sidebar-float-open:hover {
  color: var(--brand);
  border-color: rgba(59, 130, 246, 0.45);
  transform: translateY(-1px);
}
.erp-sidebar-float-open[hidden] {
  display: none;
}
.erp-sidebar__head { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.erp-sidebar__empresa {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}
.erp-sidebar__empresa:hover { color: var(--brand); }
.erp-sidebar__back { font-size: 12px; }
.erp-sidebar__group {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin: 12px 8px 6px;
}
.erp-sidebar__group:first-of-type { margin-top: 4px; }
.erp-sidebar__link {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}
.erp-sidebar__link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
.erp-sidebar__link.is-active {
  color: var(--brand);
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.35);
}
.erp-nav-tree {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.erp-nav-tree__group {
  border: 1px solid transparent;
  border-radius: 8px;
}
.erp-nav-tree__group[open] {
  border-color: rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.12);
}
.erp-nav-tree__summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  user-select: none;
}
.erp-nav-tree__summary::-webkit-details-marker {
  display: none;
}
.erp-nav-tree__chevron::before {
  content: "▸";
  display: inline-block;
  width: 14px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.erp-nav-tree__group[open] > .erp-nav-tree__summary .erp-nav-tree__chevron::before {
  transform: rotate(90deg);
}
.erp-nav-tree__children {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 4px 8px;
}
.erp-nav-tree__children .erp-sidebar__link {
  padding-left: 22px;
}
.erp-sidebar__link.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}
.erp-sidebar__link-hint {
  display: block;
  font-size: 10px;
  margin-top: 2px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  line-height: 1.3;
}
@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .erp-sidebar {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    position: static;
    max-height: none;
  }
  .app-layout.is-sidebar-collapsed .erp-sidebar,
  html.is-sidebar-collapsed .erp-sidebar {
    display: none;
    width: 0;
    min-width: 0;
    max-width: 0;
    height: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
    border-width: 0;
    overflow: hidden;
  }
  .app-main { padding-left: 0; padding-top: 12px; }
}
