:root {
  --ink: #10231f;
  --muted: #64736e;
  --line: #d9e1de;
  --line-strong: #bbc9c4;
  --surface: #ffffff;
  --surface-soft: #f3f6f4;
  --surface-alt: #e9efec;
  --sidebar: #10231f;
  --sidebar-active: #2c403a;
  --teal: #087f6c;
  --teal-dark: #056252;
  --purple: #28135f;
  --yellow: #f3bc4b;
  --red: #b42318;
  --green: #137a3d;
  --amber: #a85f00;
  --blue: #245aa6;
  --shadow: 0 12px 28px rgb(16 35 31 / 8%);
  --radius: 6px;
  --sidebar-width: 276px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface-soft);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--surface-soft);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

a {
  color: var(--teal-dark);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 6px;
  font-size: 21px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
  line-height: 1.3;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  border-left: 9px solid var(--purple);
  background: var(--surface-soft);
}

.login-panel {
  display: grid;
  width: min(440px, 100%);
  gap: 18px;
  padding: 34px;
  border: 1px solid var(--line);
  border-top: 5px solid var(--teal);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  width: min(250px, 80%);
  height: 62px;
  object-fit: contain;
  object-position: left center;
}

.login-panel h1 {
  font-size: 27px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  height: 100vh;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  background: var(--sidebar);
  color: #f7fbf9;
}

.brand {
  display: grid;
  min-height: 82px;
  align-items: center;
  gap: 11px;
  grid-template-columns: 86px minmax(0, 1fr);
  padding: 14px 16px;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
}

.brand img {
  width: 86px;
  height: 42px;
  padding: 5px;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}

.brand strong,
.brand span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  font-size: 15px;
}

.brand span {
  color: #b7c7c1;
  font-size: 12px;
}

.sidebar-close {
  display: none;
}

.navigation {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px 26px;
  scrollbar-color: #52655f transparent;
}

