/* Webapp styles — adaptado del diseño "Panel de Control MasErp" (claude.ai/design)
   sobre tokens.css. Sin frameworks: JS vanilla en /js/app.js maneja el estado
   (colapsar sidebar, nav móvil, toggle de tier en el alta de cliente). */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--ink-50); color: var(--fg); font-family: var(--font-sans); }
a { color: var(--navy-700); text-decoration: none; }
a:hover { color: var(--navy-800); text-decoration: underline; }
::placeholder { color: var(--ink-300); }

/* ==================== Franja de ambiente ==================== */
.envbar {
  height: 28px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; flex-shrink: 0;
}
.envbar.local { background: var(--ink-200); color: var(--ink-700); }
.envbar.staging { background: var(--warn-100); color: var(--warn-700); }
.envbar.prod { background: var(--navy-900); color: #fff; }

/* ==================== Layout ==================== */
.shell { min-height: 100vh; width: 100%; display: flex; flex-direction: column; }
.app { flex: 1; display: flex; min-height: 0; position: relative; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; overflow: auto; padding: 28px 32px; max-width: 1280px; width: 100%; }

/* ==================== Sidebar ==================== */
.sidebar {
  background: var(--navy-900);
  color: rgba(255,255,255,0.72);
  display: flex; flex-direction: column;
  padding: 16px 0;
  border-right: 1px solid rgba(0,0,0,0.2);
  position: sticky; top: 28px; height: calc(100vh - 28px);
  width: 240px; flex-shrink: 0;
  transition: width var(--dur-base) var(--ease-out);
  z-index: 30;
}
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .brand { justify-content: center; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .sidebar-section-label,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .user-chip .name,
.sidebar.collapsed .user-chip .biz,
.sidebar.collapsed .user-chip .icon-btn { display: none; }

.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 8px 16px 20px; }
.sidebar .brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.sidebar .brand-name { font-family: var(--font-serif); font-weight: 500; font-size: 18px; color: #fff; letter-spacing: 0.5px; font-variation-settings: "opsz" 36; white-space: nowrap; }
.sidebar-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.4); padding: 12px 20px 6px; white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; margin: 1px 10px;
  border-radius: 6px;
  color: rgba(255,255,255,0.72);
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { background: rgba(244,185,66,0.12); color: var(--gold-300); }
.nav-item.active .nav-icon { filter: brightness(0) saturate(100%) invert(82%) sepia(25%) saturate(900%) hue-rotate(347deg) brightness(103%) contrast(96%); }
.nav-item .lock-icon { width: 13px; height: 13px; margin-left: auto; opacity: 0.6; filter: brightness(0) invert(1) opacity(0.6); }
.nav-icon { width: 18px; height: 18px; filter: brightness(0) invert(1) opacity(0.8); flex-shrink: 0; }
.sidebar-footer { margin-top: auto; padding: 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; }
.user-chip:hover { background: rgba(255,255,255,0.05); }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: linear-gradient(135deg,var(--gold-400),var(--gold-600)); display: flex; align-items: center; justify-content: center; color: var(--navy-900); font-weight: 600; font-size: 13px; font-family: var(--font-serif); flex-shrink: 0; }
.user-chip .name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .biz { color: rgba(255,255,255,0.5); font-size: 12px; }

.sidebar-collapse-toggle { margin-top: 12px; padding: 0 10px; }
.sidebar-collapse-toggle .icon-btn { width: 100%; background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.6); }
.sidebar-collapse-toggle img { filter: brightness(0) invert(1) opacity(0.7); }

/* Móvil: sidebar off-canvas */
.scrim { position: fixed; inset: 0; background: rgba(7,36,61,0.4); backdrop-filter: blur(4px); z-index: 40; animation: fadeIn var(--dur-base) var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 28px; left: 0; height: calc(100vh - 28px); width: 240px;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease-out);
  }
  .sidebar.collapsed { width: 240px; }
  .sidebar.collapsed .brand-name,
  .sidebar.collapsed .sidebar-section-label,
  .sidebar.collapsed .nav-item span,
  .sidebar.collapsed .user-chip .name,
  .sidebar.collapsed .user-chip .biz,
  .sidebar.collapsed .user-chip .icon-btn { display: block; }
  .sidebar.collapsed .brand { justify-content: flex-start; }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-collapse-toggle { display: none; }
  .mobile-menu-btn { display: inline-flex !important; }
}
.mobile-menu-btn { display: none; }

/* ==================== Topbar ==================== */
.topbar {
  height: 64px; padding: 0 32px;
  display: flex; align-items: center; gap: 16px;
  background: rgba(251,252,253,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ink-200);
  position: sticky; top: 28px; z-index: 20;
}
.topbar h1 { font: 500 22px/1.2 var(--font-serif); color: var(--navy-900); letter-spacing: -0.005em; margin: 0; font-variation-settings: "opsz" 36; }
.topbar .sub { color: var(--fg-muted); font-size: 13px; }

/* ==================== Botones ==================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: 6px; cursor: pointer;
  font: 600 14px/1 var(--font-sans);
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy-800); color: #fff; box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.1); }
.btn-primary:hover { background: var(--navy-700); box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,0.1); }
.btn-secondary { background: var(--paper); color: var(--ink-900); border-color: var(--ink-200); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--ink-50); }
.btn-ghost { background: transparent; color: var(--ink-900); }
.btn-ghost:hover { background: var(--ink-100); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 15px; }
.btn img { width: 16px; height: 16px; filter: brightness(0) invert(1); }
.btn-secondary img, .btn-ghost img { filter: none; opacity: 0.7; }

/* ==================== Inputs ==================== */
.input, .select {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--ink-200); border-radius: 6px;
  background: var(--paper); font: 400 14px var(--font-sans); color: var(--ink-900);
  box-shadow: inset 0 1px 0 rgba(11,59,92,0.04);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.input:focus, .select:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--navy-500); }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-900); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--fg-muted); margin-top: 4px; }

