:root {
  color-scheme: light;
  --bg: #fafafa;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --surface: #ffffff;
  --soft: #f4f4f5;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #ecfdf5;
  --warn: #b45309;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(0, 0, 0, .03), 0 8px 24px rgba(0, 0, 0, .035);
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(228, 228, 231, .85);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(16px);
}

.header-container {
  display: flex;
  width: min(1280px, 100%);
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto;
  padding: 12px 24px;
}

.header-brand-block, .header-actions { display: flex; align-items: center; gap: 12px; }
.header-brand-block { min-width: 0; }
.header-divider { width: 1px; height: 32px; background: var(--line); }
.module-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.module-mark svg { width: 19px; height: 19px; }
.header-brand { margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; }
h1 { margin: 1px 0 0; font-size: 18px; font-weight: 600; letter-spacing: 0; }
h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0; }

.back-link, .context-badge, .date-badge, .month-filter-badge, button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 11px;
  color: #3f3f46;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
}
.back-link svg, .context-badge svg, button svg { width: 15px; height: 15px; }
.back-link:hover, button.secondary:hover { background: #f4f4f5; }
.back-link:active, button:active { transform: translateY(1px); }
.context-badge { border-color: #d1fae5; background: var(--accent-soft); color: var(--accent-dark); }
.date-badge { color: var(--muted); }
.month-filter-badge {
  align-items: stretch;
  gap: 8px;
  border-color: var(--line);
  background: #fff;
  padding: 4px 6px 4px 10px;
}
.month-filter-badge span {
  align-self: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.month-filter-badge select {
  width: auto;
  min-width: 132px;
  min-height: 28px;
  border: 0;
  background: #fafafa;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

main { width: min(1280px, 100%); margin: 0 auto; padding: 24px 24px 42px; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.metric-card, .panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-card { padding: 16px; }
.metric-card span, label span, .formula-list span, .eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.metric-card span {
  display: block;
  min-height: 18px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  line-height: 1.15;
}
.metric-card strong { display: block; margin-top: 8px; font-size: 24px; font-weight: 650; letter-spacing: 0; text-align: center; }
.malote-metric { border-color: #bfdbfe; background: linear-gradient(180deg, #eff6ff, #fff); color: #1d4ed8; }
.lion-metric, .lion-metric.lion-low { border-color: #bfdbfe; background: linear-gradient(180deg, #eff6ff, #fff); color: #1d4ed8; }
.lion-metric.lion-mid { border-color: #fde68a; background: linear-gradient(180deg, #fffbeb, #fff); color: #b45309; }
.lion-metric.lion-high { border-color: #fecaca; background: linear-gradient(180deg, #fef2f2, #fff); color: #b91c1c; }
.cash-metric { border-color: #fed7aa; background: linear-gradient(180deg, #fff7ed, #fff); color: #c2410c; }
.balance-metric { border-color: #fde68a; background: linear-gradient(180deg, #fffbeb, #fff); }
.year-metric { border-color: #d4d4d8; background: linear-gradient(180deg, #f4f4f5, #fff); color: #52525b; }
.progress-bar {
  width: 100%;
  height: 10px;
  overflow: hidden;
  margin-top: 12px;
  border-radius: 999px;
  background: #e4e4e7;
}
.progress-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #2563eb);
  transition: width .18s ease;
}
.lion-metric.lion-low .progress-bar i { background: linear-gradient(90deg, #60a5fa, #1d4ed8); }
.lion-metric.lion-mid .progress-bar i { background: linear-gradient(90deg, #facc15, #b45309); }
.lion-metric.lion-high .progress-bar i { background: linear-gradient(90deg, #f87171, #b91c1c); }
.progress-metric small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, .8fr); gap: 16px; margin-top: 16px; }
.event-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.event-picker-card {
  min-height: 96px;
  justify-content: flex-start;
  align-items: center;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
  padding: 14px;
  text-align: left;
}
.event-picker-card.active { border-color: #0f766e; background: #ecfdf5; color: #115e59; }
.event-picker-card:hover {
  border-color: #0f766e;
  background: #f0fdfa;
  color: #115e59;
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(15, 118, 110, .12);
}
.event-picker-card strong { font-size: 12px; line-height: 1.25; letter-spacing: .02em; }
.event-picker-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  background: #f4f4f5;
}
.event-picker-card.active .event-picker-icon { background: #d1fae5; }
.event-picker-icon svg { width: 18px; height: 18px; }
.event-entry-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 12px; }
.event-entry-grid + .panel { margin-top: 26px; }
.panel { padding: 18px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-heading.compact { align-items: center; }
.eyebrow { display: block; margin: 0 0 5px; color: var(--accent); }
.panel-icon {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  background: var(--soft);
  color: var(--accent-dark);
}
.panel-icon svg { width: 18px; height: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.event-form-grid { display: grid; grid-template-columns: repeat(2, minmax(160px, 1fr)); gap: 14px; }
label { display: grid; min-width: 0; gap: 7px; }
label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reason-field { grid-column: 1 / -1; }
.wide-field { grid-column: 1 / -1; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  border: 1px solid #d4d4d8;
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  color: var(--ink);
  font-size: 15px;
  text-align: center;
  outline: none;
}
select { text-align-last: center; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13, 148, 136, .12); }
input[readonly] { background: #fafafa; color: var(--accent-dark); font-weight: 750; }
#totalInput { font-size: 17px; }
.form-actions, .action-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.form-actions button, .action-strip button { min-height: 40px; border-radius: 8px; padding: 0 14px; font-size: 13px; font-weight: 650; }
button { border-color: #18181b; background: #18181b; color: #fff; }
.form-actions button[type="submit"] { border-color: #16a34a; background: #16a34a; color: #fff; }
button.secondary, .form-actions button.secondary { border-color: #facc15; background: #fef3c7; color: #854d0e; }
button.danger { border-color: #fecaca; background: #fff; color: var(--danger); }
button.icon-button { width: 34px; min-height: 34px; padding: 0; }

.formula-list { display: grid; gap: 10px; }
.formula-list div {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  padding: 12px;
}
.formula-list strong { font-size: 13px; font-weight: 650; }

.summary-table-wrap, .table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.summary-table-wrap table, .table-wrap table { min-width: 100%; border-collapse: collapse; }
.panel + .panel { margin-top: 16px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px; text-align: center; vertical-align: middle; }
th { background: #fafafa; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
td.money, th.money { text-align: center; white-space: nowrap; }
.records-panel .panel-heading { text-align: center; }
.records-panel .panel-heading { align-items: flex-end; flex-wrap: nowrap; text-align: left; }
.records-panel .panel-heading > div:first-child { flex: 1 1 auto; min-width: 240px; }
.records-panel .filters { flex: 0 0 auto; justify-content: flex-end; flex-wrap: nowrap; }
.records-panel th { text-align: center; }
.records-panel td { text-align: left; }
.records-panel td.money { text-align: left; }
.summary-table-wrap tbody td:first-child { text-align: left; }
tr.total-row td { background: #fafafa; color: var(--ink); font-weight: 700; }
tr.withdrawal-row td { background: #fff7ed; color: var(--warn); font-weight: 700; }
.summary-table-wrap th:nth-child(2),
.summary-table-wrap th:nth-child(3),
.summary-table-wrap th:nth-child(4) { color: #71717a; font-weight: 800; }
.summary-table-wrap tbody td:nth-child(2),
.summary-table-wrap tbody td:nth-child(3) { color: #15803d; font-weight: 800; }
.summary-table-wrap tbody td:nth-child(4) { color: #dc2626; font-weight: 800; }

.filters { display: flex; flex-wrap: nowrap; gap: 8px; justify-content: flex-end; }
.filters select { min-width: 190px; min-height: 36px; text-align: left; text-align-last: left; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; white-space: nowrap; }
.row-actions .icon-button {
  display: inline-flex;
  width: 36px;
  height: 36px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.row-actions .icon-button svg { width: 16px; height: 16px; display: block; stroke: currentColor !important; }
.row-actions .edit-action { border-color: #86efac; background: #dcfce7; color: #15803d; }
.row-actions .delete-action { border-color: #fecaca; background: #fef2f2; color: #dc2626; }

#maloteDateInput,
#maloteStoreInput,
#cashWithdrawalDateInput,
#cashWithdrawalReasonInput,
#pixDateInput,
#pixStoreInput,
#pixReasonInput,
#bankDepositDateInput,
#bankDepositValueInput {
  text-align: left;
  text-align-last: left;
}
.status-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
}
.status-pill.ok { background: #ecfdf5; color: var(--accent-dark); }
.status-pill.pending { background: #fff7ed; color: var(--warn); }
.empty-state { padding: 22px; color: var(--muted); text-align: center; }

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 22px;
  color: var(--ink);
  box-shadow: 0 28px 70px rgba(0,0,0,.2);
}
.confirm-dialog::backdrop { background: rgba(24,24,27,.45); backdrop-filter: blur(3px); }
.confirm-dialog-heading { display: flex; align-items: flex-start; gap: 12px; }
.confirm-dialog .dialog-icon {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
}
.confirm-dialog .dialog-icon.danger { background: #fef2f2; color: var(--danger); }
.confirm-dialog .dialog-icon svg { width: 18px; height: 18px; }
.confirm-dialog strong { display: block; font-size: 18px; font-weight: 650; letter-spacing: 0; }
.confirm-dialog p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.dialog-actions button {
  min-width: 132px;
  min-height: 40px;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
}
.dialog-actions .quiet {
  min-width: 104px;
  border-color: #dc2626;
  background: #fef2f2;
  color: #b91c1c;
}
.dialog-actions .quiet:hover { background: #fee2e2; }
.dialog-actions .danger { border-color: #0f766e; background: #0f766e; color: #fff; }
.dialog-actions .danger:hover { border-color: #0d655f; background: #0d655f; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(380px, calc(100vw - 36px));
  border-radius: 8px;
  background: #18181b;
  padding: 12px 14px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 16px 40px rgba(0,0,0,.18);
}

@media (max-width: 1060px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-grid { grid-template-columns: 1fr; }
  .event-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-entry-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .header-container { align-items: flex-start; flex-direction: column; padding: 12px 16px; }
  .header-actions { flex-wrap: wrap; }
  .month-filter-badge { width: 100%; }
  .month-filter-badge select { flex: 1; }
  .header-divider { display: none; }
  main { padding: 18px 16px 34px; }
  .metric-grid, .form-grid, .event-form-grid { grid-template-columns: 1fr; }
  .panel-heading.compact { align-items: flex-start; flex-direction: column; }
  .event-picker { grid-template-columns: 1fr; }
  .filters { width: 100%; justify-content: stretch; flex-wrap: wrap; }
  .filters select { min-width: 0; }
}