.nav-link,
.nav-group > summary {
  display: flex;
  min-height: 42px;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 0;
  border-radius: 5px;
  color: #edf4f1;
  background: transparent;
  text-align: left;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.nav-link:hover,
.nav-group > summary:hover {
  background: rgb(255 255 255 / 8%);
}

.nav-link.active {
  color: #fff;
  background: var(--sidebar-active);
  box-shadow: inset 3px 0 var(--yellow);
}

.nav-link svg,
.nav-group > summary svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.nav-group {
  margin: 2px 0;
}

.nav-group > summary {
  cursor: pointer;
  list-style: none;
}

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

.nav-group > summary::after {
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

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

.nav-children {
  display: grid;
  gap: 2px;
  padding: 2px 0 5px 28px;
}

.nav-children .nav-link {
  min-height: 36px;
  padding: 7px 10px;
  color: #c8d5d1;
  font-size: 13px;
}

.sidebar-footer {
  padding: 14px 18px 18px;
  border-top: 1px solid rgb(255 255 255 / 10%);
  color: #b8c9c3;
}

.sidebar-footer span,
.sidebar-footer small {
  display: block;
}

.sidebar-footer span {
  font-size: 12px;
  font-weight: 700;
}

.sidebar-footer small {
  margin-top: 3px;
  color: #82978f;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  min-height: 82px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(10px);
}

.topbar-title {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.topbar-title h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumbs {
  display: flex;
  min-height: 18px;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.breadcrumbs span + span::before,
.breadcrumbs a + span::before {
  margin-right: 7px;
  color: var(--line-strong);
  content: "/";
}

.user-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
}

.current-user {
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.current-user span,
.current-user strong {
  display: block;
}

.current-user span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.current-user strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-button {
  display: none;
}

.page {
  display: grid;
  gap: 18px;
  padding: 22px 24px 60px;
}

.page-intro {
  display: flex;
  min-width: 0;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.page-intro p,
.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.page-actions,
.form-actions,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 5px 20px rgb(16 35 31 / 4%);
}

.panel.flush {
  padding: 0;
}

.section-heading {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading.compact {
  margin-bottom: 9px;
}

.filter-panel {
  padding: 14px 16px;
}

.filter-grid,
.form-grid {
  display: grid;
  align-items: end;
  gap: 13px;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.form-grid {
  align-items: start;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
}

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

.field > span,
.field-label {
  color: #4e605a;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.combobox-input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
  color: var(--ink);
  background: var(--surface);
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.combobox-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgb(8 127 108 / 12%);
}

.field.span-2 {
  grid-column: span 2;
}

.field.span-3 {
  grid-column: 1 / -1;
}

.check-field {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  font-weight: 600;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.check-grid {
  display: grid;
  gap: 8px 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-group {
  display: grid;
  min-width: 0;
  gap: 8px 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.choice-group.span-3,
.check-row.span-3 {
  grid-column: 1 / -1;
}

.choice-group legend {
  padding: 0 5px;
  color: #4e605a;
  font-size: 12px;
  font-weight: 700;
}

.check-row {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.check-row input {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  accent-color: var(--teal);
}

.row-actions {
  display: flex;
  gap: 5px;
}

.row-actions .icon-button {
  width: 34px;
  height: 34px;
}

.icon-button.danger {
  color: var(--red);
}

.button,
.icon-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 700;
  text-decoration: none;
  transition: background 120ms ease, border 120ms ease, color 120ms ease;
}

.button {
  min-height: 42px;
  gap: 8px;
  padding: 9px 14px;
  background: var(--surface-alt);
  color: var(--ink);
}

.button svg {
  width: 17px;
  height: 17px;
}

.button.primary {
  border-color: var(--teal);
  color: #fff;
  background: var(--teal);
}

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

.button.secondary {
  border-color: var(--purple);
  color: var(--purple);
  background: #fff;
}

.button.subtle {
  border-color: var(--line);
  background: #fff;
}

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

.button.wide {
  width: 100%;
}

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

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-color: var(--line);
  color: var(--ink);
  background: #fff;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-alt);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.sidebar-close,
.menu-button {
  display: none;
}

.metrics-grid {
  display: grid;
  min-width: 0;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metrics-grid.six {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.metric {
  min-width: 0;
  min-height: 128px;
  padding: 15px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 5px 18px rgb(16 35 31 / 5%);
}

.metric.positive {
  border-top-color: var(--green);
}

.metric.warning {
  border-top-color: var(--yellow);
}

.metric.negative {
  border-top-color: var(--red);
}

.metric.info {
  border-top-color: var(--purple);
}

.metric-label {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-value {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
  font-size: 27px;
  font-weight: 800;
  line-height: 1.12;
}

.metric-foot {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-badge,
.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #40534d;
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.won,
.status-badge.paid {
  color: var(--green);
  background: #eaf6ed;
}

.status-badge.lost,
.status-badge.overdue {
  color: var(--red);
  background: #fff0ef;
}

.status-badge.under_review,
.status-badge.waiting_payment {
  color: var(--amber);
  background: #fff6df;
}

.table-shell {
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  scrollbar-color: #9eaba7 #eef2f0;
}

.trip-journal-resizable {
  height: 520px;
  min-height: 240px;
  max-height: 75vh;
  overflow: auto;
  resize: vertical;
}

.trip-journal-resizable.is-collapsed {
  display: none;
}

.data-table {
  width: 100%;
  min-width: 960px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  position: relative;
  height: 48px;
  padding: 9px 11px;
  overflow: hidden;
  border-bottom: 1px solid #e9eeec;
  text-align: left;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 44px;
  color: #344640;
  background: #eef3f0;
  font-size: 12px;
  font-weight: 800;
  min-width: 52px;
}

.space-top {
  margin-top: 18px;
}

.data-table tbody tr:hover td {
  background: #f8faf9;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table td.numeric,
.data-table th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cell-link {
  display: block;
  width: 100%;
  overflow: hidden;
  color: var(--teal-dark);
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.cell-link {
  padding: 0;
  border: 0;
  background: transparent;
}

.cell-actions {
  display: flex;
  gap: 5px;
}

.cell-actions .icon-button {
  width: 32px;
  height: 32px;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 4;
  width: 9px;
  height: 100%;
  cursor: col-resize;
}

.column-resizer:hover,
body.resizing-column .column-resizer {
  border-right: 2px solid var(--teal);
}

body.resizing-column {
  cursor: col-resize;
  user-select: none;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 7px;
}

.empty-state,
.placeholder {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 36px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: #fbfcfb;
  text-align: center;
}

.placeholder svg {
  width: 42px;
  height: 42px;
  margin-bottom: 12px;
  color: var(--purple);
}

.loading {
  display: grid;
  min-height: 300px;
  place-items: center;
  color: var(--muted);
}

.loading::before {
  width: 26px;
  height: 26px;
  margin-right: 10px;
  border: 3px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  content: "";
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow-y: auto;
  padding: 5vh 18px;
  background: rgb(16 35 31 / 62%);
}

.modal {
  width: min(1080px, 100%);
  max-height: 90vh;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgb(0 0 0 / 26%);
}

.modal.narrow {
  width: min(650px, 100%);
}

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

.modal-header h2 {
  margin: 0;
}

.modal-body {
  max-height: calc(90vh - 64px);
  overflow-y: auto;
  padding: 18px;
}

.modal-body form {
  display: grid;
  gap: 18px;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 150;
  display: grid;
  width: min(390px, calc(100vw - 36px));
  gap: 8px;
}

.toast {
  padding: 12px 14px;
  border-left: 4px solid var(--teal);
  border-radius: 5px;
  color: #fff;
  background: #173a32;
  box-shadow: var(--shadow);
}

.toast.error {
  border-left-color: var(--yellow);
  background: #7b251e;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.callout {
  padding: 12px 14px;
  border-left: 4px solid var(--yellow);
  background: #fff8e8;
  color: #57451e;
}

.combobox {
  position: relative;
}

.combobox-list {
  position: absolute;
  top: calc(100% + 3px);
  right: 0;
  left: 0;
  z-index: 20;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  box-shadow: var(--shadow);
}

.combobox-option {
  display: block;
  width: 100%;
  padding: 9px 11px;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid #edf1ef;
  background: #fff;
  color: var(--ink);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combobox-option:hover,
.combobox-option.active {
  background: var(--surface-alt);
}

.split-layout {
  display: grid;
  min-width: 0;
  gap: 18px;
  grid-template-columns: minmax(0, 1.4fr) minmax(310px, 0.6fr);
}

.summary-list {
  display: grid;
  gap: 1px;
  border: 1px solid var(--line);
  background: var(--line);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  background: #fff;
}

.summary-row strong {
  text-align: right;
}

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

.positive-text {
  color: var(--green);
}

.negative-text {
  color: var(--red);
}

.nowrap {
  white-space: nowrap;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgb(0 0 0 / 42%);
}

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

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    width: min(var(--sidebar-width), calc(100vw - 54px));
    transition: transform 160ms ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close,
  .menu-button {
    display: inline-flex;
  }

  .brand {
    grid-template-columns: 86px minmax(0, 1fr) 38px;
  }

  .brand .sidebar-close {
    width: 38px;
    height: 38px;
    border-color: rgb(255 255 255 / 20%);
    color: #fff;
    background: transparent;
  }

  .topbar {
    padding: 12px 16px;
  }

  .page {
    padding: 18px 16px 50px;
  }

  .current-user {
    min-width: 170px;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  body {
    font-size: 14px;
  }

  h1 {
    font-size: 23px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: flex-start;
    gap: 8px;
  }

  .user-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 5px;
  }

  .current-user {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .user-actions .button span {
    display: none;
  }

  .user-actions .button {
    width: 42px;
    padding: 0;
  }

  .filter-grid,
  .form-grid,
  .metrics-grid,
  .metrics-grid.six {
    grid-template-columns: 1fr;
  }

  .field.span-2,
  .field.span-3 {
    grid-column: auto;
  }

  .metric {
    min-height: 108px;
  }

  .page-intro,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions,
  .section-heading .page-actions {
    justify-content: flex-start;
  }

  .modal-layer {
    padding: 0;
  }

  .modal {
    width: 100%;
    min-height: 100vh;
    max-height: none;
    border: 0;
  }

  .modal-body {
    max-height: calc(100vh - 64px);
  }

  .login-panel {
    padding: 25px 21px;
  }
}
