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

:root {
  --sky: #5BAED6;
  --sky-light: #87CEEB;
  --sky-pale: #EBF6FD;
  --sky-border: #C8E8F7;
  --white: #ffffff;
  --gray-50: #F8FAFB;
  --gray-100: #F0F4F7;
  --gray-200: #E2E8ED;
  --gray-300: #CBD5DC;
  --gray-400: #9AAAB6;
  --gray-500: #6B7D8A;
  --gray-700: #374955;
  --gray-900: #1A2830;
  --green: #2DAA6E;
  --green-bg: #EAF7F1;
  --red: #D94040;
  --red-bg: #FDF0F0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 4px 24px rgba(91,174,214,0.13), 0 1px 4px rgba(0,0,0,0.05);
  --font: 'DM Sans', sans-serif;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
  padding: 0 0 60px;
}

/* ── Header ── */
header {
  background: var(--white);
  border-bottom: 1.5px solid var(--gray-200);
  padding: 18px 32px 0;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 10px rgba(91,174,214,0.08);
}
.header-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.logo {
  display: flex; align-items: center; justify-content: center;
  overflow: visible;
}
.logo img { max-height: 2rem; width: auto; height: auto; }
h1 { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.02em; color: var(--gray-900); }

/* ── Save status badge ── */
.save-status {
  margin-left: auto;
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 500; color: var(--gray-400);
  transition: color 0.2s;
  min-width: 120px; justify-content: flex-end;
}
.save-status.saving { color: var(--sky); }
.save-status.saved  { color: var(--green); }
.save-status.error  { color: var(--red); }
.save-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.save-status.saving .save-dot { animation: pulse 0.8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── Tabs ── */
.tabs { display: flex; }
.tab-btn {
  padding: 10px 24px; border: none; background: none;
  font-family: var(--font); font-size: 0.9rem; font-weight: 500;
  color: var(--gray-400); cursor: pointer;
  border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
  transition: color 0.18s, border-color 0.18s;
  letter-spacing: -0.01em; white-space: nowrap;
}
.tab-btn:hover { color: var(--sky); }
.tab-btn.active { color: var(--sky); border-bottom-color: var(--sky); font-weight: 600; }

/* ── Main ── */
main { padding: 28px 16px 0; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tables-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }

/* ── Card ── */
.card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-card); border: 1.5px solid var(--gray-200); overflow: hidden;
}
.card-header {
  padding: 16px 20px 14px; border-bottom: 1.5px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--white);
}
.card-title-group { display: flex; align-items: center; gap: 10px; }
.card-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.card-title { font-size: 0.88rem; font-weight: 600; letter-spacing: -0.01em; color: var(--gray-700); }
.card-subtitle { font-size: 0.75rem; color: var(--gray-400); font-weight: 400; margin-top: 1px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; table-layout: auto; }
thead th {
  background: var(--gray-50); color: var(--gray-500); font-weight: 500;
  font-size: 0.76rem; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 9px 12px; text-align: left; border-bottom: 1.5px solid var(--gray-200); white-space: nowrap;
}
thead th:first-child { min-width: 14rem; }
thead th:last-child { width: auto; min-width: 2.5rem; }
thead th.col-total { text-align: right; }

/* Tooltip wrapper */
.tooltip-wrapper {
  position: relative;
  overflow: visible;
  display: block;
}

.tooltip-wrapper:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: var(--white);
  padding: 0.4rem 0.75rem;
  border-radius: 0.25rem;
  white-space: nowrap;
  font-size: 0.75rem;
  z-index: 1000;
  font-weight: 500;
  pointer-events: none;
  box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.15);
  animation: tooltipFadeIn 0.2s ease-out;
}

.tooltip-wrapper:hover::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 0.125rem);
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 0.3rem solid transparent;
  border-right: 0.3rem solid transparent;
  border-top: 0.3rem solid var(--gray-900);
  z-index: 1000;
  pointer-events: none;
}

