:root {
  --olive:        #A8B36B;
  --olive-dark:   #7E8C4A;
  --olive-light:  #D4DBB0;
  --gold:         #C9A961;
  --gold-light:   #E3D4A8;
  --beige:        #F5F0E1;
  --bg:           #FAFAF7;
  --surface:      #FFFFFF;
  --text:         #3C3C3C;
  --text-soft:    #777;
  --border:       #E8E4D8;
  --danger:       #C86B6B;
  --success:      #7FA87F;
  --warning:      #D9B36C;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 8px rgba(0,0,0,0.05);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.08);
  --sidebar-w:    260px;
  --sidebar-w-collapsed: 68px;
  --header-h:     64px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* HEADER */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.header-left, .header-right { display: flex; align-items: center; gap: 16px; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--olive), var(--olive-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px; box-shadow: var(--shadow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-small { font-size: 10px; letter-spacing: 2px; color: var(--gold); font-weight: 500; }
.brand-big { font-size: 18px; font-weight: 700; color: var(--olive-dark); letter-spacing: 3px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text); transition: all 0.2s;
}
.icon-btn:hover { background: var(--beige); color: var(--olive-dark); }

.save-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; background: var(--beige);
  border-radius: 20px; font-size: 12px; color: var(--text-soft);
}
.save-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); transition: background 0.3s;
}
.save-indicator.saving .dot { background: var(--warning); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.company-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--beige); padding: 4px 10px; border-radius: var(--radius-sm);
}
.company-selector label { font-size: 12px; color: var(--text-soft); }
.company-selector select {
  border: none; background: transparent; padding: 4px 8px;
  font-weight: 500; cursor: pointer; outline: none; max-width: 160px;
}

.settings-menu {
  position: absolute;
  top: calc(var(--header-h) - 8px);
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px; min-width: 240px; z-index: 200;
  max-height: 80vh; overflow-y: auto;
}
.settings-menu.hidden { display: none; }
.settings-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
  text-align: left; font-size: 13px; transition: background 0.15s;
}
.settings-menu button:hover { background: var(--beige); }
.settings-menu button.danger { color: var(--danger); }
.settings-menu button.danger:hover { background: #FBEEEE; }
.settings-menu hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

/* LAYOUT */
.app-layout { display: flex; min-height: calc(100vh - var(--header-h)); }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  transition: width 0.25s ease, padding 0.25s ease;
  flex-shrink: 0; position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); padding: 20px 8px; }
.sidebar.collapsed .nav-txt, .sidebar.collapsed .nav-title { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; }

.nav-group { margin-bottom: 24px; }
.nav-title {
  font-size: 10px; letter-spacing: 1.5px; color: var(--gold);
  text-transform: uppercase; padding: 0 12px;
  margin-bottom: 8px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: 13.5px; font-weight: 500;
  margin-bottom: 3px; transition: all 0.18s; text-align: left;
}
.nav-item:hover { background: var(--beige); color: var(--olive-dark); }
.nav-item.active {
  background: linear-gradient(90deg, var(--olive), var(--olive-dark));
  color: #fff; box-shadow: var(--shadow);
}
.nav-ico { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }

.main-content { flex: 1; padding: 28px; overflow-x: auto; min-width: 0; }

.view-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.view-title { font-size: 24px; font-weight: 700; color: var(--olive-dark); margin-bottom: 4px; }
.view-subtitle { color: var(--text-soft); font-size: 13.5px; }
.view-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.badge-niif {
  display: inline-block;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: #fff; font-size: 10.5px; font-weight: 700;
  letter-spacing: 1px; padding: 4px 10px; border-radius: 20px;
  margin-left: 8px; vertical-align: middle;
}

