:root {
  color-scheme: light;
  --page: #f4f6f5;
  --surface: #ffffff;
  --surface-muted: #edf1ef;
  --line: #d4dbd7;
  --line-strong: #bac5bf;
  --ink: #17211d;
  --muted: #62706a;
  --accent: #087a65;
  --accent-dark: #065c4d;
  --accent-soft: #dff4eb;
  --danger: #b42318;
  --danger-soft: #fee8e7;
  --warning: #a66000;
  --warning-soft: #fff1d6;
  --success: #087a65;
  --success-soft: #dff4eb;
  --shadow: 0 12px 30px rgba(23, 33, 29, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-size: 14px;
  line-height: 1.45;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--surface);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(8, 122, 101, 0.24);
  outline-offset: 1px;
}

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

label > input,
label > select,
label > textarea {
  color: var(--ink);
  font-weight: 400;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--surface-muted);
}

.auth-panel {
  display: grid;
  width: min(100%, 390px);
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 720;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 760;
}

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 5px;
  color: #ffffff;
  background: var(--accent);
  font-size: 15px;
}

.form-error {
  min-height: 20px;
  margin: -8px 0 0;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar-actions,
.toolbar,
.action-row,
.selection-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.application-layout {
  display: grid;
  grid-template-columns: 202px minmax(0, 1fr);
  min-height: calc(100vh - 60px);
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: #edf1ef;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.nav-item:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}

.nav-item.is-active {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.content {
  min-width: 0;
  padding: 28px;
}

.view {
  width: min(100%, 1320px);
  margin: 0 auto;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.view-title {
  margin: 0;
  font-size: 23px;
  line-height: 1.15;
  font-weight: 760;
}

.view-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 12px;
  color: var(--ink);
  background: var(--surface-muted);
  font-weight: 680;
  white-space: nowrap;
}

.button:hover {
  background: #dfe7e2;
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
}

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

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

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

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

.button-full {
  width: 100%;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.metric {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.metric dt {
  color: var(--muted);
  font-weight: 650;
}

.metric dd {
  margin: 7px 0 0;
  font-size: 25px;
  font-weight: 760;
}

.metric dd.metric-date {
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.5;
}

.section-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 730;
}

.data-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

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

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

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

th {
  color: var(--muted);
  background: #fafcfb;
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fbfdfc;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.table-actions .button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.cell-primary {
  font-weight: 700;
}

.cell-secondary {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 720;
  white-space: nowrap;
}

.status-success {
  color: var(--success);
  background: var(--success-soft);
}

.status-failure {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-muted {
  color: var(--muted);
  background: var(--surface-muted);
}

.selection-toolbar {
  justify-content: space-between;
  min-height: 54px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.selection-toolbar select {
  width: min(260px, 100%);
}

.stacked-form {
  display: grid;
  gap: 20px;
  width: min(100%, 850px);
}

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

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

.field-span-full {
  grid-column: 1 / -1;
}

.check-label {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 650;
}

.check-label input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.form-section {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.form-section h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.empty-state {
  padding: 42px 20px;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(620px, calc(100vw - 28px));
  max-height: min(800px, calc(100vh - 28px));
  margin: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(23, 33, 29, 0.38);
}

.modal-content {
  display: grid;
  max-height: inherit;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

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

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

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  overflow-y: auto;
  padding: 18px;
}

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

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

.icon-close {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-size: 21px;
  line-height: 1;
}

.icon-close:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  display: grid;
  width: min(360px, calc(100vw - 40px));
  gap: 8px;
}

.toast {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 5px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(23, 33, 29, 0.11);
}

.toast.is-error {
  border-left-color: var(--danger);
}

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

.nowrap {
  white-space: nowrap;
}

@media (max-width: 920px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: 54px;
    padding: 0 14px;
  }

  .application-layout {
    display: block;
  }

  .sidebar {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .content {
    padding: 20px 14px;
  }

  .view-header {
    display: grid;
  }

  .metric-grid,
  .field-grid,
  .field-grid.triple {
    grid-template-columns: 1fr;
  }

  .selection-toolbar {
    align-items: stretch;
  }

  .table-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 460px) {
  .topbar-actions .button:first-child {
    display: none;
  }

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

  .view-title {
    font-size: 21px;
  }
}
