:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --ink: #111827;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #d9deea;
  --line-soft: #e8ecf5;
  --blue: #1747d4;
  --blue-soft: #eef3ff;
  --cyan: #16b8c7;
  --green: #0f8f61;
  --green-soft: #eaf7f1;
  --amber: #a15c00;
  --amber-soft: #fff5e6;
  --red: #c13333;
  --red-soft: #fff0f0;
  --sidebar: #071024;
  --sidebar-soft: #111b31;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-screen[hidden] {
  display: none;
}

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

.login-panel .brand {
  margin: -4px -4px 18px;
  padding: 4px 4px 18px;
  border-bottom-color: var(--line-soft);
  color: var(--ink);
}

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

.login-panel .brand-mark {
  border-color: var(--line);
  background: var(--blue-soft);
  color: var(--blue);
}

.login-error {
  min-height: 20px;
  margin-top: 10px;
  color: var(--red);
  font-size: 13px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 16px;
  background: var(--sidebar);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: #10214a;
  color: #63eff6;
  font-size: 12px;
  font-weight: 700;
}

.brand-title {
  font-size: 15px;
  font-weight: 650;
}

.brand-subtitle,
.mini-label,
.eyebrow,
.panel-kicker {
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-subtitle {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.52);
}

.nav-list {
  display: grid;
  gap: 4px;
  margin-top: 20px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.68);
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--sidebar-soft);
  color: #fff;
}

.nav-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: #63eff6;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 8px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.env-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 12px;
}

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

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

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 650;
}

h2 {
  margin-top: 4px;
  font-size: 17px;
  font-weight: 650;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 320px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.primary-button,
.secondary-button,
.icon-button,
.text-button,
.filter,
.segmented button {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  min-height: 40px;
  padding: 0 14px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 650;
}

.secondary-button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 600;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  font-size: 18px;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  color: var(--blue);
  font-weight: 650;
}

.view {
  display: none;
}

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

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

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

.metric-card {
  padding: 16px;
}

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

.metric-value {
  margin-top: 12px;
  font-size: 30px;
  font-weight: 680;
}

.metric-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.7fr);
  gap: 16px;
  margin-top: 16px;
}

.overview-grid {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
}

.policies-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.55fr);
}

.panel {
  padding: 16px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.panel-header,
.toolbar,
.drawer-header,
.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbar {
  margin-bottom: 14px;
}

.segmented,
.filter-group {
  display: flex;
  gap: 6px;
}

.segmented {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented button,
.filter {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  color: var(--muted);
}

.segmented button.is-active,
.filter.is-active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--blue);
  font-weight: 650;
}

.chart {
  display: grid;
  grid-template-columns: repeat(var(--chart-bars, 24), minmax(7px, 1fr));
  align-items: end;
  gap: 7px;
  height: 220px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.chart-bar {
  position: relative;
  min-height: 18px;
  border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--cyan), var(--blue));
}

.chart-bar::after {
  content: attr(data-count);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 10px;
}

.channel-list,
.event-stack,
.workstation-mini,
.rules-list,
.audit-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.channel-row,
.mini-row,
.rule-row,
.audit-row,
.event-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
}

.channel-row,
.mini-row,
.rule-row,
.audit-row {
  padding: 12px;
}

.channel-top,
.rule-top,
.audit-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress {
  height: 7px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--blue-soft);
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.event-card {
  padding: 12px;
}

.event-card:hover,
.table-row:hover {
  background: var(--surface-soft);
}

.event-title,
.table-primary {
  font-weight: 650;
}

.event-meta,
.table-secondary,
.small-muted {
  color: var(--muted);
  font-size: 12px;
}

.severity,
.decision,
.state-pill,
.version-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
}

.severity.critical,
.decision.block {
  background: var(--red-soft);
  color: var(--red);
}

.severity.high,
.decision.mask {
  background: var(--amber-soft);
  color: var(--amber);
}

.severity.medium,
.decision.warn {
  background: var(--blue-soft);
  color: var(--blue);
}

.severity.low,
.decision.allow,
.state-pill.ok {
  background: var(--green-soft);
  color: var(--green);
}

.state-pill.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.state-pill.bad {
  background: var(--red-soft);
  color: var(--red);
}

.version-pill {
  background: var(--blue-soft);
  color: var(--blue);
}

.data-table {
  width: 100%;
}

.table-head,
.table-row {
  display: grid;
  align-items: center;
  gap: 12px;
  min-width: 920px;
  padding: 12px 16px;
}

.table-head {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-row {
  border-bottom: 1px solid var(--line-soft);
}

.events-table .table-head,
.events-table .table-row {
  grid-template-columns: 115px 1.2fr 0.8fr 0.75fr 0.7fr 0.7fr 92px;
}

.workstations-table .table-head,
.workstations-table .table-row {
  grid-template-columns: 1.1fr 0.8fr 0.65fr 0.75fr 0.9fr 0.75fr 120px;
}

.policies-table .table-head,
.policies-table .table-row {
  grid-template-columns: 1fr 0.7fr 0.7fr 0.75fr 112px;
}

.users-table .table-head,
.users-table .table-row {
  grid-template-columns: 1fr 0.8fr 0.7fr 0.75fr 140px;
  min-width: 780px;
}

.table-action {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue);
  font-weight: 650;
}

.rule-builder {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.rule-builder label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.stack-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.stack-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.stack-form input,
.stack-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.stack-form input {
  height: 40px;
  padding: 0 10px;
}

.stack-form textarea {
  min-height: 132px;
  padding: 10px;
  resize: vertical;
}

select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.snapshot-box {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.credential-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--amber);
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--ink);
}

.credential-box code {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--amber);
  font-weight: 700;
}

.readonly-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.version-grid {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.snapshot-row {
  display: grid;
  gap: 5px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.snapshot-row span {
  color: var(--muted);
  font-size: 12px;
}

.full-width {
  width: 100%;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.warn {
  background: var(--amber);
}

.status-dot.bad {
  background: var(--red);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 19;
  display: none;
  background: rgba(7, 16, 36, 0.22);
}

.drawer-backdrop.is-open {
  display: block;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(460px, 100vw);
  height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -24px 0 70px rgba(15, 23, 42, 0.16);
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-body {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.detail-block {
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-soft);
}

.detail-block span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(7, 16, 36, 0.5);
}

.modal-backdrop.is-open {
  display: grid;
}

.modal {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-body,
.modal-actions {
  padding: 16px;
}

.modal-body {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  min-width: 280px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sidebar);
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

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

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  .brand-title,
  .brand-subtitle,
  .nav-item span:last-child,
  .sidebar-footer {
    display: none;
  }

  .brand {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
  }

  .metrics-grid,
  .content-grid,
  .overview-grid,
  .policies-grid {
    grid-template-columns: 1fr 1fr;
  }

  .wide-panel,
  .policy-editor {
    grid-column: 1 / -1;
  }

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .brand {
    justify-content: flex-start;
    padding-bottom: 12px;
  }

  .brand-title,
  .brand-subtitle,
  .nav-item span:last-child {
    display: block;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    overflow-x: auto;
  }

  .nav-item {
    justify-content: center;
    min-width: 96px;
  }

  .main {
    padding: 16px;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .search {
    width: 100%;
  }

  .metrics-grid,
  .content-grid,
  .overview-grid,
  .policies-grid,
  .rule-builder {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .filter-group {
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }

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