.btn {
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; transition: all 0.18s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-primary { background: linear-gradient(135deg, var(--olive), var(--olive-dark)); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--beige); color: var(--olive-dark); }
.btn-secondary:hover { background: var(--olive-light); }
.btn-danger { background: #FBEEEE; color: var(--danger); }
.btn-danger:hover { background: #F5D5D5; }
.btn-gold { background: linear-gradient(135deg, var(--gold), #B89850); color: #fff; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 14px;
  margin-bottom: 16px; max-width: 380px;
}
.search-box input { border: none; background: transparent; outline: none; width: 100%; }
.search-box::before { content: '🔍'; font-size: 13px; opacity: 0.6; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 18px;
  overflow: hidden; box-shadow: var(--shadow);
}
.card-header {
  padding: 14px 20px; background: var(--beige);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
}
.card-header h3 {
  font-size: 14px; font-weight: 600; color: var(--olive-dark);
  letter-spacing: 0.5px; text-transform: uppercase;
}
.card-header .toggle { transition: transform 0.2s; color: var(--text-soft); }
.card.collapsed .card-header .toggle { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }

.fin-table { width: 100%; border-collapse: collapse; }
.fin-table thead th {
  background: #F4F1E7; text-align: right;
  padding: 10px 16px; font-size: 11.5px; font-weight: 600;
  color: var(--olive-dark); text-transform: uppercase;
  letter-spacing: 0.6px; border-bottom: 1px solid var(--border);
}
.fin-table thead th:first-child { text-align: left; }

.fin-table tbody td {
  padding: 6px 16px; border-bottom: 1px solid #F4F1E7;
  font-size: 13.5px; vertical-align: middle;
}
.fin-table tbody td.cell-label { text-align: left; }
.fin-table tbody td.cell-var-abs,
.fin-table tbody td.cell-var-pct { text-align: right; font-size: 12.5px; color: var(--text-soft); }
.fin-table tbody tr:hover { background: #FBFAF4; }

.data-row.calculated { background: #F7F5EC; font-weight: 600; }
.data-row.calculated td { color: var(--olive-dark); }

.cell-input {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 6px 8px; border-radius: 6px; text-align: right;
  font-size: 13.5px; transition: all 0.15s;
}
.cell-input:hover { border-color: var(--border); }
.cell-input:focus {
  outline: none; border-color: var(--olive);
  background: #fff; box-shadow: 0 0 0 3px rgba(168,179,107,0.15);
}

.info-tip {
  color: var(--gold); font-size: 11px; cursor: help;
  margin-left: 6px; opacity: 0.7; transition: opacity 0.2s;
}
.info-tip:hover { opacity: 1; }

.data-row.subtotal { background: #EFF3E0; font-weight: 600; }
.data-row.subtotal td { color: var(--olive-dark); padding: 9px 16px; }
.data-row.total { background: linear-gradient(90deg, var(--olive-light), #E9EED4); font-weight: 700; }
.data-row.total td { color: var(--olive-dark); padding: 11px 16px; font-size: 14px; }

.validation-alert {
  margin-top: 14px; padding: 12px 18px;
  border-radius: var(--radius-sm); font-size: 13px;
  display: flex; align-items: center; gap: 10px;
}
.validation-alert.ok { background: #EAF4EA; color: var(--success); }
.validation-alert.error { background: #FBEEEE; color: var(--danger); }
.validation-alert.warn { background: #FBF4E5; color: var(--warning); }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); transition: transform 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-label { font-size: 11.5px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--olive-dark); margin-bottom: 6px; }
.kpi-status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.kpi-status.good { background: var(--success); }
.kpi-status.warn { background: var(--warning); }
.kpi-status.bad  { background: var(--danger); }
.kpi-hint { font-size: 11px; color: var(--text-soft); }

.charts-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.chart-card h4 {
  font-size: 13.5px; font-weight: 600; color: var(--olive-dark);
  margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.5px;
}
.chart-container { position: relative; height: 280px; }

.compare-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); margin-bottom: 20px;
}
.compare-table th, .compare-table td {
  padding: 12px 16px; text-align: right;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.compare-table th {
  background: var(--beige); color: var(--olive-dark);
  font-weight: 600; text-transform: uppercase;
  font-size: 11.5px; letter-spacing: 0.6px;
}
.compare-table th:first-child, .compare-table td:first-child { text-align: left; }
.compare-table .positive { color: var(--success); font-weight: 500; }
.compare-table .negative { color: var(--danger); font-weight: 500; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(60,60,60,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: modalIn 0.22s ease;
}
.modal.modal-wide { max-width: 780px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 16px; color: var(--olive-dark); font-weight: 600; }
.modal-body { padding: 22px; overflow-y: auto; }

.modal-body label.field {
  display: block; font-size: 12px; color: var(--text-soft);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px; margin-top: 14px;
}
.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); outline: none; transition: all 0.18s;
}
.modal-body input:focus, .modal-body select:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(168,179,107,0.15);
  background: #fff;
}

.modal-body .check-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}
.modal-body .check-row:hover { background: var(--beige); border-color: var(--olive-light); }
.modal-body .check-row input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer;
  accent-color: var(--olive); flex-shrink: 0;
}
.modal-body .check-row span { font-size: 13.5px; color: var(--text); }

.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* EDITOR DE ÍTEMS */
.items-editor-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px;
  background: var(--beige);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  align-items: center;
}
.items-editor-toolbar button { font-size: 12.5px; padding: 7px 12px; }

.items-list {
  max-height: 400px; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.items-group-title {
  background: #F4F1E7;
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--olive-dark);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  position: sticky; top: 0;
}
.item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid #F4F1E7;
  transition: background 0.15s;
}
.item-row:hover { background: #FBFAF4; }
.item-row input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--olive); cursor: pointer; flex-shrink: 0;
}
.item-row .item-label {
  flex: 1; font-size: 13px;
}
.item-row .item-id {
  font-size: 10.5px; color: var(--text-soft);
  font-family: monospace;
  background: var(--beige);
  padding: 2px 6px; border-radius: 4px;
}
.item-row input[type="text"].item-label-input {
  flex: 1; padding: 5px 8px; font-size: 13px;
  border: 1px solid var(--olive);
  border-radius: 4px; outline: none;
  background: #fff;
}

/* TAB SELECTOR */
.tab-selector {
  display: flex; gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab-selector button {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab-selector button:hover { color: var(--olive-dark); }
.tab-selector button.active {
  color: var(--olive-dark);
  border-bottom-color: var(--olive);
  font-weight: 600;
}

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--olive-dark); color: #fff;
  padding: 12px 20px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); z-index: 2000;
  font-size: 13.5px; font-weight: 500;
  animation: toastIn 0.3s ease;
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); }
.toast.gold { background: var(--gold); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: var(--header-h); z-index: 50; box-shadow: var(--shadow-md); }
  .sidebar.collapsed { transform: translateX(-100%); width: var(--sidebar-w); }
  .sidebar.collapsed .nav-txt, .sidebar.collapsed .nav-title { display: block; }
  .main-content { padding: 18px; }
  .charts-grid { grid-template-columns: 1fr; }
  .brand-text { display: none; }
}

@media print {
  .app-header, .sidebar, .view-actions, .search-box,
  .settings-menu, .toast, .modal-overlay, .no-print { display: none !important; }
  .main-content { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; page-break-inside: avoid; }
}