/* Oficinapp — sistema de diseño (UI-OFICINAPP.md §1) y shell del panel (§4). */

:root {
  --navy-900: #0B1F3A;
  --navy-800: #13294B;
  --navy-700: #1E3A64;
  --orange-500: #FF6B1A;
  --orange-600: #E85A0C;
  --orange-50: #FFF1E8;
  --gray-50: #F5F7FA;
  --gray-100: #EEF1F5;
  --gray-300: #D0D5DD;
  --gray-500: #667085;
  --gray-900: #101828;
  --white: #FFFFFF;
  --success: #16A34A; --success-50: #E8F7EE;
  --warning: #F59E0B; --warning-50: #FEF4E6;
  --danger: #DC2626;  --danger-50: #FDECEC;
  --info: #2563EB;    --info-50: #EAF1FE;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;

  --shadow-card: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --shadow-elevated: 0 12px 24px -6px rgba(11,31,58,.18);

  --sidebar-w: 264px;
  --sidebar-w-collapsed: 76px;
  --gap: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; color: var(--navy-900); line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 18px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--gray-500); }
.num { font-variant-numeric: tabular-nums; }
.icon { flex: none; stroke-width: 2; }

:focus-visible { outline: 2px solid var(--orange-500); outline-offset: 2px; border-radius: 4px; }

/* ---------- Shell ---------- */
.shell { display: flex; height: 100dvh; width: 100vw; overflow: hidden; }

