:root {
  --ink: #16201c;
  --muted: #66736d;
  --line: #d9e0dc;
  --surface: #ffffff;
  --surface-soft: #f5f7f4;
  --teal: #0e6f68;
  --teal-dark: #084943;
  --coral: #bd4f38;
  --gold: #9b6f16;
  --green: #2f7d4f;
  --red: #a43434;
  --shadow: 0 16px 36px rgba(22, 32, 28, 0.09);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  color: #f8fbf8;
  background: #172622;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #172622;
  background: #f2c763;
  border-radius: 8px;
  font-weight: 800;
}

.brand-lockup strong,
.mode-panel strong {
  display: block;
  font-size: 15px;
}

.brand-lockup span,
.mode-panel span {
  display: block;
  margin-top: 2px;
  color: #b8c9c1;
  font-size: 13px;
}

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

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  color: #dbe7e2;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.mode-panel {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
}

.operator-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.operator-panel span {
  display: block;
  color: #b8c9c1;
  font-size: 12px;
}

.operator-panel strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: #f8fbf8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operator-panel button {
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 6px 9px;
  color: #172622;
  background: #dbe7e2;
  font-size: 12px;
  font-weight: 750;
}

.sidebar-secret {
  display: grid;
  gap: 7px;
  color: #d5e7df;
  font-size: 12px;
  font-weight: 750;
}

.sidebar-secret input {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0 10px;
  color: #f8fbf8;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 999px;
  background: #66d18f;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
}

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

h1 {
  max-width: 760px;
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

select,
input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
}

.topbar select {
  width: 150px;
}

.primary-button,
.secondary-button,
.danger-button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #ffffff;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
}

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

.secondary-button {
  background: var(--ink);
}

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

.link-button {
  min-height: 34px;
  color: var(--ink);
  background: #eef2ef;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

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

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

.metric-card {
  padding: 18px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--teal-dark);
  background: #dcefed;
  font-size: 12px;
  font-weight: 760;
}

.pill.success {
  color: #1f5d39;
  background: #ddf1e5;
}

.pill.muted {
  color: #57615d;
  background: #edf0ee;
}

.details-list {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 14px;
  margin: 0;
}

.details-list dt {
  color: var(--muted);
}

.details-list dd {
  margin: 0;
  font-weight: 680;
  overflow-wrap: anywhere;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.wide {
  grid-column: 1 / -1;
}

.target-list,
.event-list,
.report-list,
.admin-list,
.control-stack {
  display: grid;
  gap: 10px;
}

.target-list.spaced {
  margin-top: 14px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.admin-form.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
}

.admin-form button {
  align-self: end;
}

#admin-issued-key {
  min-height: 82px;
  margin: 12px 0 0;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  color: #e9f4ee;
  background: #16201c;
  font-size: 12px;
  line-height: 1.45;
}

.target-item,
.event-item,
.report-item,
.admin-item,
.gate-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.target-item strong,
.event-item strong,
.report-item strong,
.admin-item strong,
.gate-item strong {
  font-size: 14px;
}

.target-item span,
.event-item span,
.report-item span,
.admin-item span,
.gate-item span,
.control-stack p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.admin-item button {
  min-height: 30px;
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--ink);
  background: #e8ece9;
  font-weight: 750;
}

.admin-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.mini-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  background: #e8ece9;
  font-size: 12px;
  font-weight: 700;
}

.mini-pill.good {
  color: #1f5d39;
  background: #ddf1e5;
}

.mini-pill.warn {
  color: #7a4f10;
  background: #f4e8c8;
}

.doc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.doc-links a {
  color: var(--teal-dark);
  font-weight: 750;
  text-decoration: none;
}

.gate-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

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

.target-toggle input {
  width: 22px;
  min-height: 22px;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.inline-toggle input {
  width: 20px;
  min-height: 20px;
}

.text-danger {
  min-height: 34px;
  border: 1px solid rgba(164, 52, 52, 0.24);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--red);
  background: #fff7f5;
  font-weight: 750;
}

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

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segment {
  min-height: 40px;
  border: 0;
  color: var(--muted);
  background: #f8faf8;
  font-weight: 750;
}

.segment.active {
  color: #ffffff;
  background: var(--teal);
}

.result-panel pre {
  min-height: 260px;
  margin: 0;
  overflow: auto;
  border-radius: 8px;
  padding: 14px;
  color: #e9f4ee;
  background: #16201c;
  font-size: 13px;
  line-height: 1.5;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

#toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #172622;
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  display: grid;
  gap: 22px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  padding: 28px;
  background: #f8faf8;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

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

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

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

  .sidebar {
    position: static;
    padding: 18px;
  }

  .nav-list {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .mode-panel {
    margin-top: 0;
  }

  .metric-grid,
  .two-column,
  .gate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .main {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions,
  .topbar select,
  .topbar-actions button {
    width: 100%;
  }

  h1 {
    font-size: 24px;
  }

  .nav-list,
  .metric-grid,
  .two-column,
  .gate-grid,
  .admin-form,
  .admin-form.compact,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .details-list {
    grid-template-columns: 1fr;
  }
}
