:root {
  color-scheme: light dark;
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-soft: #ece8df;
  --text: #202124;
  --muted: #62605b;
  --line: #d7d1c4;
  --accent: #276a62;
  --accent-strong: #194d47;
  --danger-bg: #fff0f0;
  --danger-text: #8a1f1f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(32, 33, 36, 0.12);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.muted,
.tool-card p {
  color: var(--muted);
  line-height: 1.55;
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

label {
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(39, 106, 98, 0.18);
}

button {
  min-height: 44px;
  padding: 10px 16px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.secondary-button {
  color: var(--text);
  background: var(--surface-soft);
}

.secondary-button:hover {
  color: #fff;
  background: var(--accent-strong);
}

.danger-button {
  color: #fff;
  background: #9b2f2f;
}

.danger-button:hover {
  background: #7b2424;
}

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

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

.ghost-button {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

.ghost-button:hover {
  background: var(--surface-soft);
}

.flash {
  padding: 10px 12px;
  border-radius: 6px;
}

.flash.error {
  color: var(--danger-text);
  background: var(--danger-bg);
}

.flash.success {
  color: #145437;
  background: #dff2e8;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px min(5vw, 42px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
  text-decoration: none;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topnav a,
.ghost-link,
.tool-footer a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.topnav a:hover,
.ghost-link:hover,
.tool-footer a:hover {
  text-decoration: underline;
}

.portal-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 48px min(5vw, 42px);
}

.portal-shell.compact {
  padding-top: 28px;
}

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

.section-head h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 6vw, 3rem);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.hero {
  max-width: 720px;
  margin-bottom: 34px;
}

.hero h1 {
  font-size: clamp(2.2rem, 7vw, 4.6rem);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.tool-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tool-card span {
  width: fit-content;
  padding: 5px 9px;
  color: var(--accent-strong);
  background: rgba(39, 106, 98, 0.12);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

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

.admin-section {
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.admin-head {
  margin-bottom: 14px;
}

.admin-head h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.admin-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 280px));
}

.docker-list {
  display: grid;
  gap: 12px;
}

.docker-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.docker-main {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #9b2f2f;
}

.status-dot.online {
  background: #20754d;
}

.status-dot.partial {
  background: #a96f13;
}

.docker-title {
  min-width: 0;
}

.docker-title h2,
.docker-title p {
  overflow-wrap: anywhere;
}

.docker-title p,
.docker-details {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.state-pill,
.locked-note {
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.state-pill.online {
  color: #145437;
  background: #dff2e8;
}

.state-pill.partial {
  color: #6b4308;
  background: #f7e9cf;
}

.state-pill.offline,
.locked-note {
  color: #7f2525;
  background: #f7dddd;
}

.docker-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.docker-meta div {
  min-width: 0;
}

.docker-meta dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.docker-meta dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-size: 0.88rem;
}

.docker-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.docker-actions form {
  margin: 0;
}

.docker-actions button,
.docker-actions .ghost-link {
  min-width: 86px;
}

.log-box {
  min-height: 420px;
  max-height: 70vh;
  margin: 0;
  padding: 14px;
  overflow: auto;
  color: #eef6f3;
  background: #111615;
  border-radius: 8px;
  font: 0.82rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log-box.small {
  min-height: 240px;
}

.job-panel {
  display: grid;
  gap: 16px;
  margin-bottom: 28px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.job-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.job-meta {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.section-head.lower {
  margin-top: 6px;
}

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

.location-summary {
  grid-template-columns: minmax(180px, 1.2fr) repeat(auto-fit, minmax(150px, 1fr));
}

.metric,
.sp-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 14px;
}

.total-metric {
  border-color: rgba(39, 106, 98, 0.42);
}

.metric span,
.location-list dt {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.sp-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.sp-main,
.sp-side,
.sp-stack,
.pot-list,
.booking-list,
.sp-form,
.location-list {
  display: grid;
  gap: 12px;
}

.sp-panel {
  padding: 16px;
}

.modal {
  width: min(92vw, 560px);
  max-height: min(86vh, 760px);
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}

.modal::backdrop {
  background: rgba(32, 33, 36, 0.48);
}

.modal-panel {
  max-height: min(86vh, 760px);
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(32, 33, 36, 0.22);
}

.modal.wide {
  width: min(92vw, 760px);
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover {
  color: #fff;
  background: var(--accent-strong);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.salary-input-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.salary-summary {
  margin: 0;
}

.salary-preview {
  max-height: 280px;
  overflow: auto;
  padding-right: 4px;
}

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

.panel-head h2 {
  margin-bottom: 0;
}

.pot-card {
  display: grid;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pot-card:hover {
  border-color: rgba(39, 106, 98, 0.58);
}

.pot-link {
  display: grid;
  gap: 10px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
}

.pot-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.pot-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.pot-card p,
.booking-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.pot-balance-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.pot-balance-row strong {
  font-size: 1.25rem;
}

.pot-balance-row span,
.location-splits,
.booking-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.progress-bar {
  height: 9px;
  overflow: hidden;
  background: var(--surface);
  border-radius: 999px;
}

.progress-bar div {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.location-splits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.booking-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.booking-item:last-child {
  border-bottom: 0;
}

.booking-item strong,
.booking-item b {
  overflow-wrap: anywhere;
}

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

.booking-item a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.booking-item b {
  text-align: right;
}

.positive {
  color: #20754d;
}

.negative {
  color: #9b2f2f;
}

.sp-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.location-list {
  margin: 0;
}

.location-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.location-list div:last-child {
  border-bottom: 0;
}

.location-list dd {
  margin: 0;
  font-weight: 800;
}

.edit-list {
  display: grid;
  gap: 14px;
}

.edit-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.edit-form button {
  grid-column: 1 / -1;
}

code {
  padding: 1px 4px;
  background: var(--surface-soft);
  border-radius: 4px;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .page-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .page-actions button,
  .modal-actions button,
  .modal-actions .ghost-link {
    width: 100%;
  }

  .docker-main,
  .docker-meta,
  .job-meta,
  .sp-summary,
  .sp-layout,
  .salary-input-row {
    grid-template-columns: 1fr;
  }

  .modal-actions .ghost-link {
    min-height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
  }

  .pot-card-head,
  .booking-item {
    grid-template-columns: 1fr;
  }

  .booking-item b {
    text-align: left;
  }

  .status-dot {
    display: none;
  }

  .state-pill {
    width: fit-content;
  }

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

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

  .docker-actions form,
  .docker-actions button,
  .docker-actions .ghost-link {
    width: 100%;
  }

  .docker-actions .ghost-link {
    min-height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171917;
    --surface: #20231f;
    --surface-soft: #2a2e29;
    --text: #f1f0ea;
    --muted: #b8b3a6;
    --line: #3d423b;
    --accent: #80c7ba;
    --accent-strong: #a9ded4;
    --danger-bg: #3b2020;
    --danger-text: #ffc7c7;
  }
}
