:root {
  color-scheme: light;
  --primary: #01509a;
  --primary-dark: #00509a;
  --ink: #404040;
  --heading: #13264d;
  --muted: rgba(0, 0, 0, 0.45);
  --line: #cce1f4;
  --table-line: #b3cbe1;
  --paper: #f8fbff;
  --card: #ffffff;
  --danger: #ff5252;
  --danger-bg: #ffe2e2;
  --success: #30af5b;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
  --sider: linear-gradient(261.31deg, #006ccf -29.57%, #00509a 121.11%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Montserrat, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
}

a {
  color: var(--primary);
}

h1 {
  margin: 0 0 20px;
  color: var(--heading);
  font-size: 1.6rem;
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.875rem;
  font-weight: 500;
}

input,
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  color: var(--ink);
  background: white;
}

input:focus,
select:focus {
  outline: 2px solid rgba(1, 80, 154, 0.25);
  border-color: var(--primary);
}

input[type="radio"],
input[type="checkbox"],
input[type="file"] {
  display: inline-block;
  width: auto;
  margin: 0 6px 0 0;
  padding: 0;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 7px;
  margin: 0 0 16px;
}

fieldset label {
  display: inline-flex;
  align-items: center;
  margin: 0 16px 0 0;
}

button,
.button {
  font: inherit;
  font-weight: 600;
  background: var(--primary);
  color: white;
  border: 0;
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: var(--primary-dark);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

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

.login-card {
  width: min(100%, 420px);
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
}

.login-card .brand {
  color: var(--primary);
}

.login-card h1 {
  margin-top: 8px;
}

.login-extra {
  margin: -8px 0 16px;
  text-align: right;
}

.login-extra a {
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}

.brand {
  margin: 0;
  color: white;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 7px;
  padding: 10px 12px;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  overflow: hidden;
}

.sidebar {
  background: var(--sider);
  color: white;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow: auto;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar a {
  color: white;
  text-decoration: none;
  border-radius: 7px;
  padding: 10px 12px;
  font-weight: 500;
}

.sidebar a.brand {
  padding: 0 12px 8px;
  font-size: 1.15rem;
  font-weight: 700;
}

.sidebar a.active,
.sidebar a:hover {
  background: rgba(255, 255, 255, 0.16);
}

.sidebar a.brand:hover {
  background: transparent;
}

.nav-group {
  margin-top: 8px;
}

.nav-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 7px;
  color: white;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.nav-group summary::-webkit-details-marker {
  display: none;
}

.nav-group summary::after {
  content: "";
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid currentColor;
}

.nav-group[open] summary::after {
  transform: rotate(180deg);
}

.nav-group summary:hover,
.nav-group[open] summary {
  background: rgba(255, 255, 255, 0.16);
}

.nav-group a {
  display: block;
  padding-left: 28px;
  font-weight: 400;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.topbar {
  height: 4.25rem;
  display: grid;
  grid-template-columns: 1fr minmax(240px, 460px) 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
}

.page-search {
  position: relative;
  grid-column: 2;
  width: 100%;
}

.topbar-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-search input {
  width: 100%;
  margin: 0;
  border-radius: 999px;
  padding: 10px 44px;
}

.page-search input[type="search"]::-webkit-search-cancel-button {
  display: none;
}

.page-search-icon,
.page-search-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  color: var(--primary);
}

.page-search-icon {
  left: 14px;
  pointer-events: none;
}

.page-search-toggle {
  right: 8px;
  padding: 0;
  background: transparent;
  color: var(--primary);
}

.page-search-toggle:hover,
.page-search-toggle[aria-pressed="true"] {
  background: transparent;
  color: var(--primary-dark);
}

.page-search-menu {
  position: absolute;
  z-index: 6;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  padding: 8px 0 12px;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 380px;
  overflow: auto;
}

.page-search-menu[hidden],
.page-search-filter[hidden] {
  display: none;
}

.page-search-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.page-search-filter label {
  display: flex;
  align-items: center;
  margin: 0;
  font-weight: 500;
}

.page-search-results h3 {
  margin: 12px 16px 4px;
  color: var(--primary);
  font-size: 0.95rem;
}

.page-search-results a {
  display: block;
  padding: 10px 16px;
  color: var(--heading);
  font-weight: 600;
  text-decoration: none;
}

.page-search-results a:hover {
  background: rgba(1, 80, 154, 0.06);
}

.linkish {
  background: transparent;
  color: var(--primary);
  padding: 8px 12px;
  text-decoration: none;
}

.linkish:hover {
  background: rgba(1, 80, 154, 0.08);
}

.content {
  padding: 8px 32px 32px;
}

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

.notice {
  color: var(--success);
  font-weight: 600;
}

.toolbar,
.lookup-form,
#table-panel {
  min-width: 0;
}

#table-panel,
.content > table {
  background: var(--card);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

#table-panel table {
  background: transparent;
  box-shadow: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  padding: 16px;
}

.toolbar form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar a {
  font-weight: 600;
  text-decoration: none;
}

.lookup-form,
.lookup-form form {
  display: grid;
  gap: 4px;
  max-width: 520px;
  margin-bottom: 16px;
  padding: 20px;
}

.lookup-form form {
  padding: 0;
  margin: 0;
  box-shadow: none;
  background: transparent;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--table-line);
  vertical-align: middle;
  overflow-wrap: break-word;
}

