:root {
  --bg: #f1ede3;
  --bg-deep: #1f2a2a;
  --panel: #fffaf0;
  --panel-strong: #ffffff;
  --line: #d7cfbf;
  --text: #182020;
  --muted: #66716d;
  --accent: #ba4a2f;
  --accent-soft: #ecdfd1;
  --success: #356859;
  --error: #982b1c;
  --shadow: 0 22px 60px rgba(33, 40, 37, 0.12);
  --table-font-size: 0.9rem;
  --table-cell-padding-y: 10px;
  --table-cell-padding-x: 10px;
  --table-value-width: 92px;
  --table-code-width: 72px;
  --table-label-width: 320px;
  --table-account-width: 128px;
  --table-max-height: min(72vh, 980px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(186, 74, 47, 0.14), transparent 30%),
    linear-gradient(160deg, #f5efe3 0%, #efe7d8 50%, #e8dfd2 100%);
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
}

.sidebar {
  background: var(--bg-deep);
  color: #edf1eb;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar h1,
.login-card h1,
.hero h2 {
  font-family: "Fraunces", Georgia, serif;
  margin: 0;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: var(--accent);
  margin: 0 0 10px;
}

.sidebar .eyebrow {
  color: #ffb69a;
}

.muted {
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 10px;
}

.nav-link {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.nav-link.active,
.nav-link:hover {
  background: rgba(255, 255, 255, 0.11);
}

.content {
  min-width: 0;
  padding: clamp(16px, 2vw, 24px);
}

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

.topbar form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel {
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

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

.hero-stats {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.stat-card {
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.25rem;
}

.grid {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.two-col {
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  margin: 18px 0;
}

.list {
  display: grid;
  gap: 12px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.link-row:hover {
  transform: translateY(-1px);
}

.compact .list-row {
  padding: 10px 12px;
}

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

.inline-upload {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-upload input[type="file"] {
  max-width: 260px;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
}

textarea.code-area {
  min-height: 500px;
  font-family: "IBM Plex Mono", monospace;
}

button,
.ghost-button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 11px 18px;
  background: var(--accent);
  color: white;
}

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

.ghost-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
}

.pill.active {
  background: rgba(53, 104, 89, 0.15);
  color: var(--success);
}

.pill.neutral {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  border: 1px solid var(--line);
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.flash {
  padding: 12px 14px;
  border-radius: 14px;
}

.flash.success {
  background: rgba(53, 104, 89, 0.12);
  color: var(--success);
}

.flash.error {
  background: rgba(152, 43, 28, 0.1);
  color: var(--error);
}

.process-status-card {
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.6);
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.process-status-header,
.process-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(133, 110, 84, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(167, 87, 46, 0.92), rgba(53, 104, 89, 0.9));
  transition: width 0.25s ease;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  border-radius: 18px;
  position: relative;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: var(--table-cell-padding-y) var(--table-cell-padding-x);
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-size: var(--table-font-size);
}

th:first-child,
td:first-child {
  text-align: left;
}

.label-cell.level-1 {
  padding-left: 24px;
}

.label-cell.level-2 {
  padding-left: 40px;
}

.label-cell.level-3 {
  padding-left: 56px;
}

.chart {
  min-height: clamp(280px, 34vh, 460px);
  width: 100%;
}

.chart.tall {
  min-height: 420px;
}

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

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.filter-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.report-hero {
  margin-bottom: 18px;
}

.logic-panel {
  margin-bottom: 18px;
}

.logic-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.logic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.logic-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  padding: 14px 16px;
}

.logic-card strong {
  display: block;
  margin-bottom: 8px;
}

.logic-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.report-top-grid {
  margin-top: 0;
}

.report-panel {
  padding: 18px;
}

.report-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.filter-groups {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.period-actions {
  justify-content: flex-end;
}

.period-chip.ghost {
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border: 1px solid var(--line);
}

.period-chip.ghost:hover {
  background: rgba(255, 255, 255, 1);
}

.filter-choice-group.hidden-filter-group {
  display: none;
}

.report-surface {
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(255, 248, 238, 0.95));
  min-width: 0;
}

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

.chart-panel-inner {
  padding: 16px;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.62);
}

.chart-panel-wide,
.report-subpanel {
  margin: 0 14px 14px;
}

.chart-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.table-toolbar {
  display: grid;
  gap: 16px;
  padding: 14px 14px 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(249, 243, 234, 0.92));
  border-bottom: 1px solid var(--line);
}

.table-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  align-items: end;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group-inline {
  align-content: end;
}

.control-label,
.slider-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.density-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.density-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
}

.density-chip.active {
  background: var(--bg-deep);
  color: #fff;
  border-color: var(--bg-deep);
}

.table-meta {
  padding: 0 18px 14px;
  background: rgba(255, 255, 255, 0.72);
}

.plan-editor-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
}

.plan-editor-table {
  width: max-content;
  min-width: 100%;
}

.plan-editor-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7efe3;
}