@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(0.25rem); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--sky-pale); }
tbody td { padding: 0; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody td input {
  width: 100%; border: none; outline: none; background: transparent;
  font-family: var(--font); font-size: 0.84rem; color: var(--gray-900);
  padding: 9px 12px; transition: background 0.12s;
}
tbody td input:focus {
  background: var(--sky-pale);
  box-shadow: inset 0 0 0 1.5px var(--sky-light); border-radius: 3px;
}
tbody td input[type="number"] { text-align: right; }
tbody td.td-total { padding: 9px 12px; text-align: right; font-weight: 500; color: var(--gray-700); white-space: nowrap; font-feature-settings: "tnum"; }
tbody td.td-actions { padding: 4px 8px; text-align: center; width: auto; display: flex; gap: 4px; justify-content: center; align-items: center; }

/* row saving indicator */
tbody tr.row-saving td { opacity: 0.55; }
tbody tr.row-error { background: #fff5f5; }

.btn-delete {
  width: 26px; height: 26px; border: none; background: var(--gray-100);
  color: var(--gray-400); border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.14s, color 0.14s; font-size: 14px; line-height: 1;
}
.btn-delete:hover { background: #FDEAEA; color: var(--red); }
.btn-delete:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-save {
  width: 26px; height: 26px; border: none; background: var(--gray-100);
  color: var(--gray-400); border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.14s, color 0.14s; font-size: 12px; line-height: 1;
}
.btn-save:hover { background: #E8F5E9; color: var(--green); }
.btn-save:disabled { opacity: 0.4; cursor: not-allowed; }

tfoot tr { background: var(--gray-50); border-top: 2px solid var(--gray-200); }
tfoot td { padding: 10px 12px; font-size: 0.83rem; color: var(--gray-500); font-weight: 500; }
tfoot td.tfoot-total { text-align: right; font-size: 0.95rem; font-weight: 600; color: var(--gray-900); font-feature-settings: "tnum"; letter-spacing: -0.01em; white-space: nowrap; }

.card-footer { padding: 12px 16px; border-top: 1.5px solid var(--gray-100); }
.btn-add {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 1.5px dashed var(--sky-border);
  background: var(--sky-pale); color: var(--sky);
  font-family: var(--font); font-size: 0.82rem; font-weight: 500;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.14s, border-color 0.14s; letter-spacing: -0.01em;
}
.btn-add:hover { background: #D4ECFA; border-color: var(--sky); }
.btn-add:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-add i { font-size: 13px; }

/* ── Resumen ── */
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.summary-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-card); border: 1.5px solid var(--gray-200); overflow: hidden; }
.summary-header { padding: 16px 20px; border-bottom: 1.5px solid var(--gray-200); display: flex; align-items: center; gap: 10px; }
.summary-title { font-size: 0.88rem; font-weight: 600; color: var(--gray-700); letter-spacing: -0.01em; }
.summary-body { padding: 20px; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 6px; background: var(--gray-50); border: 1px solid var(--gray-100); }
.summary-row-label { font-size: 0.82rem; color: var(--gray-500); font-weight: 400; }
.summary-row-value { font-size: 0.88rem; font-weight: 600; color: var(--gray-700); font-feature-settings: "tnum"; letter-spacing: -0.01em; white-space: nowrap; }
.summary-divider { height: 1.5px; background: var(--gray-200); margin: 14px 0; }
.summary-result { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-radius: var(--radius-sm); border: 2px solid; }
.summary-result.positive { background: var(--green-bg); border-color: #A8DDBF; }
.summary-result.negative { background: var(--red-bg); border-color: #F0BCBC; }
.summary-result.neutral  { background: var(--gray-50); border-color: var(--gray-200); }
.result-label { font-size: 0.82rem; font-weight: 500; color: var(--gray-500); }
.result-value { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.03em; font-feature-settings: "tnum"; }
.result-value.positive { color: var(--green); }
.result-value.negative { color: var(--red); }
.result-value.neutral   { color: var(--gray-500); }
.result-badge { display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 600; padding: 3px 8px; border-radius: 20px; margin-top: 4px; letter-spacing: 0.03em; text-transform: uppercase; }
.result-badge.positive { background: #C1EDD5; color: #1D8350; }
.result-badge.negative { background: #F6CCCC; color: #A83030; }
.result-info { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 999;
  font-size: 0.9rem; color: var(--gray-500); font-family: var(--font);
}
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--sky-border);
  border-top-color: var(--sky); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay.hidden { display: none; }

/* ── Mobile ── */
@media (max-width: 780px) {
  header { padding: 14px 16px 0; }
  main { padding: 18px 16px 0; }
  .tables-row, .summary-grid { grid-template-columns: 1fr; }
  .tab-btn { padding: 10px 14px; font-size: 0.82rem; }
  .save-status span { display: none; }
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

@keyframes rowIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row-new { animation: rowIn 0.18s ease; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; font-family: var(--font);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  padding: 28px 24px; max-width: 360px; width: 90%;
}
.modal-title {
  font-size: 1rem; font-weight: 600;
  color: var(--gray-900); margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.modal-text {
  font-size: 0.88rem; color: var(--gray-500);
  line-height: 1.5; margin-bottom: 20px;
}
.modal-buttons {
  display: flex; gap: 10px; justify-content: flex-end;
}
.btn-modal {
  padding: 8px 16px; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-size: 0.85rem; font-weight: 500;
  transition: background 0.14s, color 0.14s;
  letter-spacing: -0.01em;
}
.btn-modal.cancel {
  background: var(--gray-100); color: var(--gray-700);
}
.btn-modal.cancel:hover { background: var(--gray-200); }
.btn-modal.confirm {
  background: var(--sky); color: var(--white);
}
.btn-modal.confirm:hover { background: #4A9ECB; }
.btn-modal.delete {
  background: var(--red); color: var(--white);
}
.btn-modal.delete:hover { background: #C73232; }

/* ── Logout button ── */
.btn-logout {
  position: fixed; bottom: 24px; right: 24px;
  padding: 10px 18px; background: var(--sky);
  color: var(--white); border: none;
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-size: 0.85rem; font-weight: 500;
  box-shadow: 0 4px 12px rgba(91,174,214,0.25);
  transition: background 0.14s, box-shadow 0.14s;
  z-index: 99; letter-spacing: -0.01em;
}
.btn-logout:hover {
  background: #4A9ECB;
  box-shadow: 0 6px 16px rgba(91,174,214,0.35);
}
.btn-logout:active { transform: scale(0.98); }

@media (max-width: 480px) {
  .modal { max-width: 85%; }
  .btn-logout { bottom: 16px; right: 16px; padding: 9px 14px; font-size: 0.8rem; }
}
