:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07131f;
  color: #eaf2f8;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(25, 105, 138, 0.19), transparent 30rem),
    linear-gradient(180deg, #07131f 0%, #0b1824 100%);
}

button { font: inherit; }
a { color: inherit; }
.inline-form { display: inline; margin: 0; }

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.control-row,
.matrix-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar { margin-bottom: 22px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.eyebrow,
.axis-label {
  margin: 0 0 5px;
  color: #66b8d7;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1, h2 { margin: 0; letter-spacing: -0.025em; }
h1 { font-size: clamp(1.55rem, 3vw, 2.25rem); }
h2 { font-size: 1.1rem; }

.lock-button,
.nav-button,
.collect-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #2c475b;
  border-radius: 9px;
  background: #102535;
  color: #f4f8fb;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}

.lock-button:hover,
.nav-button:hover,
.collect-button:hover { background: #173247; }
.lock-button:disabled,
.collect-button:disabled { opacity: .5; cursor: wait; }
.lock-button:focus-visible,
.nav-button:focus-visible,
.collect-button:focus-visible,
.operator-tab:focus-visible,
[draggable="true"]:focus-visible {
  outline: 3px solid #71c8e8;
  outline-offset: 2px;
}

.control-row {
  justify-content: flex-start;
  min-height: 66px;
  padding: 10px;
  margin-bottom: 16px;
  border: 1px solid #1c3446;
  border-radius: 12px;
  background: rgba(11, 30, 44, 0.78);
}

.operator-tabs {
  display: inline-flex;
  padding: 4px;
  border-radius: 9px;
  background: #07131f;
}

.operator-tab {
  min-width: 84px;
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #9fb2c0;
  font-weight: 800;
  cursor: pointer;
}

.operator-tab.active {
  background: #176c8d;
  color: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.period-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 210px;
  padding-left: 8px;
  color: #a8bbc8;
  font-size: 0.85rem;
}

.period-block strong { color: #f0f5f8; font-size: 0.98rem; }
.month-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #8fa6b5;
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.month-control input {
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #2c475b;
  border-radius: 7px;
  background: #07131f;
  color: #f0f6f9;
  color-scheme: dark;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: normal;
}
.month-control input:focus { outline: 2px solid #71c8e8; outline-offset: 1px; }
.collect-button { align-self: flex-end; min-height: 38px; border-color: #2580a3; background: #176c8d; }
.compact-month { min-width: 150px; }
.order-status { margin: 0 0 0 auto; color: #8fa6b5; font-size: 0.9rem; }

.matrix-card {
  overflow: hidden;
  border: 1px solid #1d374a;
  border-radius: 14px;
  background: #0b1b28;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.25);
}

.matrix-heading {
  padding: 18px 20px;
  border-bottom: 1px solid #1d374a;
}

.legend { display: flex; flex-wrap: wrap; gap: 15px; color: #b7c6d0; font-size: 0.85rem; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; }
.swatch.import { background: #c09524; }
.swatch.export { background: #2f8a61; }
.swatch.transit { background: #287aa4; }

.table-scroll { overflow: auto; max-height: calc(100vh - 255px); }

table {
  width: 100%;
  min-width: 850px;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

th, td {
  min-width: 92px;
  padding: 13px 12px;
  border-right: 1px solid #1c3547;
  border-bottom: 1px solid #1c3547;
  text-align: right;
  white-space: nowrap;
}

.output-head { min-width: 132px; vertical-align: top; }

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #102535;
  color: #e7f0f6;
  text-align: center;
  font-size: 0.82rem;
}

tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 164px;
  background: #102535;
  text-align: left;
  font-size: 0.88rem;
}

.corner {
  left: 0;
  z-index: 5;
  min-width: 164px;
  text-align: left;
}

td { background: #0d202f; color: #eef4f7; font-size: 0.9rem; }
td.zero { color: rgba(235, 244, 248, 0.38); }
td.import { background: rgba(192, 149, 36, 0.30); }
td.export { background: rgba(47, 138, 97, 0.32); }
td.transit { background: rgba(40, 122, 164, 0.34); }
.matrix-value { cursor: cell; user-select: none; }
.matrix-value.selected {
  position: relative;
  z-index: 1;
  box-shadow: inset 0 0 0 2px #76d7f5;
  filter: brightness(1.25);
}

.total,
tfoot th,
tfoot td {
  background: #132b3d;
  color: #ffffff;
  font-weight: 800;
}

tfoot th { position: sticky; left: 0; z-index: 2; text-align: left; }

.drag-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

thead .drag-label { justify-content: center; }

.drag-handle {
  display: none;
  color: #70bdd9;
  font-size: 1.05rem;
  letter-spacing: -0.12em;
  cursor: grab;
  user-select: none;
}

.reorderable .drag-handle { display: inline-block; }
.reorderable [draggable="true"] { cursor: grab; }
.dragging { opacity: 0.46; }
.drop-target { box-shadow: inset 4px 0 0 #75c9e7; }
thead .drop-target { box-shadow: inset 0 4px 0 #75c9e7; }

.schedule-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

thead .schedule-heading {
  flex-direction: column;
  gap: 6px;
}

.schedule-heading > a {
  color: #eef7fb;
  text-decoration-color: #41677c;
  text-underline-offset: 3px;
}
.schedule-heading > a:hover { color: #84dbf6; text-decoration-color: currentColor; }
.pills { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
thead .pills { margin-left: 0; }
.border-pill,
.mini-border {
  padding: 2px 6px;
  border: 1px solid #35566b;
  border-radius: 999px;
  color: #8fa9b9;
  font-size: 0.68rem;
  font-weight: 800;
}
.border-pill { border-color: #315f56; background: rgba(49, 95, 86, .18); color: #83cabb; }
.border-pill.local,
.mini-border.local,
.summary-badge.local { border-color: #896820; background: rgba(137, 104, 32, .22); color: #f1c761; }
.mini-border { display: block; width: fit-content; margin: 5px auto 0; color: #83cabb; font-size: 0.62rem; }
.summary-badge { width: fit-content; padding: 3px 8px; border: 1px solid #315f56; border-radius: 999px; color: #83cabb !important; font-size: .85rem !important; }
.summary-badge.local { color: #f1c761 !important; }
.no-data-cell { height: 230px; padding: 40px; background: #0d202f; color: #9fb2c0; text-align: center; white-space: normal; font-size: 1rem; }

.page-note { max-width: 480px; margin: 0; color: #8fa6b5; font-size: 0.85rem; text-align: right; }
.narrow-shell { width: min(1120px, 100%); }
.directory-scroll { max-height: calc(100vh - 190px); }
.directory-table { min-width: 720px; }
.directory-table th { text-align: left; }
.directory-table td { text-align: left; }
.directory-table .eic-code { color: #8ed7ed; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.detail-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid #1d374a;
  border-radius: 12px;
  background: #1d374a;
}
.detail-summary > div { display: flex; flex-direction: column; gap: 5px; padding: 15px 18px; background: #0d202f; }
.detail-summary span { color: #8fa6b5; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.detail-summary strong { color: #f0f6f9; font-size: 1.05rem; }
.detail-scroll { max-height: calc(100vh - 290px); }
.detail-table { min-width: 900px; }
.detail-table thead th { min-width: 130px; }
.detail-table thead th:first-child,
.detail-table tbody th,
.detail-table tfoot th { min-width: 90px; }
.detail-table thead a { color: #e8f5fa; text-underline-offset: 3px; }
.detail-table tbody th { text-align: left; }

.detail-controls { display: flex; align-items: center; gap: 14px; }
.view-toggle { display: inline-flex; padding: 4px; border-radius: 9px; background: #07131f; }
.view-toggle button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #9fb2c0;
  font-weight: 800;
  cursor: pointer;
}
.view-toggle button.active { background: #176c8d; color: #fff; }
.view-toggle button:focus-visible { outline: 3px solid #71c8e8; outline-offset: 2px; }

.mapping-form {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr 1.1fr auto;
  gap: 12px;
  align-items: end;
  padding: 16px 20px;
  border-bottom: 1px solid #1d374a;
  background: #0d202f;
}
.mapping-form label { display: flex; flex-direction: column; gap: 6px; color: #9fb2c0; font-size: 0.78rem; font-weight: 750; }
.mapping-form input {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid #2c475b; border-radius: 7px;
  background: #07131f; color: #f0f6f9; font: inherit;
}
.mapping-form input:focus { outline: 2px solid #71c8e8; outline-offset: 1px; }
.mapping-form input[readonly] { color: #8fa6b5; background: #10202c; }
.form-actions { display: flex; gap: 8px; }
.primary-button {
  min-height: 40px; padding: 0 15px; border: 1px solid #2580a3; border-radius: 8px;
  background: #176c8d; color: #fff; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.primary-button:hover { background: #1d7c9f; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.nav-button.compact { min-height: 40px; padding: 0 12px; }
.hidden { display: none !important; }
.form-status { grid-column: 1 / -1; min-height: 1.2em; margin: 0; color: #83cabb; font-size: .82rem; }
.form-status.error { color: #ff9f9f; }
.area-chip { display: inline-block; margin: 2px 2px 2px 0; padding: 2px 7px; border: 1px solid #315f56; border-radius: 999px; color: #83cabb; font-size: .74rem; }
.row-actions { display: flex; gap: 6px; }
.table-button { padding: 5px 9px; border: 1px solid #35566b; border-radius: 6px; background: #102535; color: #dceaf1; cursor: pointer; }
.table-button:hover { background: #173247; }
.table-button.danger { border-color: #71434a; color: #f2a8ae; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 34px; border: 1px solid #1d374a; border-radius: 14px; background: #0b1b28; box-shadow: 0 22px 60px rgba(0,0,0,.35); }
.login-copy { margin: 10px 0 24px; color: #8fa6b5; }
.login-form { display: grid; gap: 16px; }
.login-form label, .user-form label { display: flex; flex-direction: column; gap: 6px; color: #9fb2c0; font-size: .78rem; font-weight: 750; }
.login-form input, .user-form input, .user-form select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #2c475b; border-radius: 7px; background: #07131f; color: #f0f6f9; font: inherit; }
.login-error { padding: 10px 12px; border: 1px solid #71434a; border-radius: 7px; background: rgba(113,67,74,.2); color: #ffb4b9; }
.user-form { display: grid; grid-template-columns: 1fr 1.4fr 1.2fr .8fr auto; gap: 12px; align-items: end; padding: 16px 20px; border-bottom: 1px solid #1d374a; background: #0d202f; }
.user-form .form-status { grid-column: 1 / -1; }
.account-card { max-width: 680px; margin: 0 auto; }
.account-form { display: grid; gap: 16px; padding: 22px; }
.account-form label { display: flex; flex-direction: column; gap: 6px; color: #9fb2c0; font-size: .8rem; font-weight: 750; }
.account-form input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #2c475b; border-radius: 7px; background: #07131f; color: #f0f6f9; font: inherit; }
.form-status.success { color: #83cabb; }

@media (max-width: 720px) {
  .app-shell { padding: 14px; }
  .topbar { align-items: flex-end; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .lock-button { padding: 0 12px; }
  .control-row { flex-wrap: wrap; }
  .period-block { order: 3; width: 100%; padding: 4px 4px 0; }
  .month-control:not(.compact-month) { order: 2; margin-left: auto; }
  .order-status { margin-left: auto; }
  .matrix-heading { align-items: flex-start; flex-direction: column; }
  .page-note { text-align: left; }
  .detail-controls { width: 100%; align-items: flex-start; flex-direction: column; }
  .detail-summary { grid-template-columns: repeat(2, 1fr); }
  .mapping-form { grid-template-columns: 1fr; }
  .user-form { grid-template-columns: 1fr; }
  .form-status { grid-column: 1; }
  .table-scroll { max-height: calc(100vh - 330px); }
}