/* ==================== Cards ==================== */
.card {
  background: var(--paper); border: 1px solid var(--ink-200);
  border-radius: 12px; box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--ink-100);
}
.card-header h3 { margin: 0; font: 600 15px var(--font-sans); color: var(--ink-900); }
.card-body { padding: 20px; }

/* ==================== KPI ==================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { padding: 16px 18px; }
.kpi .label { font-size: 11px; font-weight: 600; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .amount { font-family: var(--font-serif); font-weight: 500; font-size: 22px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--navy-900); margin: 6px 0 0; font-variation-settings: "opsz" 48; white-space: nowrap; }
.kpi .meta { color: var(--fg-muted); font-size: 13px; margin-top: 10px; }

/* ==================== Pills de estado ==================== */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill .dot { width: 6px; height: 6px; border-radius: 999px; flex-shrink: 0; }
.pill-paid { background: var(--success-100); color: var(--success-700); }
.pill-paid .dot { background: var(--success-500); }
.pill-sent { background: var(--info-100); color: var(--info-700); }
.pill-sent .dot { background: var(--info-500); }
.pill-pending { background: var(--warn-100); color: var(--warn-700); }
.pill-pending .dot { background: var(--warn-500); }
.pill-overdue { background: var(--danger-100); color: var(--danger-700); }
.pill-overdue .dot { background: var(--danger-500); }
.pill-draft { background: var(--ink-100); color: var(--ink-700); }
.pill-draft .dot { background: var(--ink-400); }

/* ==================== Tablas ==================== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 600; font-size: 11px; color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 10px 16px; border-bottom: 1px solid var(--ink-200); background: var(--ink-50);
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--ink-100); color: var(--ink-900); vertical-align: middle; }
.table tbody tr:hover td { background: var(--ink-50); }
.table td.c { font-family: var(--font-mono); font-size: 12px; color: var(--ink-700); }
.table td.right { text-align: right; }
.cell-client { display: flex; align-items: center; gap: 10px; }
.cell-avatar { width: 28px; height: 28px; border-radius: 999px; background: var(--ink-100); display: flex; align-items: center; justify-content: center; color: var(--navy-800); font-weight: 600; font-size: 12px; flex-shrink: 0; }
.empty-row td { text-align: center; padding: 32px 16px; color: var(--fg-muted); }

/* ==================== Barra de capacidad de pool ==================== */
.pool-row + .pool-row { margin-top: 16px; }
.pool-row .pool-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.pool-row .pool-head .name { font-weight: 600; }
.pool-bar { height: 6px; border-radius: 999px; background: var(--ink-100); overflow: hidden; }
.pool-bar > div { height: 100%; border-radius: 999px; }

/* ==================== Mensajes ==================== */
.flash { border-radius: 8px; padding: 12px 16px; font-size: 14px; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }
.flash-ok { background: var(--success-100); color: var(--success-700); }
.flash-err { background: var(--danger-100); color: var(--danger-700); }
.flash img { width: 18px; height: 18px; opacity: 0.9; }
.flash .close { margin-left: auto; }

.icon-btn { width: 32px; height: 32px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; border: none; background: transparent; cursor: pointer; }
.icon-btn:hover { background: var(--ink-100); }
.icon-btn img { width: 16px; height: 16px; opacity: 0.7; }

/* ==================== Formularios de subsección (infra) ==================== */
.subform { border-top: 1px solid var(--ink-100); background: var(--ink-50); padding: 20px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1; min-width: 200px; }

/* ==================== Login ==================== */
.login-wrap { flex: 1; display: flex; min-height: 0; }
.login-left {
  flex: 1; min-width: 0; padding: 48px; display: flex; flex-direction: column;
  background-image: linear-gradient(22deg, var(--navy-900), var(--navy-700)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0px, rgba(255,255,255,0.05) 1px, transparent 1px, transparent 25px);
}
.login-left .brand-row { display: flex; align-items: center; gap: 10px; }
.login-left .brand-word { font-family: var(--font-serif); font-weight: 500; font-size: 20px; color: #fff; font-variation-settings: "opsz" 36; }
.login-left .pitch { margin-top: auto; }
.login-left .pitch h1 { font-family: var(--font-serif); font-weight: 500; font-size: 36px; line-height: 1.2; color: #fff; letter-spacing: -0.015em; margin: 8px 0 12px; font-variation-settings: "opsz" 72; }
.login-left .pitch p { color: rgba(255,255,255,0.62); font-size: 15px; max-width: 420px; margin: 0; }
.login-left .pitch .eyebrow { color: rgba(255,255,255,0.55); }
.login-left .copyright { color: rgba(255,255,255,0.35); font-size: 12px; margin-top: 32px; }
.login-right { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--paper); }
.login-form { width: 100%; max-width: 360px; }

@media (max-width: 780px) {
  .login-left { display: none; }
}

/* ==================== Error / no autorizado ==================== */
.error-screen { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.error-card { max-width: 420px; text-align: center; padding: 8px; }
.error-icon { width: 56px; height: 56px; border-radius: 999px; background: var(--danger-100); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.error-icon img { width: 26px; height: 26px; filter: brightness(0) saturate(100%) invert(20%) sepia(60%) saturate(1500%) hue-rotate(330deg); }

/* ==================== Utilidades ==================== */
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 780px) { .grid-2 { grid-template-columns: 1fr; } }
