:root {
  --bg: #fffaf4;
  --panel: #ffffff;
  --ink: #2a211b;
  --muted: #776b62;
  --line: #f0e3d6;
  --brand: #f47b20;
  --brand-2: #fff0df;
  --danger: #b33a3a;
  --ok: #18855b;
  --soft: #fff5ea;
  --shadow: 0 12px 30px rgba(142, 91, 45, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(244, 123, 32, 0.09), transparent 32%),
    var(--bg);
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 14px;
  background: #ffffff;
  color: var(--ink);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 0 10px 20px;
  border-bottom: 1px solid var(--line);
}

.brand strong {
  font-size: 20px;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  color: #9b4306;
  background: var(--soft);
}

.nav .ico {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  color: #b8520d;
  background: var(--brand-2);
  font-weight: 800;
  font-size: 12px;
}

.main {
  min-width: 0;
  padding: 24px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  min-height: 38px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(244, 123, 32, 0.18);
}

.btn.secondary {
  background: #fff0df;
  color: var(--ink);
}

.btn.ghost {
  min-height: 34px;
  padding: 7px 10px;
  color: #9b4306;
  background: #fff3e6;
  box-shadow: none;
}

.btn.danger {
  background: #f8e7e7;
  color: var(--danger);
}

.select, .input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

.select:focus, .input:focus {
  outline: 2px solid rgba(244, 123, 32, 0.18);
  border-color: var(--brand);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  background: linear-gradient(180deg, #fff 0%, #fffdf9 100%);
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.grid {
  display: grid;
  gap: 14px;
}

.subnav {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.subnav button {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.subnav button:hover,
.subnav button.active {
  color: #9b4306;
  background: var(--brand-2);
}

.cols-2 {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.daily-grid {
  grid-template-columns: minmax(0, 1.75fr) minmax(260px, 0.65fr);
}

.month-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.wide-panel {
  grid-column: 1 / -1;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  table-layout: fixed;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  color: var(--muted);
  background: #fff8f0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td.num, th.num {
  text-align: right;
}

td input, td select {
  width: 100%;
  min-width: 112px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 8px;
  background: transparent;
  color: var(--ink);
}

.money-input {
  width: min(180px, 100%);
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--ink);
  background: #fff;
  text-align: right;
  font-weight: 800;
}

.money-input:focus {
  outline: 2px solid rgba(244, 123, 32, 0.18);
  border-color: var(--brand);
}

td input:focus, td select:focus {
  outline: 2px solid rgba(244, 123, 32, 0.22);
  border-color: var(--brand);
  background: #fff;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.clip, .cell-main {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-main {
  font-weight: 700;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #fffaf4;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.danger-icon {
  color: var(--danger);
  background: #f8e7e7;
}

.expenses-table {
  min-width: 980px;
}

.expenses-table .col-account { width: 22%; }
.expenses-table .col-sub { width: 18%; }
.expenses-table .col-cat { width: 14%; }
.expenses-table .col-money { width: 10%; }
.expenses-table .col-date { width: 11%; }
.expenses-table .col-status { width: 8%; }
.expenses-table .col-actions { width: 14%; }

.payables-table {
  min-width: 1160px;
}

.payables-table .col-account { width: 15%; }
.payables-table .col-supplier { width: 13%; }
.payables-table .col-sub { width: 12%; }
.payables-table .col-cat { width: 11%; }
.payables-table .col-money { width: 9%; }
.payables-table .col-date { width: 11%; }
.payables-table .col-status { width: 10%; }
.payables-table .col-actions { width: 16%; }

.payable-row:hover {
  background: #fffaf4;
}

.receivables-wrap {
  overflow-x: auto;
}

.receivables-table {
  min-width: 1180px;
  font-size: 13px;
}

.receivables-table th,
.receivables-table td {
  padding: 9px 7px;
}

.receivables-table th {
  font-size: 11px;
}

.receivables-table .col-platform { width: 7%; }
.receivables-table .col-period { width: 7%; }
.receivables-table .col-small { width: 6.5%; }
.receivables-table .col-money { width: 8%; }
.receivables-table .col-date { width: 9%; }
.receivables-table .col-status { width: 8%; }
.receivables-table .col-comp { width: 5.5%; }
.receivables-table .col-actions { width: 8%; }

.compact-cell {
  min-width: 0;
  height: 32px;
  padding: 5px 6px;
  font-size: 13px;
}

.num-cell {
  text-align: right;
}

.mini-btn {
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 6px 9px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.receivables-table .icon-btn {
  width: 32px;
  height: 32px;
}

.receivables-table .row-actions {
  gap: 6px;
}

.compact-date {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--ink);
  background: #fff;
}

.compact-date:focus {
  outline: 2px solid rgba(244, 123, 32, 0.18);
  border-color: var(--brand);
}

.pill.ok { color: var(--ok); background: #e3f4ec; }
.pill.warn { color: #9b4306; background: #fff0df; }
.pill.bad { color: var(--danger); background: #f8e7e7; }
.pill.neutral { color: #66584f; background: #f7efe6; }

.mini-chart {
  display: grid;
  gap: 9px;
  padding: 16px;
}

.bar-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 128px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-row > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #fff0df;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.bar-row strong {
  display: grid;
  gap: 2px;
  justify-items: end;
  font-size: 13px;
}

.bar-row strong b {
  font: inherit;
}

.bar-row strong small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #fffaf4 0%, #fff1df 100%);
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 22px 60px rgba(142, 91, 45, 0.14);
}

.login-brand {
  padding: 22px;
  color: var(--ink);
  background: #fff7ed;
  border-bottom: 1px solid var(--line);
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.login-form h1 {
  margin: 0;
  font-size: 26px;
}

.login-form p {
  margin: -4px 0 4px;
  color: var(--muted);
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--danger);
  background: #f8e7e7;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(78, 52, 31, 0.34);
}

.modal {
  width: min(680px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(78, 52, 31, 0.22);
  overflow: hidden;
}

.expense-modal {
  width: min(760px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--ink);
  background: #fff0df;
  font-weight: 800;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 20px;
}

.modal-body {
  padding: 16px 20px 20px;
  max-height: 70vh;
  overflow: auto;
}

.expense-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.expense-form label:nth-child(1),
.expense-form label:nth-child(2),
.expense-form .full {
  grid-column: span 2;
}

.modal-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.modal-form .full {
  grid-column: 1 / -1;
}

.recurrence-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid #ffd9b1;
  border-radius: 8px;
  background: #fff7ed;
}

.recurrence-box div {
  display: grid;
  gap: 4px;
}

.recurrence-box strong {
  color: var(--ink);
}

.recurrence-box span {
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main { padding: 18px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .toolbar { justify-content: flex-start; }
  .kpis, .cols-2, .daily-grid, .month-grid { grid-template-columns: 1fr; }
  .wide-panel { grid-column: auto; }
  .expense-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .nav { grid-template-columns: 1fr; }
  .title h1 { font-size: 23px; }
  .kpi strong { font-size: 20px; }
  .main { padding: 14px; }
  .modal-form { grid-template-columns: 1fr; }
  .expense-form { grid-template-columns: 1fr; }
  .expense-form label:nth-child(1),
  .expense-form label:nth-child(2),
  .expense-form .full { grid-column: 1; }
  .recurrence-box { align-items: stretch; flex-direction: column; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}
