/* Firma Clara — interfaz administrativa */
:root {
  --ink: #2c3a49;
  --ink-deep: #1d2935;
  --brown: #301b00;
  --gold: #a9824b;
  --gold-dark: #886736;
  --ivory: #fbfaf7;
  --paper: #ffffff;
  --sand: #f2eee6;
  --line: #e5dfd4;
  --muted: #6f7780;
  --success: #2f6b55;
  --success-soft: #e8f3ed;
  --danger: #9a433d;
  --danger-soft: #faece9;
  --warning: #916c27;
  --warning-soft: #fbf3de;
  --sidebar-width: 270px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(48, 27, 0, .05), 0 8px 24px rgba(44, 58, 73, .06);
  --shadow-lg: 0 26px 70px rgba(31, 37, 42, .16);
  --ease: 180ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; color-scheme: light; scroll-behavior: smooth; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body.menu-open { overflow: hidden; }
a { color: var(--gold-dark); text-decoration: none; transition: color var(--ease), background var(--ease), border-color var(--ease); }
a:hover { color: var(--brown); }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button, [type="submit"], [type="button"], .button { -webkit-tap-highlight-color: transparent; }
::selection { background: rgba(169, 130, 75, .24); color: var(--brown); }

/* Autenticación */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(44, 58, 73, .97), rgba(48, 27, 0, .93)),
    var(--ink);
}
.auth-shell::before,
.auth-shell::after {
  content: "";
  position: fixed;
  z-index: -1;
  border: 1px solid rgba(255, 255, 255, .08);
  transform: rotate(45deg);
}
.auth-shell::before { width: 420px; height: 420px; top: -230px; right: -80px; }
.auth-shell::after { width: 320px; height: 320px; bottom: -205px; left: -90px; border-color: rgba(169, 130, 75, .25); }
.auth-card, .login-card, .install-card {
  width: min(100%, 440px);
  padding: clamp(28px, 5vw, 46px);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 20px;
  background: rgba(251, 250, 247, .98);
  box-shadow: var(--shadow-lg);
}
.auth-card > img, .login-card > img, .install-card > img,
.auth-logo, .login-logo { width: min(330px, 92%); max-height: 135px; object-fit: contain; margin: 0 auto 28px; }
.auth-card h1, .login-card h1, .install-card h1 { margin: 0 0 8px; color: var(--brown); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.8rem, 5vw, 2.35rem); font-weight: 500; line-height: 1.14; text-align: center; }
.auth-card > p, .login-card > p, .install-card > p { margin: 0 auto 28px; max-width: 34ch; color: var(--muted); text-align: center; }
.auth-shell form { display: grid; gap: 17px; }
.auth-shell .button, .auth-shell button[type="submit"] { width: 100%; margin-top: 4px; }
.auth-footer { margin: 22px 0 0; color: #85898d; font-size: .8rem; text-align: center; }

/* Estructura principal */
.app-shell { min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  color: rgba(255, 255, 255, .84);
  background: var(--ink-deep);
  box-shadow: 1px 0 rgba(255, 255, 255, .05);
  transition: transform 240ms ease;
}
.sidebar::after { content: ""; height: 3px; position: absolute; inset: 0 0 auto; background: linear-gradient(90deg, transparent, var(--gold), transparent); opacity: .8; }
.brand { display: grid; place-items: center; min-height: 164px; padding: 28px 18px 20px; border-bottom: 1px solid rgba(255, 255, 255, .08); background: rgba(255,255,255,.025); }
.brand img { width: 100%; max-width: 235px; height: 112px; object-fit: contain; filter: brightness(0) invert(1); opacity: .97; }
.sidebar nav { display: grid; gap: 5px; padding: 25px 16px; overflow-y: auto; }
.sidebar nav a { position: relative; display: flex; align-items: center; min-height: 46px; padding: 10px 14px 10px 18px; border-radius: 9px; color: rgba(255, 255, 255, .72); font-size: .92rem; font-weight: 560; letter-spacing: .01em; }
.sidebar nav a::before { content: ""; width: 3px; position: absolute; inset: 10px auto 10px 0; border-radius: 4px; background: var(--gold); opacity: 0; transform: scaleY(.45); transition: var(--ease); }
.sidebar nav a:hover { color: #fff; background: rgba(255, 255, 255, .065); }
.sidebar nav a.active, .sidebar nav a[aria-current="page"] { color: #fff; background: rgba(169, 130, 75, .16); }
.sidebar nav a.active::before, .sidebar nav a[aria-current="page"]::before { opacity: 1; transform: scaleY(1); }
.sidebar-user { margin-top: auto; padding: 20px 28px 26px; border-top: 1px solid rgba(255, 255, 255, .09); display: grid; }
.sidebar-user strong { overflow: hidden; color: #fff; font-size: .91rem; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { margin: 2px 0 12px; color: rgba(255, 255, 255, .48); font-size: .75rem; text-transform: uppercase; letter-spacing: .09em; }
.sidebar-user a { width: max-content; color: #d7bd99; font-size: .82rem; }
.sidebar-user a:hover { color: #fff; }
.content { min-height: 100vh; margin-left: var(--sidebar-width); padding: 0 clamp(24px, 4vw, 56px) 56px; }
.topbar { min-height: 132px; display: flex; align-items: center; gap: 18px; padding: 28px 0 22px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 3px 0 0; color: var(--brown); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.85rem, 3vw, 2.5rem); font-weight: 500; line-height: 1.1; letter-spacing: -.02em; }
.eyebrow { color: var(--gold-dark); font-size: .72rem; font-weight: 750; letter-spacing: .17em; text-transform: uppercase; }
.menu-button { display: none; width: 44px; height: 44px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--paper); font-size: 1.25rem; line-height: 1; cursor: pointer; }
.sidebar-scrim { display: none; position: fixed; inset: 0; z-index: 30; border: 0; background: rgba(25, 27, 29, .52); backdrop-filter: blur(2px); }

/* Contenido, cabeceras y rejillas */
.content > :not(.topbar):first-of-type { margin-top: 28px; }
.page-header, .section-header, .section-heading, .toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 28px 0 18px; }
.page-header h2, .section-header h2, .panel h2, .card h2 { margin: 0; color: var(--brown); font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
.page-header p, .section-header p { margin: 3px 0 0; color: var(--muted); }
.actions, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.grid, .cards, .stats, .dashboard-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; margin: 28px 0; }
.stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow-sm); }
.stat span { display: block; margin-bottom: 8px; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.stat strong { display: block; color: var(--brown); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.25rem, 2vw, 1.85rem); font-weight: 500; line-height: 1.2; overflow-wrap: anywhere; }
.card, .panel, .stat-card, .summary-card, .form-card, .table-card {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}
.card, .panel { grid-column: span 6; }
.form-card, .table-card { margin: 24px 0; }
.stat-card, .summary-card { grid-column: span 3; position: relative; overflow: hidden; }
.stat-card::after, .summary-card::after { content: ""; width: 54px; height: 54px; position: absolute; right: -20px; bottom: -20px; border: 1px solid rgba(169, 130, 75, .26); transform: rotate(45deg); }
.stat-card span, .summary-card span, .stat-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: .74rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.stat-card strong, .summary-card strong, .stat-value { display: block; color: var(--brown); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 3vw, 2.15rem); font-weight: 500; line-height: 1.15; }
.stat-card small, .summary-card small { color: var(--muted); }
.panel-wide, .card-wide { grid-column: span 8; }
.panel-narrow, .card-narrow { grid-column: span 4; }