th {
  color: var(--heading);
  font-size: 0.85rem;
  font-weight: 600;
  background: #f8fbff;
}

.row-actions {
  width: 1%;
  white-space: nowrap;
}

td.row-actions {
  white-space: nowrap;
}

td.row-actions .icon-button {
  margin-right: 8px;
  vertical-align: middle;
}

td.row-actions .icon-button:last-child {
  margin-right: 0;
}

.col-filter .row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
  vertical-align: -3px;
}

a.icon-button,
button.icon-button {
  display: inline-flex;
  flex: 0 0 32px;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  background: white;
  color: var(--heading);
  border: 1px solid var(--line);
  border-radius: 7px;
}

a.icon-button:hover,
button.icon-button:hover {
  background: #f8fbff;
  color: var(--primary);
}

button.icon-button.danger {
  color: var(--danger);
  border-color: #ffc9c9;
}

button.icon-button.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

.ghost,
.row-actions a:not(.icon-button) {
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-weight: 600;
  text-decoration: none;
}

.ghost:hover,
.row-actions a:not(.icon-button):hover {
  background: transparent;
  color: var(--primary-dark);
}

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
}

.settings-index {
  list-style: none;
  margin: 0;
  padding: 8px;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 420px;
}

.settings-index a {
  display: block;
  padding: 12px 14px;
  border-radius: 7px;
  text-decoration: none;
  font-weight: 500;
}

.settings-index a:hover {
  background: rgba(1, 80, 154, 0.06);
}

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

.page-head h1 {
  margin: 0;
}

.create-menu {
  position: relative;
}

.create-menu summary {
  list-style: none;
  background: var(--primary);
  color: white;
  font-weight: 600;
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
}

.create-menu summary::-webkit-details-marker {
  display: none;
}

.create-menu summary:hover {
  background: var(--primary-dark);
}

.create-menu div {
  position: absolute;
  z-index: 4;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  padding: 8px;
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.create-menu a,
.create-menu span {
  display: block;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--heading);
  font-weight: 600;
  text-decoration: none;
}

.create-menu a:hover {
  background: rgba(1, 80, 154, 0.06);
}

.create-menu span {
  color: #b3b3b3;
}

.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
}

.pager > span:first-child {
  margin-right: auto;
}

.pager a,
.pager .current,
.pager .ellipsis {
  min-width: 2rem;
  padding: 4px 8px;
  border-radius: 7px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
}

.pager a {
  color: var(--primary);
}

.pager .current {
  background: var(--primary);
  color: white;
}

.page-size {
  margin: 0 0 0 8px;
}

.page-size select {
  width: auto;
  margin: 0;
  padding: 4px 8px;
  font-size: 0.85rem;
}

.record-form {
  display: grid;
  gap: 4px;
}

.combo {
  position: relative;
}

.combo-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.combo-menu li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.combo-menu li.muted {
  cursor: default;
}

.combo-menu li.active,
.combo-menu li[data-value]:hover {
  background: rgba(1, 80, 154, 0.08);
}

.record-form h2,
.modal h2 {
  margin: 0 0 16px;
  color: var(--heading);
  font-size: 1.15rem;
}

.modal {
  width: min(640px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal::backdrop {
  background: rgba(19, 38, 77, 0.45);
}

.modal-dismiss {
  position: absolute;
  top: 12px;
  right: 12px;
}

.modal-dismiss button {
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 6px;
}

.import-switch {
  display: grid;
}

.import-switch > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.import-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.import-tabs label {
  margin: 0;
  padding: 10px 4px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

#import-return:checked ~ .import-tabs label[for="import-return"],
#import-sheet:checked ~ .import-tabs label[for="import-sheet"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.import-panel {
  display: none;
  gap: 12px;
}

#import-return:checked ~ .import-panel[data-panel="return"],
#import-sheet:checked ~ .import-panel[data-panel="sheet"] {
  display: grid;
}

.import-panel .muted {
  margin: 0;
}

a.button.secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  background: white;
  color: var(--primary);
  border: 1px solid var(--line);
}