.sidebar {
  position: relative;
  margin: var(--gap) 0 var(--gap) var(--gap);
  width: var(--sidebar-w);
  flex: none;
  background: var(--navy-900);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-elevated);
  display: flex; flex-direction: column;
  padding: 20px 8px 12px;
  color: #fff;
  transition: width .2s ease;
  z-index: 30;
}
.sidebar__logo { display: flex; align-items: center; gap: 10px; padding: 0 12px 20px; }
.sidebar__logo img { height: 36px; }
.sidebar__logo .logo-full { height: 40px; }
.sidebar__logo .logo-mark { display: none; }
.sidebar nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 12px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.72);
  font-weight: 500;
  white-space: nowrap;
}
.nav-item:hover { background: var(--navy-800); color: #fff; }
.nav-item.is-active { background: var(--orange-500); color: #fff; }
.nav-item__label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full);
  background: var(--orange-500); color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-item.is-active .nav-badge { background: #fff; color: var(--orange-600); }
.nav-soon { font-size: 10px; font-weight: 600; letter-spacing: .02em; color: rgba(255,255,255,.45); text-transform: uppercase; }

.sidebar__footer { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; }
.user-card {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: var(--radius-md); background: var(--navy-800);
}
.user-card__text { min-width: 0; flex: 1; }
.user-card__name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card__org { font-size: 12px; color: rgba(255,255,255,.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collapse-btn {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px;
  border: 0; background: none; color: rgba(255,255,255,.6); cursor: pointer;
  border-radius: var(--radius-md); font: inherit;
}
.collapse-btn:hover { background: var(--navy-800); color: #fff; }

.avatar {
  width: 36px; height: 36px; border-radius: var(--radius-full); flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; color: #fff; background: var(--navy-700);
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

/* Colapsado: solo iconos */
.shell.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.shell.is-collapsed .nav-item__label,
.shell.is-collapsed .nav-badge,
.shell.is-collapsed .nav-soon,
.shell.is-collapsed .user-card__text,
.shell.is-collapsed .collapse-btn span,
.shell.is-collapsed .sidebar__logo .logo-full { display: none; }
.shell.is-collapsed .sidebar__logo .logo-mark { display: block; }
.shell.is-collapsed .sidebar__logo { justify-content: center; padding: 0 0 20px; }
.shell.is-collapsed .nav-item, .shell.is-collapsed .collapse-btn { justify-content: center; padding: 0; }
.shell.is-collapsed .user-card { justify-content: center; padding: 6px; }
.shell.is-collapsed .collapse-btn .icon { transform: rotate(180deg); }

/* ---------- Contenido ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; padding: var(--gap); }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px 20px;
}
.topbar__menu { display: none; }
.topbar__title { flex: 1; min-width: 0; }
.topbar__title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search {
  position: relative; width: min(360px, 32vw);
}
.search input[type=search] { padding-left: 38px; background: #fff; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-500); }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-md); border: 1px solid var(--gray-100);
  background: #fff; display: inline-flex; align-items: center; justify-content: center;
  color: var(--navy-900); cursor: pointer; position: relative;
}
.icon-btn:hover { border-color: var(--gray-300); }
.icon-btn.topbar__menu { display: none; }
.step-done { color: var(--success); }
.step-todo { color: var(--gray-300); }
.content { padding: 0 12px 24px; flex: 1; }
.content--narrow { max-width: 960px; }

/* ---------- Componentes ---------- */
.card {
  background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 20px;
}
.card__head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.card__head h3 { flex: 1; }
.card__link { color: var(--orange-600); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--radius-md);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  border: 1px solid transparent;
}
.btn--primary { background: var(--orange-500); color: #fff; }
.btn--primary:hover { background: var(--orange-600); }
.btn--secondary { background: #fff; color: var(--navy-900); border-color: var(--gray-300); }
.btn--secondary:hover { background: var(--gray-50); }
.btn--danger { background: #fff; color: var(--danger); border-color: var(--danger-50); }
.btn--danger:hover { background: var(--danger-50); }
.btn--block { width: 100%; height: 48px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill--success { background: var(--success-50); color: var(--success); }
.pill--warning { background: var(--warning-50); color: #B45309; }
.pill--danger { background: var(--danger-50); color: var(--danger); }
.pill--info { background: var(--info-50); color: var(--info); }
.pill--neutral { background: var(--gray-100); color: var(--gray-500); }
.pill--tac { background: var(--orange-50); color: var(--orange-600); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { display: flex; gap: 14px; align-items: flex-start; }
.kpi__icon {
  width: 44px; height: 44px; border-radius: var(--radius-full); background: var(--orange-50); color: var(--orange-500);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.kpi__label { font-size: 12px; color: var(--gray-500); font-weight: 500; }
.kpi__value { font-size: 32px; font-weight: 700; color: var(--navy-900); font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi__delta { font-size: 12px; color: var(--gray-500); }

.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--gray-100); }
.list-row:first-child { border-top: 0; }
.list-row__main { flex: 1; min-width: 0; }
.list-row__title { font-weight: 600; color: var(--navy-900); }
.list-row__sub { font-size: 13px; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Pestañas segmentadas */
.segmented { display: inline-flex; gap: 4px; padding: 4px; background: var(--gray-100); border-radius: var(--radius-md); }
.segmented a {
  padding: 6px 14px; border-radius: 10px; font-weight: 600; font-size: 13px; color: var(--gray-500);
}
.segmented a.is-active { background: #fff; color: var(--navy-900); box-shadow: var(--shadow-card); }

/* Tablas y listados (plantilla base de todos los listados, §4.2-07) */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar__spacer { flex: 1; }
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-500);
  padding: 12px 16px; border-bottom: 1px solid var(--gray-100); white-space: nowrap;
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--gray-50); }
.table .strong { font-weight: 600; color: var(--navy-900); }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--gray-100); }
.cards-list { display: none; }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--navy-900); }
.field .hint { font-size: 12px; color: var(--gray-500); }
.field .error { font-size: 12px; color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px; color: var(--gray-900); background: #fff;
}
@media (min-width: 768px) {
  input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], select, textarea { font-size: 14px; }
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange-500); box-shadow: 0 0 0 3px var(--orange-50); }
.has-error input, .has-error select { border-color: var(--danger); }
.radio-cards { display: flex; gap: 8px; }
.radio-cards label {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 500;
}
.radio-cards input:checked + span { color: var(--orange-600); font-weight: 600; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

.alert { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: 16px; font-weight: 500; }
.alert--success { background: var(--success-50); color: #166534; }
.alert--error { background: var(--danger-50); color: #991B1B; }
.alert--info { background: var(--info-50); color: #1E40AF; }

.empty { text-align: center; padding: 48px 16px; }
.empty .icon { color: var(--gray-300); margin-bottom: 12px; }
.empty p { color: var(--gray-500); margin-bottom: 16px; }

/* Configuración: navegación vertical secundaria */
.settings { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.subnav { display: flex; flex-direction: column; gap: 4px; }
.subnav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-md); font-weight: 500; color: var(--gray-500); }
.subnav a:hover { background: #fff; color: var(--navy-900); }
.subnav a.is-active { background: var(--orange-50); color: var(--orange-600); font-weight: 600; }

/* Ficha */
.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px; }
.dl dt { color: var(--gray-500); }
.dl dd { margin: 0; font-weight: 500; }

/* Barra inferior (móvil, §4.4 / §5.1) */
.bottom-nav { display: none; }

/* ---------- Auth ---------- */
.auth {
  min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr;
}
.auth__brand {
  background: var(--navy-900); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth__brand::after {
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 360px; height: 360px;
  border-radius: 50%; background: radial-gradient(circle, rgba(255,107,26,.35), transparent 70%);
}
.auth__brand h2 { color: #fff; font-size: 32px; font-weight: 700; max-width: 440px; }
.auth__brand ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 12px; color: rgba(255,255,255,.8); }
.auth__brand li { display: flex; gap: 10px; align-items: center; }
.auth__brand li .icon { color: var(--orange-500); }
.auth__form { display: flex; align-items: center; justify-content: center; padding: 32px 16px; background: var(--gray-50); }
.auth__card { width: 100%; max-width: 420px; }
.auth__card h1 { margin-bottom: 4px; }
.auth__card form { display: grid; gap: 16px; margin-top: 24px; }
.auth__switch { margin-top: 20px; text-align: center; color: var(--gray-500); }
.auth__switch a { color: var(--orange-600); font-weight: 600; }
.auth__mobile-logo { display: none; margin-bottom: 24px; height: 40px; }

/* ---------- Responsive (§4.3) ---------- */
@media (max-width: 1439px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1279px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1023px) {
  .grid-3, .grid-2, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-110%);
    transition: transform .2s ease; width: var(--sidebar-w) !important;
  }
  .shell.is-drawer-open .sidebar { transform: none; }
  .shell.is-collapsed .nav-item__label, .shell.is-collapsed .nav-badge, .shell.is-collapsed .user-card__text,
  .shell.is-collapsed .sidebar__logo .logo-full { display: initial; }
  .collapse-btn { display: none; }
  .scrim { position: fixed; inset: 0; background: rgba(11,31,58,.4); z-index: 20; display: none; }
  .shell.is-drawer-open .scrim { display: block; }
  .icon-btn.topbar__menu { display: inline-flex; }
  .settings { grid-template-columns: minmax(0, 1fr); }
  .subnav { flex-direction: row; overflow-x: auto; }
  .subnav a { white-space: nowrap; }
  .auth { grid-template-columns: 1fr; }
  .auth__brand { display: none; }
  .auth__mobile-logo { display: block; }
}
@media (max-width: 767px) {
  :root { --gap: 0px; }
  .main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .topbar { padding: 12px 16px; position: sticky; top: 0; background: var(--gray-50); z-index: 10; }
  .icon-btn.topbar__menu, .topbar .search, .topbar .btn--primary .btn-label { display: none; }
  .topbar .btn--primary { width: 40px; padding: 0; }
  .content { padding: 0 16px 24px; }
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
  .kpi__value { font-size: 24px; }
  .kpi__icon { display: none; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 10px; }
  /* Tablas → listas de tarjetas */
  .table-card .table { display: none; }
  .cards-list { display: grid; gap: 0; }
  .cards-list a { display: block; padding: 14px 16px; border-bottom: 1px solid var(--gray-100); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: #fff; border-top: 1px solid var(--gray-100);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: flex-end;
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; font-weight: 600; color: var(--gray-500); padding: 6px 0; min-height: 44px;
  }
  .bottom-nav a.is-active { color: var(--orange-500); }
  .bottom-nav .ofi-btn {
    width: 64px; height: 64px; margin-top: -30px; border-radius: var(--radius-full);
    background: var(--orange-500); color: #fff; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-elevated); border: 4px solid #fff;
  }
  .bottom-nav .ofi-wrap { color: var(--navy-900); }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; height: 48px; }
}
