:root {
  --bg: #f3f4ef;
  --surface: #ffffff;
  --ink: #1d2a24;
  --muted: #69746d;
  --line: #d8ddd2;
  --accent: #2f6b4f;
  --accent-dark: #1f4c38;
  --gold: #cda45b;
  --danger: #a5452f;
  --blue: #315f7d;
  --shadow: 0 14px 34px rgba(29, 42, 36, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: grid; grid-template-columns: 270px 1fr; background: var(--bg); color: var(--ink); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button { min-height: 40px; border: 0; border-radius: 7px; background: var(--accent); color: white; cursor: pointer; padding: 0 14px; font-weight: 700; }
button:hover { background: var(--accent-dark); }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); padding: 10px 12px; }
textarea { resize: vertical; }
.sidebar { min-height: 100vh; padding: 22px 16px; background: #18251f; color: #f7faf6; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand-mark { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 8px; background: var(--gold); color: #17231e; font-weight: 800; }
.brand span, .role-switch { display: block; margin-top: 3px; color: #bdc9c0; font-size: 13px; }
.role-select { margin: 8px 0 18px; background: #22342b; border-color: #31483c; color: #fff; }
.nav { display: grid; gap: 6px; }
.nav-item { width: 100%; padding: 11px 12px; background: transparent; color: #dfe8e1; text-align: left; font-weight: 600; }
.nav-item.active, .nav-item:hover { background: #26382f; color: #fff; }
.shell { padding: 26px; overflow: auto; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 22px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 13px; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 19px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.secondary-button { background: #e2e6da; color: var(--ink); }
.secondary-button:hover { background: #d3dacd; }
.section { display: none; }
.active-section { display: block; }
.section-header { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.section-header span { color: var(--muted); font-size: 14px; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric, .panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.metric { padding: 16px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 10px; font-size: 26px; }
.metric.warning strong { color: var(--danger); }
.metric.info strong { color: var(--blue); }
.content-grid, .assistant-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.panel { padding: 18px; }
.panel-header { margin-bottom: 12px; }
.form-grid { display: grid; gap: 10px; margin-bottom: 16px; }
.wide-form { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.form-grid button { min-height: 42px; }
.filters { margin-bottom: 12px; max-width: 520px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: white; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; background: #fafbf7; }
.list { display: grid; gap: 10px; }
.empty { color: var(--muted); }
.list-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcf8; }
.item-main strong, .item-main span { display: block; }
.item-main span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; background: #e8eee8; color: var(--accent-dark); padding: 5px 9px; font-size: 12px; white-space: nowrap; }
.pill.warn { background: #f6e4dc; color: var(--danger); }
.pill.info { background: #e4edf3; color: var(--blue); }
.assistant-answer { min-height: 170px; color: var(--ink); line-height: 1.5; white-space: pre-wrap; }
@media (max-width: 1100px) { .metrics-grid, .content-grid, .assistant-grid, .wide-form { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { body { grid-template-columns: 1fr; } .sidebar { min-height: auto; } .shell { padding: 18px; } .topbar, .section-header { align-items: flex-start; flex-direction: column; } .metrics-grid, .content-grid, .assistant-grid, .wide-form { grid-template-columns: 1fr; } }

@media (max-width: 760px) {
  .brand { margin-bottom: 14px; }
  .role-select { margin-bottom: 12px; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item { min-height: 44px; padding: 10px 8px; text-align: center; font-size: 13px; }
  .actions { width: 100%; }
  .actions button { flex: 1 1 150px; }
  .metric strong { font-size: 24px; }
  .section-header span { font-size: 13px; }
  .table-wrap { border-radius: 7px; -webkit-overflow-scrolling: touch; }
  table { min-width: 820px; }
  th, td { padding: 10px; font-size: 13px; }
  .list-item { align-items: flex-start; flex-direction: column; }
  .pill { white-space: normal; }
}
@media (max-width: 430px) {
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 25px; }
  h2 { font-size: 17px; }
  .shell { padding: 14px; }
  .sidebar { padding: 16px 12px; }
}

.manager-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.manager-hero h2 { font-size: 28px; }
.manager-status {
  min-width: 240px;
  padding: 14px 16px;
  border-radius: 8px;
  background: #edf3ec;
  color: var(--accent-dark);
  font-weight: 800;
  text-align: center;
}
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.quick-actions button {
  min-height: 76px;
  padding: 12px;
  font-size: 17px;
  line-height: 1.25;
}
.manager-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}
.important-panel {
  border-color: #d5b47b;
}
.compact-answer {
  min-height: 92px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcf8;
}
body.manager-mode .shell { font-size: 17px; }
body.manager-mode .nav-item { min-height: 46px; }
body.manager-mode input,
body.manager-mode select,
body.manager-mode textarea,
body.manager-mode button { font-size: 17px; }
@media (max-width: 900px) {
  .manager-hero { align-items: flex-start; flex-direction: column; }
  .manager-status { width: 100%; text-align: left; }
  .quick-actions, .manager-grid { grid-template-columns: 1fr; }
  .quick-actions button { min-height: 62px; }
}

.assistant-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  min-width: 142px;
  min-height: 54px;
  border-radius: 999px;
  box-shadow: 0 16px 38px rgba(29, 42, 36, 0.22);
}
.assistant-dock {
  position: fixed;
  right: 22px;
  bottom: 88px;
  z-index: 31;
  display: none;
  width: min(420px, calc(100vw - 28px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 54px rgba(29, 42, 36, 0.22);
}
.assistant-dock.open { display: block; }
.assistant-dock-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.assistant-dock-header span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}
.icon-button {
  min-height: 34px;
  padding: 0 10px;
  background: #e2e6da;
  color: var(--ink);
  font-size: 13px;
}
.assistant-mode-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}
.dock-answer {
  max-height: 220px;
  overflow: auto;
  margin-top: 10px;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcf8;
  font-size: 14px;
}
@media (max-width: 760px) {
  .assistant-fab {
    right: 14px;
    bottom: 14px;
    min-width: 126px;
  }
  .assistant-dock {
    right: 14px;
    bottom: 78px;
  }
}

.stage-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}
.stage-form {
  grid-template-columns: repeat(2, minmax(150px, 1fr));
}
.hint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}
.timeline-panel { margin-top: 18px; }
.timeline-list {
  display: grid;
  gap: 14px;
}
.workflow-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  padding: 14px;
}
.workflow-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.workflow-head span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 13px;
}
.stage-track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}
.stage-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 10px;
}
.stage-card.current {
  border-color: var(--gold);
  background: #fff9eb;
}
.stage-card.late {
  border-color: #d69a87;
  background: #fff2ee;
}
.stage-card.done {
  background: #eef5ee;
}
.stage-card strong,
.stage-card span { display: block; }
.stage-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}
.stage-actions {
  display: flex;
  gap: 8px;
  margin-top: 9px;
  flex-wrap: wrap;
}
.stage-actions button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}
@media (max-width: 900px) {
  .stage-layout, .stage-form { grid-template-columns: 1fr; }
}

.trace-search-panel { margin-bottom: 18px; }
.trace-search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.trace-result {
  display: grid;
  gap: 14px;
}
.trace-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 16px;
}
.trace-card h3 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0;
}
.trace-chain {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.trace-step {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcf8;
  padding: 11px;
}
.trace-step.missing {
  background: #fff2ee;
  border-color: #d69a87;
}
.trace-step strong,
.trace-step span { display: block; }
.trace-step span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.trace-related {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
@media (max-width: 760px) {
  .trace-search { grid-template-columns: 1fr; }
}

.session-chip {
  position: fixed;
  top: 10px;
  right: 14px;
  z-index: 20;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 12px;
  box-shadow: 0 8px 20px rgba(29, 42, 36, 0.08);
}
.session-chip a { color: var(--accent-dark); font-weight: 700; text-decoration: none; }
@media (max-width: 760px) {
  .session-chip { position: static; margin-top: 12px; display: inline-block; }
}

.password-panel { margin-top: 18px; }
.permission-disabled { opacity: 0.58; }
.permission-disabled::after { content: "Solo lectura para este usuario"; display: block; margin-top: 8px; color: var(--muted); font-size: 13px; }

.user-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-actions button { min-height: 32px; padding: 0 9px; font-size: 12px; }

.field-label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field-label input, .field-label select, .field-label textarea { color: var(--ink); font-weight: 400; }
.save-status { min-width: 130px; padding: 9px 12px; border-radius: 7px; background: #e8f1e8; color: var(--accent-dark); text-align: center; font-weight: 700; }
.save-status.saving { background: #fff4d8; color: #76591d; }
.role-badge { margin: 8px 0 18px; padding: 10px 12px; border-radius: 7px; background: #26382f; color: white; font-weight: 700; }
.login-page { display: grid; grid-template-columns: 1fr; min-height: 100vh; place-items: center; padding: 16px; }
.login-box { width: min(440px, 100%); padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: white; box-shadow: var(--shadow); }
.login-box form { display: grid; gap: 14px; }
.login-brand { color: var(--ink); }
.login-error { margin-bottom: 14px; padding: 11px; border-radius: 7px; background: #fff2ee; color: var(--danger); }
.assistant-mode-label { align-self: center; color: var(--muted); font-size: 13px; font-weight: 700; }
@media (max-width: 760px) {
  .table-wrap { border: 0; overflow: visible; background: transparent; }
  table, thead, tbody, tr, th, td { display: block; min-width: 0; width: 100%; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tbody tr { border: 1px solid var(--line); border-radius: 8px; background: white; padding: 8px 12px; box-shadow: 0 8px 20px rgba(29,42,36,.05); }
  tbody td { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 10px; border: 0; padding: 8px 0; }
  tbody td::before { content: attr(data-label); color: var(--muted); font-weight: 700; }
  .topbar .actions { display: grid; grid-template-columns: 1fr; }
  .save-status { width: 100%; }
}

[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #cda45b; outline-offset: 2px; }
.small-button { min-height: 34px; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.login-title { margin: 0 0 8px; font-size: 24px; }
.cancel-edit { background: #e2e6da; color: var(--ink); }
@media (max-width: 760px) { .small-button { width: 100%; min-height: 42px; } .assistant-fab { min-height: 58px; } }


.report-heading > div:first-child span { display: block; margin-top: 4px; }
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.report-filter-bar { display: grid; grid-template-columns: repeat(4, minmax(145px, 1fr)); gap: 10px; margin-bottom: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.report-filter-bar label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.report-filter-actions { display: flex; align-items: end; gap: 8px; }
.report-filter-actions button { flex: 1; }
.report-loading { margin-bottom: 14px; padding: 12px; border-left: 4px solid var(--gold); background: #fff9eb; font-weight: 700; }
.report-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.report-metric { min-height: 98px; padding: 15px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.report-metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.report-metric strong { display: block; margin-top: 12px; font-size: 22px; overflow-wrap: anywhere; }
.report-metric.good strong { color: var(--accent-dark); }
.report-metric.warn strong { color: var(--danger); }
.report-metric.info strong { color: var(--blue); }
.report-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.report-chart { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.report-chart h3 { margin: 0 0 14px; font-size: 16px; }
.bar-list { display: grid; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-size: 13px; }
.bar-label span { color: var(--muted); overflow-wrap: anywhere; }
.bar-track { height: 10px; overflow: hidden; border-radius: 5px; background: #e6eae2; }
.bar-fill { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.bar-fill.negative { background: var(--danger); }
.report-table-panel { margin-bottom: 14px; }
.report-table-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.report-table-head span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.report-notes { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.report-notes p { margin: 0; padding: 10px 12px; border-left: 3px solid var(--gold); background: #fff9eb; }
#reportTable { min-width: 900px; }
@media (max-width: 1000px) { .report-filter-bar { grid-template-columns: repeat(2, minmax(145px, 1fr)); } }
@media (max-width: 760px) {
  .report-filter-bar, .report-charts { grid-template-columns: 1fr; }
  .report-actions, .report-filter-actions { width: 100%; }
  .report-actions button, .report-filter-actions button { flex: 1; }
  .report-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-metric { min-height: 88px; }
  .report-metric strong { font-size: 19px; }
}
@media (max-width: 430px) { .report-metrics { grid-template-columns: 1fr; } }
@media print {
  @page { size: landscape; margin: 10mm; }
  body { display: block; background: white; color: black; }
  .sidebar, .topbar, .assistant-fab, .assistant-dock, .report-actions, .report-filter-bar, .report-loading { display: none !important; }
  .shell { padding: 0; overflow: visible; }
  .section { display: none !important; }
  #reportes { display: block !important; }
  .report-metrics { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .report-metric, .report-chart { box-shadow: none; break-inside: avoid; }
  .report-charts { grid-template-columns: repeat(2, 1fr); }
  #reportTable, #reportTable thead, #reportTable tbody, #reportTable tr, #reportTable th, #reportTable td { display: table; width: auto; min-width: 0; }
  #reportTable { display: table; width: 100%; border-collapse: collapse; font-size: 8pt; }
  #reportTable thead { display: table-header-group; }
  #reportTable tbody { display: table-row-group; }
  #reportTable tr { display: table-row; break-inside: avoid; }
  #reportTable th, #reportTable td { display: table-cell; padding: 4px; border: 1px solid #bbb; }
  #reportTable td::before { display: none; }
  .table-wrap { overflow: visible; border: 0; }
  .report-notes p { background: white; }
}


.payroll-notice { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; padding: 12px 14px; border-left: 4px solid var(--gold); background: #fff; }
.payroll-notice span { color: var(--muted); }
.payroll-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 22px; }
.payroll-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.payroll-form label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
.payroll-form .check-label { display: flex; align-items: center; gap: 9px; min-height: 42px; color: var(--ink); }
.payroll-form .check-label input { width: 20px; height: 20px; }
.payroll-list { display: grid; gap: 8px; max-height: 430px; overflow: auto; }
.payroll-person { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 11px; border: 1px solid var(--line); border-radius: 7px; }
.payroll-person span, .payroll-rule-summary span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.payroll-rule-summary { display: grid; gap: 5px; padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcf8; }
.payroll-period-heading { margin-top: 8px; }
.payroll-periods { display: grid; gap: 14px; }
.payroll-period-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.payroll-period-top h3 { margin: 0 0 4px; }
.payroll-period-top span { color: var(--muted); font-size: 13px; }
.payroll-totals { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 8px; margin: 14px 0; }
.payroll-totals div { padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcf8; }
.payroll-totals span, .payroll-totals strong { display: block; }
.payroll-totals span { color: var(--muted); font-size: 12px; }
.payroll-totals strong { margin-top: 5px; }
.payroll-period details summary { cursor: pointer; padding: 10px 0; font-weight: 700; }
.payroll-table { min-width: 1900px; }
.payroll-table input { min-width: 92px; padding: 7px; }
.payroll-table td small { display: block; margin-top: 3px; color: var(--muted); }
.payroll-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.payroll-error { color: var(--danger); }
@media (max-width: 1100px) { .payroll-layout { grid-template-columns: 1fr; } .payroll-totals { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 760px) {
  .payroll-notice { align-items: flex-start; flex-direction: column; }
  .payroll-form { grid-template-columns: 1fr; }
  .payroll-totals { grid-template-columns: repeat(2, 1fr); }
  .payroll-person { align-items: flex-start; flex-direction: column; }
  .payroll-person button, .payroll-actions button { width: 100%; min-height: 48px; }
}
@media (max-width: 430px) { .payroll-totals { grid-template-columns: 1fr; } }

.payroll-tax-brackets { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 7px; }
.payroll-tax-brackets legend { font-weight: 700; }
@media(max-width:760px){.payroll-tax-brackets{grid-template-columns:1fr}}
