:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #687385;
  --line: #d8e0ea;
  --line-strong: #aeb8c5;
  --accent: #0f766e;
  --accent-weak: #e5f4f2;
  --danger: #b42318;
  --warn: #9a6700;
  --shadow: 0 10px 28px rgba(23, 33, 43, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

button.secondary,
button.table-button {
  background: #fff;
  color: var(--accent);
}

button.danger,
.table-button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

button.small {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

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

.login-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.login-switch button {
  min-height: 36px;
  border-color: var(--line);
  background: #f8fafb;
  color: var(--muted);
}

.login-switch button.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

.stack-form {
  display: grid;
  gap: 12px;
}

.message {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.message.ok {
  color: var(--accent);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(210px, auto) 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.tabs,
.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tab,
.subtab {
  min-height: 32px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.tab.active,
.subtab.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

.form-kind-tabs,
.type-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.form-kind-button,
.type-toggle-button {
  min-height: 32px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.form-kind-button.active,
.type-toggle-button.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

main {
  padding: 18px;
}

.view,
.subview {
  display: none;
  gap: 14px;
}

.view.active,
.subview.active {
  display: grid;
}

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

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

.panel-head h2,
.empty-panel h2 {
  margin: 0;
  font-size: 16px;
}

.empty-panel {
  min-height: 180px;
  align-content: center;
  justify-items: center;
  padding: 28px;
  color: var(--muted);
}

.empty-panel p {
  margin: 5px 0 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  padding: 12px;
}

.compact-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.form-grid label,
.stack-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.form-grid .wide {
  grid-column: span 2;
}

.check-label {
  display: flex !important;
  align-items: center;
  gap: 8px !important;
}

.check-label input {
  width: auto;
  min-height: auto;
}

.combo-field {
  position: relative;
  display: block;
}

.combo-list {
  position: absolute;
  z-index: 70;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 230px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 28px rgba(23, 33, 43, 0.16);
}

.combo-option {
  width: 100%;
  min-height: 32px;
  justify-content: flex-start;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  padding: 7px 10px;
  text-align: left;
  font-size: 12px;
}

.combo-option:hover,
.combo-option:focus,
.combo-option.active {
  background: var(--accent-weak);
  color: var(--accent);
}

.combo-empty {
  padding: 12px 10px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-actions input {
  width: min(260px, 42vw);
}

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

.table-status,
.summary-strip {
  min-height: 38px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
}

table[data-table-id="budgetTable"] {
  min-width: 1900px;
}

table[data-table-id="dashboardMonthlyUsageTable"] {
  min-width: var(--dashboard-table-width, 1500px);
}

table[data-table-id="expenseTable"] {
  min-width: 2200px;
}

.template-title {
  padding: 14px 12px 8px;
  font-size: 16px;
  font-weight: 900;
}

.template-sections {
  display: grid;
  gap: 0;
}

.template-section {
  border-top: 1px solid var(--line);
}

.template-section h3 {
  margin: 0;
  padding: 11px 12px 0;
  color: #445164;
  font-size: 13px;
  font-weight: 900;
}

.type-toggle {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.line-items {
  border-top: 1px solid var(--line);
  background: #fff;
}

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

.line-items-head h3 {
  margin: 0;
  font-size: 15px;
}

.line-item-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.line-item-actions strong {
  color: var(--muted);
  font-size: 12px;
}

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

.line-item-table {
  min-width: 920px;
}

.line-item-table input {
  min-width: 120px;
}

.line-item-table th:first-child,
.line-item-table td:first-child {
  width: 64px;
}

.line-item-table th:last-child,
.line-item-table td:last-child {
  width: 78px;
}

.line-items-total {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fbfcfd;
}

.line-items-total strong {
  color: var(--ink);
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

th,
td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  padding: 22px 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #445164;
  font-size: 12px;
  font-weight: 900;
}

td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.wrap {
  min-width: 240px;
  white-space: normal;
}

.filter-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filter-button {
  min-height: 22px;
  width: 24px;
  padding: 0;
  border-color: var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
}

.filter-button.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

.sort-mark {
  color: var(--accent);
  font-weight: 900;
}

.filter-menu {
  position: fixed;
  z-index: 100;
  width: 260px;
  max-height: 380px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 32px rgba(23, 33, 43, 0.18);
}

.filter-menu-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 900;
}

.filter-menu-actions {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.filter-menu-actions button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.filter-search,
.range-filter {
  display: grid;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.range-filter label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-options {
  overflow: auto;
  padding: 6px 8px 10px;
}

.filter-options label {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 12px;
}

.filter-options input {
  width: auto;
  min-height: auto;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.status-badge {
  display: inline-flex;
  min-width: 44px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.status-badge.ended {
  border-color: #d1d8e0;
  background: #eef1f4;
  color: #667386;
}

.project-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.project-card {
  min-height: 82px;
  display: grid;
  gap: 5px;
  justify-items: start;
  align-content: start;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.project-card:hover,
.project-card.active {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.project-card.ended {
  border-color: #d3d9e0;
  background: #f1f3f5;
  color: #667386;
}

.project-card.ended:hover,
.project-card.ended.active {
  border-color: #96a0ad;
  background: #e9edf1;
}

.project-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.project-card strong {
  white-space: normal;
}

#budgetCards.project-card-grid {
  grid-template-columns: 1fr;
}

.budget-card-section {
  display: grid;
  gap: 8px;
}

.budget-card-section h3 {
  margin: 0;
  color: #445164;
  font-size: 13px;
  font-weight: 900;
}

.budget-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 10px;
}

.budget-card {
  min-height: 154px;
}

.budget-card-metrics {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 4px;
}

.budget-card-metrics div {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.budget-card.active .budget-card-metrics div,
.budget-card:hover .budget-card-metrics div {
  border-color: rgba(15, 118, 110, 0.22);
}

.budget-card.ended.active .budget-card-metrics div,
.budget-card.ended:hover .budget-card-metrics div {
  border-color: #c2cad4;
}

.budget-card-metrics .usage-rate {
  grid-column: 1 / -1;
}

.budget-card-metrics strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.budget-card-bar {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf3;
}

.budget-card-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.project-card.ended .budget-card-bar span {
  background: #8995a3;
}

.bulk-edit-input,
.bulk-edit-select,
.table-input,
.table-select {
  min-width: 120px;
  min-height: 30px;
  padding: 4px 6px;
  font-size: 12px;
}

.table-input {
  min-width: 150px;
}

td.wrap .bulk-edit-input {
  min-width: 220px;
}

.table-actions button.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: var(--accent);
}

.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.edit-dialog {
  width: min(920px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.edit-dialog::backdrop {
  background: rgba(23, 33, 43, 0.34);
}

.edit-form {
  background: #fff;
}

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

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

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 110;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 900;
}

.toast.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  padding: 12px;
}

.info-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.info-grid strong {
  display: block;
  margin-top: 6px;
}

.admin-dashboard {
  align-items: start;
}

.backup-status-card,
.admin-status-grid,
.admin-metric-grid {
  padding: 12px;
}

.backup-status-card {
  display: flex;
  gap: 12px;
  align-items: center;
}

.backup-status-card div:last-child {
  display: grid;
  gap: 4px;
}

.backup-status-card span,
.admin-info-card span,
.admin-metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.backup-state {
  min-width: 76px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 900;
}

.backup-state.ok {
  background: var(--accent-weak);
  color: var(--accent);
}

.backup-state.warn {
  background: #fff7e6;
  color: var(--warn);
}

.admin-status-grid,
.admin-metric-grid {
  display: grid;
  gap: 10px;
}

.admin-status-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.admin-metric-grid {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
}

.admin-info-card,
.admin-metric-card {
  min-width: 0;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.admin-info-card strong,
.admin-metric-card strong {
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .compact-form,
  .info-grid,
  .admin-status-grid,
  .admin-metric-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .table-actions {
    flex-wrap: wrap;
  }

  .line-items-head {
    align-items: stretch;
    flex-direction: column;
  }

  .line-item-actions {
    justify-content: space-between;
  }
}
