:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f7faf7;
  --ink: #1d2520;
  --muted: #66726a;
  --line: #d9ded7;
  --accent: #247a5a;
  --accent-dark: #15573e;
  --accent-soft: #dceee6;
  --gold: #b98725;
  --red: #b83d3d;
  --shadow: 0 18px 45px rgba(29, 37, 32, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #16251d;
  color: #eef4ee;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #f7f0da;
  color: #16251d;
  font-weight: 800;
  border-radius: 8px;
}

.brand h1,
.topbar h2,
.section-heading h3,
.panel h4,
dialog h3 {
  margin: 0;
  letter-spacing: 0;
}

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

.brand p,
.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
}

.brand p {
  color: #bac8be;
  font-size: 13px;
}

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

.nav-button {
  border: 0;
  background: transparent;
  color: #dbe7de;
  min-height: 44px;
  border-radius: 8px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-button span {
  width: 20px;
  text-align: center;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.period-panel {
  margin-top: auto;
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 14px;
  border-radius: 8px;
}

.sidebar .account-menu {
  width: 100%;
}

.sidebar .account-menu summary {
  width: 100%;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #eef4ee;
}

.sidebar .account-menu-panel {
  top: auto;
  right: auto;
  bottom: calc(100% + 8px);
  left: 0;
  width: 100%;
  min-width: 0;
}

.sidebar .account-menu-panel .ghost-button {
  width: 100%;
}

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

.period-panel label {
  color: #c8d6cc;
}

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

.period-panel select {
  background: #20332a;
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.16);
  min-width: 0;
  text-overflow: ellipsis;
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: flex-start;
  gap: 14px 24px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 30px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: min(100%, 520px);
}

.hidden {
  display: none !important;
}

.toolbar-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 760px;
}

.account-menu,
.admin-tools {
  position: relative;
}

.account-menu summary,
.admin-tools summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.admin-tools summary {
  border-radius: 6px;
}

.account-menu summary::-webkit-details-marker,
.admin-tools summary::-webkit-details-marker {
  display: none;
}

.account-menu-panel,
.admin-tools-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.admin-tools-panel {
  min-width: 190px;
}

.admin-tools-panel .file-action,
.admin-tools-panel .danger-button {
  width: 100%;
}

.topbar .ghost-button,
.topbar .danger-button,
.topbar .file-action,
.topbar .admin-tools summary {
  min-height: 38px;
  padding: 8px 12px;
  font-size: 14px;
}

#accountDetails {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.auth-gate {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 0.6fr);
  gap: 22px;
  align-items: start;
  padding: 22px;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-gate h3 {
  margin: 0;
  font-size: 24px;
}

.auth-gate p {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.view {
  display: none;
}

.active-view {
  display: grid;
  gap: 20px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.section-heading h3 {
  font-size: 24px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 14px;
}

.metric-card,
.panel,
.form-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 112px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  gap: 16px;
}

.metric-card span,
.panel-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 24px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.8fr);
  gap: 20px;
}

.panel {
  overflow: hidden;
}

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

.panel h4 {
  font-size: 16px;
}

.chart {
  height: 280px;
  display: flex;
  align-items: end;
  gap: 6px;
  padding: 18px;
  border-bottom: 1px solid transparent;
}

.bar {
  flex: 1;
  min-width: 8px;
  max-width: 34px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  position: relative;
}

.bar:hover::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: #16251d;
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 2;
}

.period-chart {
  width: 100%;
  height: 100%;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(120px, 1fr);
  align-items: end;
  gap: 18px;
  padding: 4px 0;
  overflow-x: auto;
}

.period-bar-group {
  min-width: 120px;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(130px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  text-align: center;
}

.period-value {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.period-bar-wrap {
  height: 100%;
  min-height: 130px;
  display: flex;
  align-items: end;
  justify-content: center;
  border-bottom: 1px solid var(--line);
}

.period-bar {
  width: 44px;
  min-height: 4px;
  background: var(--accent);
  border-radius: 6px 6px 0 0;
}

.period-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.period-sub {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.split-list {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.split-row {
  display: grid;
  gap: 7px;
}

.split-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.split-track {
  height: 10px;
  background: #e9ede8;
  border-radius: 999px;
  overflow: hidden;
}

.split-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 999px;
}

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

.full-width {
  grid-column: 1 / -1;
}

.primary-action,
.secondary-action,
.ghost-button,
.danger-button,
.icon-button,
.file-action {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 9px 13px;
  font-weight: 800;
}

.primary-action {
  background: var(--accent);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.secondary-action,
.ghost-button,
.file-action {
  background: #ffffff;
  color: var(--accent-dark);
  border-color: var(--line);
}

.file-action {
  display: inline-grid;
  place-items: center;
  gap: 0;
  font-size: 16px;
}

.file-action input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.danger-file-action {
  color: var(--red);
  border-color: #efc8c8;
}

.period-panel .secondary-action {
  background: #f7f0da;
  border: 0;
}

.danger-button {
  background: #fff;
  color: var(--red);
  border-color: #efc8c8;
}

.icon-button {
  width: 36px;
  min-height: 34px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  color: var(--red);
}

.compact-button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

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

.form-message {
  margin: -10px 0 0;
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.form-message[data-tone="success"] {
  color: var(--accent-dark);
}

.form-message[data-tone="error"] {
  color: var(--red);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(22, 37, 29, 0.4);
}

#periodForm {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  display: grid;
  gap: 16px;
}

@media (max-width: 1100px) {
  .metrics-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

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

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-height: auto;
  }

  main {
    padding: 20px;
  }

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

  .topbar-actions,
  .toolbar-group {
    width: 100%;
    justify-content: flex-start;
  }

  .topbar-actions {
    align-items: flex-start;
  }

  .account-menu-panel,
  .admin-tools-panel {
    left: 0;
    right: auto;
  }

  .metrics-grid,
  .form-grid,
  .auth-gate {
    grid-template-columns: 1fr;
  }
}