.plan-editor-table th,
.plan-editor-table td {
  min-width: 140px;
  text-align: left;
}

.plan-editor-table th:nth-child(1),
.plan-editor-table td:nth-child(1) {
  min-width: 80px;
}

.plan-editor-table th:nth-child(2),
.plan-editor-table td:nth-child(2) {
  min-width: 320px;
}

.plan-input {
  min-width: 120px;
  padding: 10px 12px;
  text-align: right;
}

.plan-editor-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.tabulator-shell {
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  min-width: 0;
  max-width: 100%;
}

.tabulator {
  border: none;
  background: transparent;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 0.82rem;
  width: 100%;
}

.tabulator .tabulator-header {
  border-bottom: 1px solid var(--line);
  background: #f7efe3;
}

.tabulator .tabulator-header .tabulator-col,
.tabulator .tabulator-header .tabulator-col.tabulator-frozen {
  background: #f7efe3;
  border-right: 1px solid rgba(215, 207, 191, 0.72);
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
  padding: 7px 6px;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  white-space: normal;
  line-height: 1.15;
}

.tabulator .tabulator-row {
  background: rgba(255, 255, 255, 0.92);
}

.tabulator .tabulator-row:nth-child(even) {
  background: rgba(252, 248, 241, 0.92);
}

.tabulator .tabulator-row:hover {
  background: rgba(255, 239, 230, 0.78);
}

.tabulator .tabulator-row .tabulator-cell,
.tabulator .tabulator-row .tabulator-cell.tabulator-frozen {
  border-right: 1px solid rgba(215, 207, 191, 0.42);
  border-bottom: 1px solid rgba(215, 207, 191, 0.56);
  padding: 7px 6px;
  background: transparent;
}

.tabulator .tabulator-row .tabulator-cell.wrap-cell {
  white-space: normal;
  line-height: 1.2;
}

.tabulator .tabulator-row.is-active-row,
.tabulator .tabulator-row.is-active-row .tabulator-cell,
.tabulator .tabulator-row.is-active-row .tabulator-cell.tabulator-frozen {
  background: rgba(186, 74, 47, 0.10);
}

.tabulator .tabulator-row.is-total-row,
.tabulator .tabulator-row.is-total-row .tabulator-cell,
.tabulator .tabulator-row.is-total-row .tabulator-cell.tabulator-frozen {
  background: rgba(186, 74, 47, 0.08);
  font-weight: 700;
}

.tabulator .tabulator-row .tabulator-cell:first-child {
  font-weight: 600;
}

.tabulator .tabulator-data-tree-control {
  border: 1px solid var(--line);
  border-radius: 999px;
  width: 22px;
  height: 22px;
  line-height: 20px;
  text-align: center;
  background: #fff;
  color: var(--accent);
}