/* Botones */
.button, button[type="submit"], input[type="submit"] {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 17px;
  border: 1px solid var(--ink);
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--ink);
  box-shadow: 0 3px 10px rgba(44, 58, 73, .12);
  font-weight: 700;
  font-size: .87rem;
  line-height: 1.2;
  cursor: pointer;
  transition: transform var(--ease), box-shadow var(--ease), color var(--ease), background var(--ease);
}
.button:hover, button[type="submit"]:hover, input[type="submit"]:hover { color: #fff; background: var(--brown); border-color: var(--brown); box-shadow: 0 7px 16px rgba(48, 27, 0, .16); transform: translateY(-1px); }
.button:active, button[type="submit"]:active { transform: translateY(0); }
.button.secondary, .button.outline, button.secondary { color: var(--ink); background: transparent; border-color: #c9c4bb; box-shadow: none; }
.button.secondary:hover, .button.outline:hover, button.secondary:hover { color: var(--brown); background: var(--sand); border-color: var(--gold); }
.button.danger, button.danger { color: var(--danger); background: transparent; border-color: #dfb9b4; box-shadow: none; }
.button.danger:hover, button.danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.button.small, .button-sm { min-height: 34px; padding: 6px 11px; font-size: .79rem; }

/* Formularios */
form { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.form-grid .full, .form-group.full, .field.full { grid-column: 1 / -1; }
.form-group, .field, label:has(> input), label:has(> select), label:has(> textarea) { display: grid; gap: 7px; color: var(--ink); font-size: .86rem; font-weight: 680; }
label { color: var(--ink); }
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]), select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d9d4ca;
  border-radius: 8px;
  outline: 0;
  color: var(--brown);
  background: #fff;
  font-size: .94rem;
  font-weight: 450;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}
textarea { min-height: 112px; resize: vertical; }
select { padding-right: 34px; cursor: pointer; }
input::placeholder, textarea::placeholder { color: #a2a2a0; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(169, 130, 75, .14); }
input[disabled], select[disabled], textarea[disabled] { color: #777; background: #f3f1ed; cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 17px; height: 17px; accent-color: var(--ink); }
.help, .hint { color: var(--muted); font-size: .78rem; font-weight: 450; }
.field-error { display: block; color: var(--danger); font-size: .78rem; font-weight: 620; }
.field-error + input, .has-error input, .has-error select, .has-error textarea, [aria-invalid="true"] { border-color: var(--danger); }
.form-actions { grid-column: 1 / -1; margin-top: 8px; padding-top: 20px; border-top: 1px solid var(--line); }
fieldset { margin: 0; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
legend { padding: 0 8px; color: var(--brown); font-family: Georgia, serif; font-size: 1.05rem; }

/* Tablas */
.table-wrap { width: 100%; margin: 22px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow-sm); -webkit-overflow-scrolling: touch; }
.table-card .table-wrap, .panel .table-wrap { margin: 16px 0 0; border-radius: 9px; box-shadow: none; }
table { width: 100%; border-collapse: collapse; border-spacing: 0; color: var(--ink); background: var(--paper); font-size: .88rem; }
thead { background: #f3f0ea; }
th { padding: 13px 16px; color: #62676c; font-size: .71rem; font-weight: 780; letter-spacing: .075em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid #ece8e1; vertical-align: middle; }
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: #fcfaf5; }
td strong { color: var(--brown); }
td:last-child.actions, th:last-child.actions { text-align: right; }
td a:not(.button) { font-weight: 650; }
.money, .amount, td.numeric, th.numeric { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Estados y avisos */
.badge, .status, .pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border: 1px solid #d8d4cd; border-radius: 999px; color: #62676c; background: #f4f2ee; font-size: .71rem; font-weight: 750; letter-spacing: .025em; white-space: nowrap; }
.badge::before, .status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.activo, .status.activo, .pill.activo,
.badge.active, .status.active, .pill.active,
.badge.success, .status.success, .pill.success,
.badge.pagado, .status.pagado, .pill.pagado,
.badge.abono, .status.abono, .pill.abono { color: var(--success); background: var(--success-soft); border-color: #bdd7ca; }
.badge.pausado, .status.pausado, .pill.pausado,
.badge.pending, .status.pending, .pill.pending,
.badge.warning, .status.warning, .pill.warning,
.badge.pendiente, .status.pendiente, .pill.pendiente { color: var(--warning); background: var(--warning-soft); border-color: #ead8a4; }
.badge.cerrado, .status.cerrado, .pill.cerrado,
.badge.inactive, .status.inactive, .pill.inactive,
.badge.danger, .status.danger, .pill.danger,
.badge.vencido, .status.vencido, .pill.vencido,
.badge.cargo, .status.cargo, .pill.cargo { color: var(--danger); background: var(--danger-soft); border-color: #e6c1bc; }
.alert { position: relative; margin: 24px 0; padding: 14px 44px 14px 16px; border: 1px solid #cbd5dd; border-left: 4px solid var(--ink); border-radius: var(--radius-sm); color: var(--ink); background: #edf2f5; box-shadow: var(--shadow-sm); }
.alert.success { color: var(--success); background: var(--success-soft); border-color: #bdd7ca; border-left-color: var(--success); }
.alert.error, .alert.danger { color: var(--danger); background: var(--danger-soft); border-color: #e6c1bc; border-left-color: var(--danger); }
.alert.warning { color: var(--warning); background: var(--warning-soft); border-color: #ead8a4; border-left-color: var(--warning); }
.alert-close { width: 30px; height: 30px; position: absolute; top: 9px; right: 9px; border: 0; border-radius: 50%; color: currentColor; background: transparent; cursor: pointer; opacity: .65; }
.alert-close:hover { background: rgba(0,0,0,.06); opacity: 1; }
.empty { min-height: 290px; display: grid; place-items: center; align-content: center; padding: 45px 24px; border: 1px dashed #d1c7b7; border-radius: var(--radius); background: rgba(255,255,255,.7); text-align: center; }
.empty > span { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 16px; border: 1px solid #d8c8af; transform: rotate(45deg); color: var(--gold); font-size: 1.25rem; }
.empty > span::first-letter { transform: rotate(-45deg); }
.empty h2 { margin: 0 0 7px; color: var(--brown); font-family: Georgia, serif; font-size: 1.42rem; font-weight: 500; }
.empty p { max-width: 48ch; margin: 0 0 20px; color: var(--muted); }

/* Detalles y utilidades */
.detail-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 0; }
.detail-list > div { padding: 14px 0; border-bottom: 1px solid var(--line); }
.detail-list dt { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.detail-list dd { margin: 3px 0 0; color: var(--brown); }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.stack { display: grid; gap: 18px; }
.divider { height: 1px; margin: 22px 0; border: 0; background: var(--line); }
.sr-only { width: 1px; height: 1px; position: absolute; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

/* Adaptación */
@media (max-width: 1100px) {
  :root { --sidebar-width: 240px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card, .summary-card { grid-column: span 6; }
  .panel-wide, .panel-narrow, .card-wide, .card-narrow { grid-column: span 6; }
}
@media (max-width: 820px) {
  .sidebar { width: min(292px, 86vw); transform: translateX(-102%); box-shadow: 18px 0 50px rgba(0,0,0,.18); }
  .menu-open .sidebar { transform: translateX(0); }
  .menu-open .sidebar-scrim { display: block; }
  .content { margin-left: 0; padding: 0 20px 40px; }
  .topbar { min-height: 104px; padding: 22px 0 18px; }
  .menu-button { display: inline-grid; place-items: center; }
  .card, .panel, .panel-wide, .panel-narrow, .card-wide, .card-narrow { grid-column: 1 / -1; }
  .brand { min-height: 136px; }
}
@media (max-width: 620px) {
  body { font-size: 14px; }
  .auth-shell { align-items: start; padding: 20px 14px; }
  .auth-card, .login-card, .install-card { margin-top: max(12px, 5vh); padding: 28px 22px; border-radius: 16px; }
  .content { padding-inline: 15px; }
  .topbar h1 { font-size: 1.7rem; }
  .eyebrow { font-size: .66rem; }
  .grid, .cards, .stats, .dashboard-grid { gap: 13px; margin: 20px 0; }
  .stats { grid-template-columns: 1fr; }
  .stat-card, .summary-card { grid-column: 1 / -1; padding: 19px; }
  .card, .panel, .form-card, .table-card { padding: 18px; border-radius: 11px; }
  .page-header, .section-header, .section-heading, .toolbar { align-items: stretch; flex-direction: column; margin-top: 22px; }
  .page-header .button, .section-header .button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; gap: 16px; }
  .form-grid > *, .form-grid .full { grid-column: 1; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button, .form-actions button { width: 100%; }
  .table-wrap { margin-inline: 0; border-radius: 10px; }
  table { min-width: 660px; }
  th, td { padding-inline: 13px; }
  .empty { min-height: 245px; padding: 34px 18px; }
  .detail-list { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media print {
  body { background: #fff; color: #000; }
  .sidebar, .menu-button, .sidebar-scrim, .button, button, .form-actions { display: none !important; }
  .content { margin: 0; padding: 0; }
  .topbar { min-height: auto; padding: 0 0 18px; }
  .card, .panel, .table-wrap { box-shadow: none; break-inside: avoid; }
}
