:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --sidebar: #07002f;
  --text: #171b34;
  --muted: #66708a;
  --line: #d8dfec;
  --line-soft: #edf1f7;
  --primary: #2351c6;
  --primary-dark: #1b3f9a;
  --ok: #16b987;
  --warn: #c65a19;
  --danger: #d53a52;
  --shadow: 0 1px 2px rgba(21, 33, 58, 0.06), 0 10px 28px rgba(21, 33, 58, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 96px;
  background: var(--sidebar);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 12px;
  z-index: 3;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--sidebar);
  background: #ffffff;
  font-weight: 900;
  font-size: 25px;
}

.nav {
  width: 100%;
  display: grid;
  gap: 12px;
  margin-top: 34px;
}

.nav-item {
  width: 100%;
  min-height: 60px;
  border: 0;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  display: grid;
  place-items: center;
  gap: 3px;
  cursor: pointer;
  text-decoration: none;
}

.nav-item span {
  font-size: 22px;
  line-height: 1;
}

.nav-item small {
  font-size: 11px;
}

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

.nav-item.active {
  box-shadow: inset 3px 0 0 #ffffff;
}

.nav-item[href*="panic"] {
  color: #ffd8df;
}

.nav-item[href*="panic"]:hover {
  background: rgba(213, 58, 82, 0.22);
}

.nav-item.bottom {
  margin-top: auto;
}

.shell {
  width: calc(100% - 96px);
  max-width: 1880px;
  margin-left: 96px;
  padding: 28px 28px 46px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 31px;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

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

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.status {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  color: #48516a;
  background: #fff;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
  font-family: inherit;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(35, 81, 198, 0.16);
}

button.primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 10px 22px rgba(35, 81, 198, 0.2);
}

button.secondary,
.icon-button,
button.warn,
button.danger {
  color: var(--text);
  border: 1px solid var(--line);
  background: #fff;
}

button.secondary:hover,
button.warn:hover,
button.danger:hover,
.icon-button:hover {
  background: #f8fafc;
  border-color: #cbd5e5;
}

button.danger {
  color: var(--danger);
  border-color: rgba(213, 58, 82, 0.28);
}

button.danger:hover {
  background: rgba(213, 58, 82, 0.08);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.login-empty,
.panel,
.metrics article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-empty {
  width: min(720px, 100%);
  min-height: 300px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 42px 34px;
  gap: 18px;
  margin: 34px auto 0;
}

.login-empty > div {
  max-width: 560px;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.metrics article {
  padding: 20px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.metrics article:hover,
.panel:hover {
  border-color: #cbd5e5;
}

.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.8fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  padding: 20px;
}

.panel.wide {
  min-width: 0;
}

.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.filter-input {
  width: min(280px, 42vw);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 14px;
  -webkit-overflow-scrolling: touch;
}

.compact {
  max-height: 260px;
  overflow: auto;
}

.compact-events {
  max-height: 386px;
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

td {
  font-size: 14px;
}

tbody tr {
  transition: background 160ms ease;
}

tbody tr:hover {
  background: #fbfcff;
}

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

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

.inline-fields {
  display: grid;
  grid-template-columns: 0.65fr 1.35fr;
  gap: 10px;
}

.input-action {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(35, 81, 198, 0.16);
  border-color: var(--primary);
}

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

.events {
  display: grid;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.event {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: #fff;
}

.event:last-child {
  border-bottom: 0;
}

.event strong {
  display: block;
  font-size: 14px;
  line-height: 1.35;
}

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

.compact-events .event {
  padding-block: 13px;
}

.empty-state {
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok {
  color: #087a5b;
  background: #dff8ef;
}

.pill.warn {
  color: #9a4a12;
  background: #fff1d6;
}

.pill.off {
  color: #667085;
  background: #eef2f7;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 16, 32, 0.44);
}

.modal[hidden],
[hidden] {
  display: none !important;
}

.modal-card {
  width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(21, 33, 58, 0.2);
  padding: 20px;
}

.modal-card.small {
  width: min(520px, 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

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

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 44px));
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: #fff;
  box-shadow: 0 12px 34px rgba(21, 33, 58, 0.16);
  font-size: 14px;
}

.toast[data-type="error"] {
  border-left-color: var(--danger);
}

@media (max-width: 1100px) {
  .dashboard-grid,
  .metrics,
  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .sidebar {
    inset: auto 0 0 0;
    width: 100%;
    height: calc(72px + env(safe-area-inset-bottom));
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand-mark {
    display: none;
  }

  .nav {
    width: auto;
    flex: 1;
    display: grid;
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    gap: 4px;
    margin-top: 0;
  }

  .nav-item,
  .nav-item.bottom {
    min-height: 54px;
    margin-top: 0;
    border-radius: 9px;
  }

  .nav-item.active {
    box-shadow: inset 0 3px 0 #ffffff;
  }

  .nav-item span {
    font-size: 19px;
  }

  .nav-item small {
    font-size: 10px;
  }

  .sidebar > .nav-item.bottom {
    width: 54px;
    flex: 0 0 54px;
    margin-left: 4px;
  }

  .shell {
    width: 100%;
    margin-left: 0;
    padding: 20px 16px 24px;
  }

  h1 {
    font-size: 26px;
  }

  h2 {
    font-size: 17px;
  }

  .topbar,
  .panel-title,
  .panel-actions,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    gap: 14px;
    margin-bottom: 16px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
  }

  .top-actions .status {
    grid-column: 1 / -1;
    justify-content: center;
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: center;
  }

  button,
  input,
  .status,
  .link-button {
    min-height: 44px;
  }

  .login-empty {
    width: 100%;
    min-height: 280px;
    margin-top: 20px;
    padding: 30px 22px;
  }

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

  .metrics article,
  .panel {
    padding: 14px;
  }

  .metrics strong {
    font-size: 26px;
  }

  .filter-input {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  table {
    border-collapse: separate;
    border-spacing: 0;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
  }

  tbody tr:hover {
    background: #fff;
  }

  td {
    display: grid;
    grid-template-columns: minmax(112px, 38%) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--line-soft);
    padding: 10px 12px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

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

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td.empty-state {
    display: block;
    border: 0;
    text-align: center;
  }

  td.empty-state::before {
    content: none;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .modal {
    align-items: end;
    padding: 12px;
  }

  .modal-card {
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: 12px;
    padding: 16px;
  }

  .modal-header {
    align-items: flex-start;
  }

  .input-action {
    grid-template-columns: 1fr;
  }

  .toast {
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 420px) {
  .shell {
    padding-inline: 10px;
  }

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

  .top-actions .icon-button {
    width: 100%;
  }

  .nav-item small {
    display: none;
  }

  .nav-item,
  .nav-item.bottom {
    min-height: 48px;
  }

  td {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .row-actions {
    grid-template-columns: 1fr;
  }
}
