:root {
  --page: #f6f7f4;
  --panel: #ffffff;
  --line: #cfd8d2;
  --line-strong: #a9b8b0;
  --text: #1f2a24;
  --muted: #637168;
  --brand: #0e6f5c;
  --danger: #b42318;
  --warning: #8a6116;
  --success: #137a36;
  --focus: rgba(14, 111, 92, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
a.button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

button.primary,
a.button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

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

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

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text);
  background: #fff;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

label {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
  margin-bottom: 5px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}

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

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  background: #edf1ed;
}

.tbody-header td {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  font-weight: 700;
  background: #edf1ed;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.sidebar {
  background: #29322c;
  color: #f4faf6;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-block {
  display: grid;
  gap: 3px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: #e2b86b;
  color: #29322c;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-name {
  font-weight: 750;
  margin-top: 5px;
}

.brand-sub {
  color: #c7d4cc;
  font-size: 0.8rem;
}

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

.nav a {
  color: #e9f0eb;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 6px;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.session-box {
  margin-top: auto;
  color: #d8e2dc;
  font-size: 0.85rem;
  display: grid;
  gap: 10px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 58px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 22px;
}

.content {
  padding: 22px;
  width: 100%;
  max-width: 1380px;
}

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

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-panel h1,
.page-title h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.25;
}

.login-panel p,
.page-title p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  justify-content: space-between;
  margin: 18px 0 14px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(140px, 180px) minmax(140px, 180px) auto;
  gap: 10px;
  align-items: end;
}

.table-wrap,
.panel,
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.panel {
  padding: 16px;
}

.panel + .panel {
  margin-top: 14px;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #f2f5f2;
}

.page-chip {
  min-width: 38px;
  padding-inline: 8px;
}

.page-chip.active {
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.79rem;
  font-weight: 700;
  background: #e8ece8;
  color: var(--muted);
  margin: 2px;
}

.badge.active,
.badge.current,
.badge.open {
  background: #e5f4e9;
  color: var(--success);
}

.badge.inactive,
.badge.blocked,
.badge.past-due {
  background: #fdebea;
  color: var(--danger);
}

.badge.scenario {
  background: #fff0d6;
  color: var(--warning);
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.95fr) minmax(420px, 1.4fr);
  gap: 16px;
  align-items: start;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr;
  border-top: 1px solid var(--line);
}

.field-grid .label,
.field-grid .value {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.field-grid .label {
  color: var(--muted);
  font-weight: 700;
}

.field-grid .value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.split-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.inline-edit {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.toggle-title {
  font-weight: 750;
}

.toggle-help {
  color: var(--muted);
  display: block;
  font-size: 0.86rem;
  margin-top: 3px;
}

.skeleton {
  min-height: 44px;
  border-radius: 6px;
  background: linear-gradient(90deg, #edf1ee, #f8faf8, #edf1ee);
  background-size: 220% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  to {
    background-position-x: -220%;
  }
}

.notice {
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--brand);
  border-radius: 6px;
  background: #f7fbf8;
  color: var(--text);
  margin: 12px 0;
}

.notice.warning {
  border-left-color: var(--warning);
}

.notice.danger {
  border-left-color: var(--danger);
}

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

.error-text {
  color: var(--danger);
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(25, 31, 27, 0.5);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
}

.modal-header,
.modal-footer {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-body {
  padding: 16px;
}

.modal-footer {
  border-top: 1px solid var(--line);
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 60;
}

.toast {
  background: #202a24;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 230px;
  box-shadow: 0 10px 24px rgba(20, 26, 22, 0.22);
}

.toast.error {
  background: var(--danger);
}

.code-block {
  white-space: pre-wrap;
  overflow: auto;
  padding: 12px;
  background: #222a25;
  color: #e7f2ea;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

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

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

  .detail-layout,
  .inline-edit,
  .filters {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 16px;
  }
}
