:root {
  --bg: #f5f6f4;
  --surface: #fff;
  --ink: #1f2722;
  --muted: #657169;
  --line: #dce3de;
  --primary: #0f766e;
  --primary-dark: #0b5954;
  --accent: #b45309;
  --danger: #b42318;
  --success: #15803d;
  --warning: #a16207;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Tahoma, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-stack {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
}
.login-card {
  width: 100%;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 18px 45px rgba(30, 36, 32, .08);
  display: grid;
  gap: 14px;
}
.brand {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-card h2 { margin: 0; font-size: 20px; }
.login-card p, .login-card small { color: var(--muted); line-height: 1.7; }
.login-links, .recovery-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.login-links button, .recovery-tabs button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 800;
  padding: 4px 0;
}
.recovery-tabs button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #f8faf8;
  color: var(--ink);
}
.recovery-tabs button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.recovery-form {
  display: grid;
  gap: 12px;
}
.recovery-result {
  min-height: 24px;
  color: var(--primary-dark);
  font-weight: 800;
}

label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; color: #344039; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}
input.readonly-calc {
  background: #f8faf8;
  color: var(--primary-dark);
  font-weight: 800;
  direction: ltr;
  text-align: right;
}
textarea { min-height: 82px; resize: vertical; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}
.sidebar {
  background: #1f2a24;
  color: white;
  min-height: 100vh;
  padding: 20px 16px;
  display: grid;
  align-content: start;
  gap: 18px;
  position: sticky;
  top: 0;
}
.brand-row { display: flex; align-items: center; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-row span { display: block; color: rgba(255,255,255,.64); font-size: 12px; margin-top: 3px; }
nav { display: grid; gap: 7px; }
nav button, .ghost {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  color: rgba(255,255,255,.82);
  background: transparent;
  text-align: left;
}
nav button.active, nav button:hover, .ghost:hover { background: rgba(255,255,255,.12); color: white; }
main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar h2 { margin: 0 0 4px; font-size: 22px; }
.topbar p { margin: 0; color: var(--muted); font-size: 13px; }
.view { display: none; padding: 24px; gap: 18px; }
.view.active { display: grid; }
.dashboard-toolbar {
  display: flex;
  justify-content: flex-end;
}
.dashboard-toolbar label {
  width: min(220px, 100%);
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel header {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.panel h3 { margin: 0; font-size: 17px; }
.panel p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 16px 18px; }
.budget-project-picker {
  display: grid;
  grid-template-columns: minmax(280px, 560px) minmax(180px, 1fr);
  gap: 12px;
  align-items: end;
}
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(280px, 1fr)); }
.grid.side { grid-template-columns: 330px minmax(0, 1fr); align-items: start; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
}
.stats.compact { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
.stat {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 104px;
  display: grid;
  gap: 10px;
}
.stat small { color: var(--muted); font-weight: 700; }
.stat strong { font-size: 22px; direction: ltr; text-align: left; }
.stat span { color: var(--muted); font-size: 12px; }
.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 700;
}
.btn.primary { border-color: var(--primary); background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff1f0; color: var(--danger); border-color: #ffd0cc; }
.form {
  display: grid;
  gap: 12px;
}
.form.wide {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}
.form .full { grid-column: 1 / -1; }
.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 10px;
  margin-bottom: 12px;
}
.list { display: grid; gap: 10px; }
.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.list-item.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.manager-card {
  gap: 12px;
}
.manager-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.permission-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.permission-toggle {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  align-items: start;
  font-weight: 700;
}
.permission-toggle small {
  grid-column: 2;
  color: var(--muted);
  font-weight: 500;
}
.permission-toggle.changed span::after {
  content: " changed";
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
}
.selected-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 12px;
  display: grid;
  gap: 6px;
}
.project-card {
  width: 100%;
  color: inherit;
  text-align: left;
}
.project-card:hover {
  border-color: var(--primary);
  background: #f4fbf8;
}
.dashboard-project-list {
  padding: 0;
}
.dashboard-project-table th,
.dashboard-project-table td {
  padding: 9px 10px;
}
.dashboard-project-table td:first-child {
  min-width: 210px;
}
.clickable-row {
  cursor: pointer;
}
.clickable-row:hover {
  background: #f4fbf8;
}
.mini { color: var(--muted); font-size: 12px; }
.warning-text { color: var(--warning); font-weight: 700; }
.inline-link { color: var(--primary); font-weight: 700; text-decoration: none; }
.inline-link:hover { text-decoration: underline; }
.amount { direction: ltr; text-align: right; white-space: nowrap; font-weight: 700; }
.amount.over { color: var(--danger); }
.amount.under { color: var(--success); }
.badge {
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}
.badge.success { color: var(--success); background: #ecfdf3; }
.badge.warning { color: var(--warning); background: #fffbeb; }
.badge.danger { color: var(--danger); background: #fff1f0; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 11px 10px; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #f9faf9; font-size: 12px; white-space: nowrap; }
.budget-body { display: grid; gap: 12px; }
.budget-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}
.budget-section summary {
  cursor: pointer;
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: #f8faf8;
}
.budget-section summary::-webkit-details-marker { display: none; }
.section-name-edit {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.section-name-edit input {
  min-height: 34px;
  font-weight: 700;
}
.budget-items {
  min-width: 1320px;
  table-layout: fixed;
}
.budget-items th:nth-child(1), .budget-items td:nth-child(1) { width: 78px; }
.budget-items th:nth-child(2), .budget-items td:nth-child(2) { width: 520px; }
.budget-items th:nth-child(3), .budget-items td:nth-child(3),
.budget-items th:nth-child(4), .budget-items td:nth-child(4) { width: 90px; }
.budget-items th:nth-child(5), .budget-items td:nth-child(5) { width: 150px; }
.budget-items th:nth-child(6), .budget-items td:nth-child(6) { width: 120px; }
.budget-items th:nth-child(7), .budget-items td:nth-child(7),
.budget-items th:nth-child(8), .budget-items td:nth-child(8),
.budget-items th:nth-child(9), .budget-items td:nth-child(9) { width: 120px; }
.budget-items th:nth-child(10), .budget-items td:nth-child(10) { width: 80px; }
.budget-items input, .budget-items select, .budget-items textarea { min-height: 34px; padding: 6px 8px; }
.budget-item-name textarea {
  min-height: 64px;
  line-height: 1.45;
  resize: vertical;
  white-space: normal;
  overflow-wrap: anywhere;
}
.chart {
  height: 280px;
  display: flex;
  align-items: end;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 16px 4px 0;
}
.month {
  flex: 1;
  min-width: 28px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  text-align: center;
}
.bars { display: flex; align-items: end; justify-content: center; gap: 4px; height: 220px; }
.bar {
  width: 12px;
  min-height: 3px;
  border: 0;
  padding: 0;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
}
span.bar { cursor: default; }
.bar:hover { filter: brightness(.9); }
.bar:focus-visible { outline: 2px solid var(--primary-dark); outline-offset: 2px; }
.expense { background: var(--accent); }
.income { background: var(--primary); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 12px; }
.report-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}
.group-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.admin-list-table {
  margin-top: 8px;
  min-width: 420px;
}
.admin-list-table .serial {
  width: 48px;
  color: var(--primary-dark);
  font-weight: 800;
}
.toast {
  position: fixed;
  left: 22px;
  bottom: 22px;
  background: #1f2722;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: 160ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1120px) {
  .app, .grid.side, .grid.two { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; position: static; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats, .stats.compact, .form.wide, .inline-form, .manager-grid, .budget-project-picker, .permission-grid { grid-template-columns: 1fr; }
}
