:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #24272d;
  --muted: #686f78;
  --line: #d8dde3;
  --accent: #1f7a68;
  --accent-strong: #165d50;
  --warning: #a65f00;
  --warning-bg: #fff8ed;
  --warning-border: #f0c76e;
  --error: #a23b3b;
  --shadow: 0 14px 34px rgba(42, 51, 61, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

button,
textarea {
  font: inherit;
}

/* ── Shell & layout ───────────────────────────────────────────────────────── */

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 32px auto 64px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
  min-width: 0;
}

.nav-sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.nav-new-btn {
  width: 100%;
  text-align: center;
  font-weight: 800;
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
}

.nav-new-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

/* ── Input panel ────────────────────────────────────────────────────────────  */

.input-panel,
.status-panel,
.result-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.input-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(340px, 1.15fr);
  gap: 32px;
  padding: 28px;
}

.input-left {
  display: flex;
  flex-direction: column;
}

.input-right {
  display: grid;
  gap: 0;
}

/* ── Typography ─────────────────────────────────────────────────────────────  */

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 3.2rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.2rem;
}

.lede {
  max-width: 560px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.lede-meta {
  margin: 8px 0 0;
  font-size: 0.85rem;
}

/* ── Ticket form ────────────────────────────────────────────────────────────  */

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

.ticket-form label {
  font-weight: 800;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid #b9c2cc;
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: #fbfcfd;
}

textarea:focus {
  outline: 3px solid rgba(31, 122, 104, 0.2);
  border-color: var(--accent);
}

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

.input-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: -4px;
}

/* ── Budget Calculator ──────────────────────────────────────────────────────  */

.budget-calc {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.budget-calc-heading {
  margin: 0 0 12px;
}

.calc-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
}

.calc-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.calc-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #b9c2cc;
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: #fbfcfd;
}

.calc-input:focus {
  outline: 2px solid rgba(31, 122, 104, 0.25);
  border-color: var(--accent);
}

