/* =========================================================
   ESTILOS BASE Y COMPONENTES
   ========================================================= */

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-body);
  color: var(--ink-900);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--navy-900); }
p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--blue-100); }

/* ---------- Layout raíz ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--gradient-brand);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-brand .mark {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600; font-size: 17px;
  flex-shrink: 0;
}
.sidebar-brand .names { min-width: 0; }
.sidebar-brand .names .name {
  font-family: var(--font-display);
  font-weight: 600; font-size: 15px; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand .names .role {
  font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 2px;
}

.sidebar-nav { padding: var(--sp-3) var(--sp-3) var(--sp-6); flex: 1; }
.nav-category {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  padding: var(--sp-5) var(--sp-3) var(--sp-2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-3);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s ease;
}
.nav-item .ico { width: 18px; text-align: center; flex-shrink: 0; opacity: 0.9; }
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: #fff; color: var(--navy-800); font-weight: 600; }
.nav-item.active .ico { opacity: 1; }
.nav-item.soon { opacity: 0.45; cursor: default; }
.nav-item.soon:hover { background: transparent; color: rgba(255,255,255,0.85); }
.nav-tag {
  margin-left: auto; font-size: 10px; font-weight: 600;
  background: rgba(255,255,255,0.15); padding: 2px 6px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.03em;
}

/* ---------- Área de contenido ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-8);
  background: var(--surface);
  border-bottom: 1px solid var(--line-200);
  position: sticky; top: 0; z-index: 10;
}
.breadcrumb { font-size: 13px; color: var(--ink-500); margin-bottom: 4px; }
.page-title { font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-3); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line-200); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--ink-700);
}
.icon-btn:hover { background: var(--surface-muted); }
.user-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--navy-900); color: #fff;
  padding: 8px 14px 8px 8px; border-radius: 30px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--blue-500);
  display: flex; align-items: center; justify-content: center; font-size: 11px;
}

.content { padding: var(--sp-8); flex: 1; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--line-100);
}
.card-header h3 { font-size: 16px; }
.card-body { padding: var(--sp-6); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line-200);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: var(--shadow-sm);
}
.stat-card .num { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--navy-900); }
.stat-card .lbl { font-size: 12.5px; color: var(--ink-500); margin-top: 2px; }
.stat-card .stat-ico {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  flex-shrink: 0;
}

.welcome-banner {
  background: var(--gradient-brand);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-8);
  margin-bottom: var(--sp-6);
}
.welcome-banner h2 { color: #fff; font-size: 21px; margin-bottom: 4px; }
.welcome-banner p { color: rgba(255,255,255,0.75); font-size: 14px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.btn-primary { background: var(--navy-900); color: #fff; }
.btn-primary:hover { background: var(--navy-800); }
.btn-secondary { background: var(--surface); color: var(--navy-900); border-color: var(--line-200); }
.btn-secondary:hover { background: var(--surface-muted); }
.btn-danger { background: var(--danger-100); color: var(--danger-600); }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 12px 16px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-500); border-bottom: 1px solid var(--line-200);
  white-space: nowrap;
}
.data-table td {
  padding: 14px 16px; border-bottom: 1px solid var(--line-100);
  color: var(--ink-900); vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-muted); }
.data-table .cell-sub { color: var(--ink-500); font-size: 12px; margin-top: 2px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-empty { padding: var(--sp-10); text-align: center; color: var(--ink-500); }
.table-empty .big-ico { font-size: 32px; margin-bottom: var(--sp-3); opacity: 0.5; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-100); color: var(--success-600); }
.badge-success .badge-dot { background: var(--success-600); }
.badge-warning { background: var(--warning-100); color: var(--warning-600); }
.badge-warning .badge-dot { background: var(--warning-600); }
.badge-danger { background: var(--danger-100); color: var(--danger-600); }
.badge-danger .badge-dot { background: var(--danger-600); }
.badge-info { background: var(--info-100); color: var(--info-600); }
.badge-info .badge-dot { background: var(--info-600); }
.badge-neutral { background: var(--neutral-100); color: var(--neutral-600); }
.badge-neutral .badge-dot { background: var(--neutral-600); }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-5); }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--ink-700); }
.form-field .hint { font-size: 12px; color: var(--ink-500); }
.form-field input,
.form-field select,
.form-field textarea {
  font-family: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--ink-900);
  background: var(--surface);
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none; border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--blue-100);
}
.form-field textarea { resize: vertical; min-height: 70px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; flex-direction: row; }
.checkbox-field input { width: 16px; height: 16px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 22, 41, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--sp-8) var(--sp-4); overflow-y: auto; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 640px;
  box-shadow: var(--shadow-lg);
  margin: auto 0;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--line-100);
}
.modal-header h3 { font-size: 17px; }
.modal-close { cursor: pointer; color: var(--ink-500); font-size: 20px; border: none; background: none; }
.modal-body { padding: var(--sp-6); max-height: 65vh; overflow-y: auto; }
.modal-footer {
  padding: var(--sp-5) var(--sp-6); border-top: 1px solid var(--line-100);
  display: flex; justify-content: flex-end; gap: var(--sp-3);
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--sp-2); border-bottom: 1px solid var(--line-200); margin-bottom: var(--sp-5); }
.tab-btn {
  padding: 10px 4px; margin-right: var(--sp-5);
  font-size: 14px; font-weight: 600; color: var(--ink-500);
  border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--navy-900); border-bottom-color: var(--blue-500); }

/* ---------- Utilidades ---------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { display: flex; align-items: center; gap: var(--sp-3); }
.muted { color: var(--ink-500); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.search-input {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-200);
  border-radius: var(--radius-sm); padding: 9px 14px; min-width: 260px;
}
.search-input input { border: none; outline: none; font-size: 14px; width: 100%; }
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--navy-900); color: #fff;
  padding: 14px 20px; border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; z-index: 200;
  animation: toast-in 0.2s ease;
}
.toast.error { background: var(--danger-600); }
.toast.success { background: var(--success-600); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { text-align: center; padding: var(--sp-12) var(--sp-6); color: var(--ink-500); }
.empty-state .big-ico { font-size: 40px; margin-bottom: var(--sp-4); opacity: 0.4; }
.empty-state h4 { color: var(--ink-700); margin-bottom: var(--sp-2); }

.unit-type-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.unit-type-card {
  border: 1.5px solid var(--line-200); border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-2); text-align: center; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--ink-700);
}
.unit-type-card .ico { font-size: 20px; display: block; margin-bottom: 6px; }
.unit-type-card.active { border-color: var(--blue-500); background: var(--blue-50); color: var(--navy-900); }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex;
}
.login-visual {
  flex: 1.1;
  background: var(--gradient-brand);
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: var(--sp-12);
  color: #fff;
  overflow: hidden;
}
.login-visual::after {
  content: ''; position: absolute; right: -120px; top: -120px;
  width: 420px; height: 420px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
}
.login-visual::before {
  content: ''; position: absolute; right: -40px; top: 40px;
  width: 300px; height: 300px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
}
.login-visual .mark {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.5);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 21px;
  position: relative; z-index: 1;
}
.login-visual .quote {
  font-family: var(--font-display); font-size: 26px; line-height: 1.4;
  max-width: 420px; position: relative; z-index: 1;
}
.login-visual .quote-by { font-size: 13px; color: rgba(255,255,255,0.65); margin-top: var(--sp-4); position: relative; z-index: 1; }
.login-form-side {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: var(--sp-8);
}
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { font-size: 25px; margin-bottom: 6px; }
.login-box .sub { color: var(--ink-500); font-size: 14px; margin-bottom: var(--sp-8); }
.login-box .form-field { margin-bottom: var(--sp-4); }
.login-box .btn { width: 100%; justify-content: center; padding: 12px; margin-top: var(--sp-2); }
.login-error {
  background: var(--danger-100); color: var(--danger-600);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px;
  margin-bottom: var(--sp-4); display: none;
}

@media (max-width: 900px) {
  .login-visual { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .unit-type-picker { grid-template-columns: repeat(3, 1fr); }
}