.tabulator .tabulator-footer {
  background: #f7efe3;
  border-top: 1px solid var(--line);
}

.period-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.period-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
}

.period-chip.active {
  background: var(--accent);
  color: #fff;
}

.month-detail {
  margin-top: 16px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.month-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.month-pill {
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}

.month-pill span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.tree-toggle {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  padding: 0;
  margin-right: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.tree-spacer {
  display: inline-block;
  width: 24px;
  margin-right: 8px;
}

.hidden-row {
  display: none;
}

.filtered-out {
  display: none;
}

.quarter-value-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 6px 10px;
  width: 100%;
}

.quarter-value-button:hover {
  background: var(--accent-soft);
}

.tree-table th,
.tree-table td {
  min-width: var(--table-value-width);
}

.tree-table th:nth-child(2),
.tree-table td:nth-child(2) {
  min-width: var(--table-label-width);
}

.sticky-col {
  position: sticky;
  background: rgba(255, 251, 244, 0.98);
  z-index: 2;
  box-shadow: 1px 0 0 rgba(215, 207, 191, 0.72);
}

.tree-table th.sticky-col {
  z-index: 4;
}

.sticky-col-1 {
  left: 0;
  min-width: var(--table-code-width);
}

.sticky-col-2 {
  left: var(--table-code-width);
  min-width: var(--table-label-width);
  max-width: min(540px, var(--table-label-width));
}

.sticky-col-3 {
  left: calc(var(--table-code-width) + var(--table-label-width));
  min-width: var(--table-account-width);
}

.label-cell {
  white-space: normal;
}

.tree-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f7efe3;
  box-shadow: inset 0 -1px 0 var(--line);
}

.tree-table thead tr:first-child th {
  top: 0;
}

.tree-table thead tr:nth-child(2) th {
  top: calc(var(--table-cell-padding-y) * 2 + 18px);
}

.tree-table tbody tr:nth-child(odd) td {
  background: rgba(255, 255, 255, 0.52);
}

.tree-table tbody tr:hover td {
  background: rgba(255, 239, 230, 0.78);
}

.tree-table .quarter-value-button {
  min-width: calc(var(--table-value-width) - 10px);
}

.table-viewport {
  max-height: var(--table-max-height);
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(241, 237, 227, 0.94) 0, rgba(241, 237, 227, 0) 16px) left center / 16px 100% no-repeat,
    linear-gradient(180deg, rgba(247, 239, 227, 0.98) 0, rgba(247, 239, 227, 0) 18px) top center / 100% 18px no-repeat,
    #fffdf8;
}

.table-viewport::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.table-viewport::-webkit-scrollbar-thumb {
  background: rgba(102, 113, 109, 0.35);
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.7);
}

.table-viewport::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.65);
}

.command-block {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  overflow: auto;
}

.command-block code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.92rem;
}

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

.login-card {
  width: min(460px, 100%);
  background: rgba(255, 250, 240, 0.92);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-form {
  display: grid;
  gap: 10px;
}

@media (max-width: 980px) {
  .chart-block-grid {
    grid-template-columns: 1fr;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding-bottom: 16px;
  }

  .two-col,
  .hero {
    grid-template-columns: 1fr;
    display: grid;
  }

  .report-panel-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  .filter-groups {
    justify-items: start;
  }

  .report-panel-head,
  .table-controls {
    grid-template-columns: 1fr;
    display: grid;
  }

  .sticky-col {
    position: static;
    box-shadow: none;
  }

  .tree-table th:nth-child(2),
  .tree-table td:nth-child(2) {
    min-width: 240px;
  }

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

  .table-viewport {
    max-height: none;
  }

  .tree-table thead th,
  .tree-table thead tr:nth-child(2) th {
    position: static;
  }

  .plan-editor-actions {
    justify-content: stretch;
  }
}

@media (max-width: 1280px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .hero {
    align-items: flex-start;
  }
}
