:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --line: #d9e0e3;
  --text: #1e2528;
  --muted: #657177;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warning: #a16207;
  --danger: #b42318;
  --ok: #167a42;
  --shadow: 0 1px 2px rgb(30 37 40 / 8%);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 0 14px;
  cursor: pointer;
}

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

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

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

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

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f8fafb;
}

td button {
  min-height: 30px;
  padding: 0 10px;
}

.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #162326;
  color: white;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 26%);
  border-radius: 8px;
  background: #0f766e;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #b8c6c9;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-button {
  width: 100%;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: #dce7e9;
  text-align: left;
}

.nav-button:hover,
.nav-button.is-active {
  border-color: rgb(255 255 255 / 16%);
  background: rgb(255 255 255 / 10%);
  color: white;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.shell.is-login {
  grid-template-columns: minmax(0, 1fr);
}

.shell.is-login .workspace {
  width: min(560px, 100%);
  margin: 0 auto;
  padding-top: 12vh;
}

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

.topbar h2 {
  font-size: 24px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.session,
.toolbar,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.session span {
  color: var(--muted);
  font-weight: 700;
}

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #f0d28a;
  border-radius: 8px;
  background: #fff8e6;
  color: var(--warning);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.login-panel,
.detail,
.table-wrap,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel {
  margin-bottom: 18px;
  padding: 16px;
}

.login-header {
  margin-bottom: 14px;
}

.login-header h2,
.login-header p {
  margin: 0;
}

.login-header h2 {
  font-size: 22px;
}

.login-header p {
  margin-top: 4px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto;
  align-items: end;
  gap: 12px;
}

.form-grid.compact {
  margin-top: 12px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

.metric {
  display: block;
  width: 100%;
  min-height: 96px;
  padding: 16px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.metric:hover {
  border-color: var(--accent);
  background: #eef7f5;
  color: var(--text);
}

.metric:focus-visible {
  outline: 3px solid rgb(15 118 110 / 25%);
  outline-offset: 2px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input {
  flex: 1 1 220px;
  max-width: 320px;
}

.toolbar select {
  flex: 0 1 190px;
}

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

.table-wrap {
  overflow: auto;
}

.detail {
  padding: 16px;
}

.detail h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stack {
  display: grid;
  gap: 12px;
}

.action-area {
  margin-top: 18px;
}

.action-area + .action-area {
  margin-top: 22px;
}

.action-area:not(.compact) > button {
  min-height: 46px;
}

.stack.action-area > button {
  width: 100%;
}

.line-editor {
  display: grid;
  grid-template-columns: 1fr 90px 110px auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 20px;
}

.state-actions {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: #eef2f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.state.new {
  background: #e8f5f1;
  color: var(--accent-strong);
}

.state.processing {
  background: #fff1d6;
  color: var(--warning);
}

.state.processed {
  background: #e8f4ec;
  color: var(--ok);
}

.state.cancelled {
  background: #fdebea;
  color: var(--danger);
}

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

.empty-row {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 0;
}

tr.is-selected td {
  background: #eef7f5;
}

@media (max-width: 980px) {
  .shell,
  .split,
  .form-grid,
  .line-editor {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
  }

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar input,
  .toolbar select {
    max-width: none;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 16px;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }
}