.calc-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calc-result {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.calc-copy-btn {
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  border-color: var(--line);
  color: var(--muted);
}

.calc-copy-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.calc-copy-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Buttons ────────────────────────────────────────────────────────────────  */

button {
  min-height: 40px;
  border: 1px solid #b8c1ca;
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

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

.primary {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}

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

.secondary {
  font-weight: 700;
}

/* ── Generate modal ─────────────────────────────────────────────────────────  */

.generate-modal {
  border: none;
  border-radius: 12px;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: 400px;
  width: calc(100vw - 48px);
}

.generate-modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.modal-body {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-actions button {
  width: 100%;
  text-align: center;
}

/* ── Results toolbar ────────────────────────────────────────────────────────  */

.results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  box-shadow: var(--shadow);
}

.autosave-status {
  font-size: 0.82rem;
  color: var(--muted);
  margin-left: 4px;
}

.autosave-status.error {
  color: var(--error);
  font-weight: 700;
}

/* ── Status panel ───────────────────────────────────────────────────────────  */

.status-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

.stat {
  padding: 18px 22px;
  cursor: default;
  user-select: none;
}

.stat span {
  font-size: 2rem;
  font-weight: 900;
}

.stat p {
  margin: 4px 0 0;
  color: var(--muted);
}

/* ── Results area ───────────────────────────────────────────────────────────  */

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

.results-toolbar + .results .result-group:first-child {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
  box-shadow: none;
}

.empty-state {
  border: 1px dashed #aeb8c4;
  border-radius: 8px;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

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

button.copy-section {
  font-weight: 700;
  flex-shrink: 0;
}

button.copy-section:hover {
  border-color: var(--accent);
}

/* ── Table ──────────────────────────────────────────────────────────────────  */

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #eef4f2;
  font-weight: 800;
}

td.warning {
  color: var(--warning);
  font-weight: 700;
}

td.currency {
  font-variant-numeric: tabular-nums;
}

td.error {
  color: var(--error);
  font-weight: 800;
}

a {
  color: var(--accent-strong);
  font-weight: 700;
}

/* ── Sticky action columns ──────────────────────────────────────────────────  */

th.copy-col,
th.delete-col {
  width: 36px;
  min-width: 36px;
  padding: 0;
  position: sticky;
  right: 0;
  background: #eef4f2;
  z-index: 1;
}

th.delete-col {
  right: 36px;
  width: 32px;
  min-width: 32px;
}

td.copy-col,
td.delete-col {
  padding: 6px 4px;
  text-align: center;
  position: sticky;
  background: var(--panel);
  z-index: 1;
}

td.copy-col {
  right: 0;
}

td.delete-col {
  right: 36px;
  padding: 4px 2px;
  text-align: center;
}

button.copy-row {
  min-height: unset;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

button.copy-row:hover {
  color: var(--ink);
  border: none;
  background: var(--bg-alt, #f0f4f2);
}

button.delete-row {
  min-height: unset;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

button.delete-row:hover {
  color: var(--error);
  background: #fdf3f3;
  border: none;
}

/* ── Flight rows & save/edit ────────────────────────────────────────────────  */

th.flight-col {
  width: 28px;
  min-width: 28px;
  padding: 0;
}

td.flight-col {
  padding: 4px 2px;
  text-align: center;
}

th.save-col {
  width: 52px;
  min-width: 52px;
  padding: 0;
}

td.save-col {
  padding: 4px 4px;
  text-align: center;
  white-space: nowrap;
}

button.row-save {
  min-height: unset;
  height: 24px;
  padding: 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  border-radius: 4px;
}

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

button.row-edit {
  min-height: unset;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

button.row-edit:hover {
  color: var(--ink);
  background: var(--bg);
  border: none;
}

tr.flight-row td {
  border-left: 3px solid var(--accent);
}

tr.flight-row td:first-child {
  padding-left: 10px;
}

button.add-flight {
  min-height: unset;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.add-flight:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Editable cells — must beat tr.flight-row td (specificity 0,1,2) */
td.editable,
tr.flight-row td.editable {
  background: #e8f7ef;
  box-shadow: inset 3px 0 0 #2f7d6b;
  cursor: text;
  outline: none;
  transition: background 0.12s;
}

td.editable:hover,
tr.flight-row td.editable:hover {
  background: #d4ede3;
}

td.editable:focus,
tr.flight-row td.editable:focus {
  background: #d4ede3;
  outline: 2px solid #15803d;
  outline-offset: -2px;
}

/* ── Dedup + warning messages ───────────────────────────────────────────────  */

.dedup-message {
  font-size: 0.9rem;
  color: var(--muted);
  padding: 2px 0;
}

.warning-bar {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 0.9rem;
  color: var(--warning);
}

.warning-bar strong {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.warning-bar ul {
  margin: 0;
  padding-left: 20px;
}

.warning-bar li {
  margin: 2px 0;
  word-break: break-all;
}

/* ── Sidebar history ────────────────────────────────────────────────────────  */

.history-section {
  display: flex;
  flex-direction: column;
}

.history-heading {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 10px;
}

.history-empty {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.history-entry {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel);
  transition: border-color 0.12s;
}

.history-entry.active {
  border-color: var(--accent);
  background: #f0faf7;
}

.history-entry-date {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--ink);
  margin-bottom: 2px;
}

.history-entry-summary {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.history-entry-actions {
  display: flex;
  gap: 6px;
}

button.history-load {
  font-size: 0.82rem;
  min-height: 28px;
  padding: 0 10px;
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
  font-weight: 700;
}

button.history-load:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.history-delete {
  color: var(--error);
  border-color: transparent;
  background: transparent;
  font-size: 0.82rem;
  min-height: 28px;
  padding: 0 8px;
}

button.history-delete:hover {
  border-color: var(--error);
  background: #fdf3f3;
}

/* ── Responsive ─────────────────────────────────────────────────────────────  */

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

  .nav-sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }

  .nav-new-btn {
    width: auto;
  }

  .history-section {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
  }

  .history-entry {
    margin-bottom: 0;
  }
}

@media (max-width: 800px) {
  .input-panel {
    grid-template-columns: 1fr;
  }
}

/* ── Budget flighting upload panel ──────────────────────────────────────────  */

.flighting-panel {
  background: var(--panel);
  border: 1px solid var(--warning-border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.flighting-heading {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--ink);
}

.flighting-note {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.flighting-item {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.flighting-item-label {
  flex: 1 1 240px;
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-word;
}

.flighting-input {
  min-height: unset;
}

.flighting-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.flighting-status.ok {
  color: var(--accent-strong);
}

.flighting-status.error {
  color: var(--error);
}

.flighting-status.warn {
  color: var(--warning);
}

.flighting-continue {
  margin-top: 14px;
}

/* ── Candidate table selector ───────────────────────────────────────────────  */

.flighting-selection {
  flex-basis: 100%;
}

.flighting-select {
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 4px 0 8px;
}

.flighting-select legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  padding: 0 6px;
}

.flighting-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.85rem;
  cursor: pointer;
}

.flighting-option input {
  margin-top: 3px;
}

.flighting-option-meta {
  color: var(--muted);
}

.flighting-selected {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
}

/* Passive (non-selectable) candidate list + ticket expectation + info note. */
.flighting-passive {
  flex-basis: 100%;
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.flighting-passive-heading {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--ink);
}

.flighting-passive ul {
  margin: 0;
  padding-left: 18px;
}

.flighting-passive li {
  margin: 2px 0;
}

.flighting-passive-meta {
  color: var(--muted);
}

.flighting-expected {
  font-size: 0.85rem;
  margin: 0 0 8px;
  color: var(--ink);
}

.flighting-note-info {
  font-size: 0.83rem;
  margin: 0 0 8px;
  color: var(--muted);
}

/* ── Flighting preview + alignment warning ──────────────────────────────────  */

.flighting-preview {
  flex-basis: 100%;
  margin-top: 4px;
}

.flighting-warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--warning);
}

.flighting-warning strong {
  display: block;
  margin-bottom: 4px;
}

.flighting-warning ul {
  margin: 0;
  padding-left: 18px;
}

.flighting-warning li {
  margin: 2px 0;
}

.flighting-preview-caption {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.flighting-preview-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 320px;
}

.flighting-preview-table th,
.flighting-preview-table td {
  border: 1px solid var(--line);
  padding: 4px 10px;
  text-align: left;
}

.flighting-preview-table th {
  background: var(--bg);
  font-weight: 600;
}

.flighting-preview-table td.currency {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.flighting-preview-table tfoot td {
  font-weight: 700;
  background: var(--bg);
}

/* Outside-window rows: shown but visibly excluded (not color-only — the Status
   column spells out why, and the row is struck through). */
.flighting-preview-table tr.flighting-row-excluded td {
  color: var(--muted);
  text-decoration: line-through;
  background: var(--bg);
}

.flighting-preview-table td.flight-status-excluded {
  text-decoration: none;
  font-style: italic;
}

.flighting-preview-table td.flight-status-ok {
  color: var(--accent-strong);
}

.flighting-checks {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 10px 0 0;
  font-size: 0.83rem;
}

.flighting-checks dt {
  font-weight: 600;
}

.flighting-checks dd {
  margin: 0;
}

.flighting-checks .check-ok {
  color: var(--accent-strong);
}

.flighting-checks .check-warn {
  color: var(--warning);
}

/* ── Auto-created flight rows ───────────────────────────────────────────────  */

/* Highlight only the Start Date → Platform Budget band, not the whole row.
   Editable cells in the band keep their own (editable) styling via :not(). */
td.flight-cell:not(.editable) {
  background: #f2faf6;
}

/* Keep the accent divider line only within the highlighted band. Off-band cells
   (and every cell once the row is saved, when none are flight-cells) go clear. */
tr.auto-flight-row td:not(.flight-cell) {
  border-left-color: transparent;
}

/* ── Duplicate side-by-side comparison ──────────────────────────────────────  */

tr.duplicate-row td {
  opacity: 0.62;
}

tr.dup-comparison-row td {
  padding: 0;
  background: var(--warning-bg);
}

.dup-comparison {
  padding: 12px 16px;
}

.dup-tag {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dup-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.dup-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.dup-panel-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.dup-fields {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  font-size: 0.85rem;
}

.dup-fields dt {
  color: var(--muted);
  font-weight: 600;
}

.dup-fields dd {
  margin: 0;
  color: var(--ink);
  word-break: break-word;
}

.dup-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--accent);
}

@media (max-width: 700px) {
  .dup-panels {
    grid-template-columns: 1fr;
  }
}