a.button.secondary:hover {
  background: #f8fbff;
}

.file-drop {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  margin: 0;
  padding: 24px 16px;
  border: 1px dashed var(--primary);
  border-radius: 8px;
  background: #f8fbff;
  color: var(--heading);
  font-weight: 600;
  cursor: pointer;
}

.file-drop .file-name {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.file-drop input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.col-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.col-head > a {
  color: var(--heading);
  text-decoration: none;
}

.col-filter {
  position: relative;
  margin-left: auto;
}

.col-filter summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
}

th {
  white-space: nowrap;
}

.col-filter.active summary {
  color: var(--primary);
  background: rgba(1, 80, 154, 0.08);
  border-color: var(--primary);
}

.col-filter summary::-webkit-details-marker {
  display: none;
}

.col-filter form {
  position: absolute;
  z-index: 3;
  top: calc(100% + 6px);
  right: 0;
  width: 240px;
  padding: 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filter-options {
  max-height: 220px;
  overflow: auto;
  margin-bottom: 8px;
}

.filter-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  font-weight: 400;
}

.dash-period {
  margin: 4px 0 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat,
.dash-card {
  background: var(--card);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat {
  padding: 16px 18px;
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-value {
  margin: 8px 0 4px;
  color: var(--heading);
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  margin: 0;
  font-size: 0.85rem;
}

.stat-note.up {
  color: var(--success);
}

.stat-note.down {
  color: var(--danger);
}

.stat-note.flat,
.chart-total {
  color: var(--muted);
}

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.dash-card {
  padding: 18px 18px 8px;
  margin-bottom: 16px;
}

.dash-grid .dash-card {
  margin-bottom: 0;
}

.dash-card h2 {
  margin: 0 0 16px;
  color: var(--heading);
  font-size: 1.05rem;
  font-weight: 600;
}

.dash-card .page-head {
  margin-bottom: 8px;
}

.dash-card .page-head h2 {
  margin: 0;
}

.bars-scroll {
  overflow-x: auto;
}

.bars {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 8px;
  height: 200px;
  min-width: 520px;
}

.bar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.bar-plot {
  display: flex;
  flex: 1;
  align-items: flex-end;
}

.bar-stack {
  display: flex;
  flex-direction: column-reverse;
  width: 100%;
  height: var(--h);
  border-radius: 4px 4px 0 0;
  overflow: hidden;
}

.bar-stack span {
  display: block;
  min-height: 2px;
}

.month-picker {
  margin: 0;
}

.month-picker label {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.month-picker select {
  width: auto;
  min-width: 220px;
  margin-top: 6px;
}

.bar-detail {
  display: none;
}

.chart-tip {
  position: fixed;
  z-index: 8;
  min-width: 180px;
  max-width: 260px;
  padding: 10px 12px;
  background: white;
  color: var(--heading);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 0.85rem;
}

.chart-tip[hidden] {
  display: none;
}

.chart-tip strong,
.chart-tip p {
  margin: 0;
}

.chart-tip p {
  margin-top: 2px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-tip ul {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.chart-tip li {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.chart-tip li span {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.chart-tip i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.bar-label {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.68rem;
  text-align: center;
}

.bar.is-current .bar-label {
  color: var(--heading);
  font-weight: 700;
}

.chart-total {
  margin: 12px 0 0;
  font-size: 0.85rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 10px 0 12px;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 2px;
}

.type-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

.type-track {
  grid-column: 1 / -1;
  height: 8px;
  background: #e7f0f8;
  border-radius: 999px;
  overflow: hidden;
}

.type-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.latest-table {
  margin: 0 -18px;
  overflow-x: auto;
}

.latest-table table {
  background: transparent;
  box-shadow: none;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 14px 18px;
  border: 0;
  border-left: 4px solid var(--success);
  border-radius: 8px;
  background: var(--heading);
  color: white;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(19, 38, 77, 0.28);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: none;
}

@media (max-width: 800px) {
  .shell {
    height: auto;
    overflow: visible;
    grid-template-columns: 1fr;
  }

  .main {
    overflow: visible;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-group {
    width: 100%;
  }

  .content,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

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

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