:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d7dee8;
  --accent: #0d766f;
  --accent-strong: #075e59;
  --accent-soft: #e8f5f3;
  --gold: #b7791f;
  --gold-soft: #fff7e6;
  --warning: #b45309;
  --danger: #b42318;
  --success: #166534;
  --selected: #eef7f1;
  --shadow: 0 16px 40px rgba(31, 41, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, #e8eef5 0, #f7f9fc 260px, var(--bg) 100%);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
  padding: 0 30px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.05);
}

.brand {
  color: #0f3f3b;
  font-weight: 700;
  text-decoration: none;
}

.nav {
  align-items: center;
  display: flex;
  gap: 18px;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover {
  color: var(--text);
}

.logout-form {
  margin: 0;
}

.user-chip {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  width: min(1280px, calc(100vw - 32px));
  margin: 28px auto 48px;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 4px 2px;
}

.page-heading h1 {
  margin: 0 0 4px;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

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

.heading-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.panel {
  margin-bottom: 18px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.calculation-panel {
  border-top: 4px solid var(--accent);
}

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

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.panel-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.auth-panel {
  width: min(420px, 100%);
}

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

.form-grid,
.settings-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
}

.calculation-panel .form-grid {
  grid-template-columns: minmax(260px, 420px) 180px minmax(160px, 1fr);
  align-items: end;
}

.calculation-unit-field {
  max-width: 420px;
}

.calculation-date-field {
  max-width: 180px;
}

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

.autocomplete-field {
  position: relative;
}

label span,
legend {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

select:disabled,
option:disabled,
.button:disabled {
  color: #98a2b3;
}

.button:disabled {
  background: #e2e8f0;
  border-color: #cbd5e1;
  cursor: not-allowed;
}

.autocomplete-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: none;
  max-height: 340px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.autocomplete-list::-webkit-scrollbar {
  width: 10px;
}

.autocomplete-list::-webkit-scrollbar-thumb {
  background: #b8c2d0;
  border: 3px solid #ffffff;
  border-radius: 999px;
}

.autocomplete-list.is-open {
  display: block;
}

.autocomplete-option,
.autocomplete-empty {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid #eef2f7;
  font: inherit;
  text-align: left;
}

.autocomplete-option {
  cursor: pointer;
}

.autocomplete-option:hover,
.autocomplete-option:focus {
  background: var(--accent-soft);
  outline: none;
}

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

.source-fieldset {
  min-width: 0;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.radio-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.radio-row input {
  width: auto;
  min-height: auto;
}

.form-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.route-builder {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.route-builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.route-builder-header h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.route-list {
  display: grid;
  gap: 10px;
}

.route-row {
  display: grid;
  grid-template-columns: minmax(130px, 160px) minmax(200px, 1fr) minmax(130px, 160px) minmax(200px, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid #dfe6ef;
  border-radius: 8px;
}

.route-remove {
  min-height: 40px;
  align-self: end;
}

.help-card {
  margin-bottom: 16px;
  background: linear-gradient(180deg, var(--gold-soft), #ffffff);
  border: 1px solid #f0d99b;
  border-radius: 8px;
}

.help-card summary {
  padding: 12px 14px;
  color: #6f4e12;
  font-weight: 700;
  cursor: pointer;
}

.help-body {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
  color: #475467;
}

.help-body p {
  margin: 0;
}

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  background: var(--accent-strong);
}

.button-secondary {
  color: #17403c;
  background: #ffffff;
  border-color: #aacbc7;
}

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

.link-button {
  padding: 0;
  color: var(--accent);
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

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

.inline-form {
  display: inline;
  margin: 0;
}

.action-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.calculation-progress {
  grid-column: 1 / -1;
  min-height: 22px;
  color: var(--muted);
}

.calculation-progress:not(:empty) {
  padding: 10px 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #b9e0dc;
  border-radius: 6px;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid;
}

.alert-success {
  color: var(--success);
  background: #edf7ed;
  border-color: #b7dfbc;
}

.alert-warning {
  color: var(--warning);
  background: #fff7ed;
  border-color: #fed7aa;
}

.alert-error {
  color: var(--danger);
  background: #fff1f0;
  border-color: #fecdca;
}

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

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

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

th {
  color: #475467;
  background: #f4f7fb;
  font-size: 13px;
  font-weight: 700;
}

.status {
  display: inline-block;
  max-width: 220px;
  color: #344054;
}

.candidate-row.is-hidden {
  display: none;
}

.candidate-box {
  padding: 10px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.nested-table {
  min-width: 760px;
  background: #ffffff;
}

.selected-candidate {
  background: var(--selected);
}

.selected-candidate td:first-child {
  border-left: 4px solid var(--success);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.meta-grid div {
  display: grid;
  gap: 4px;
}

.meta-grid span {
  color: var(--muted);
  font-size: 13px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .topbar,
  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    flex-wrap: wrap;
  }

  .form-grid,
  .settings-form,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .calculation-panel .form-grid {
    grid-template-columns: 1fr;
  }

  .calculation-unit-field,
  .calculation-date-field {
    max-width: none;
  }

  .route-builder-header {
    align-items: stretch;
    flex-direction: column;
  }

  .route-row {
    grid-template-columns: 1fr;
  }

  .main {
    width: min(100vw - 20px, 1280px);
    margin-top: 14px;
  }
}
