:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --bg-soft: #e8edf2;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-raised: #fbfcfd;
  --line: #d7dee8;
  --line-soft: #e8edf3;
  --text: #101828;
  --muted: #667085;
  --subtle: #98a2b3;
  --accent: #0f766e;
  --accent-strong: #0b5c56;
  --accent-soft: #d9f0ec;
  --info: #315caa;
  --info-soft: #e4ebfb;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warn: #a15c07;
  --focus: rgba(15, 118, 110, 0.24);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 18px 45px rgba(16, 24, 40, 0.08);
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, 0.05);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101418;
  --bg-soft: #151b22;
  --panel: rgba(24, 31, 39, 0.9);
  --panel-solid: #171e26;
  --panel-raised: #1d2630;
  --line: #2d3a47;
  --line-soft: #25313d;
  --text: #edf2f7;
  --muted: #a7b2c0;
  --subtle: #7f8b99;
  --accent: #2dd4bf;
  --accent-strong: #6ee7d8;
  --accent-soft: rgba(45, 212, 191, 0.13);
  --info: #8bb4ff;
  --info-soft: rgba(96, 165, 250, 0.14);
  --danger: #ff8a80;
  --danger-soft: rgba(255, 138, 128, 0.13);
  --warn: #f7b955;
  --focus: rgba(45, 212, 191, 0.22);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.32), 0 20px 55px rgba(0, 0, 0, 0.36);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, var(--bg-soft) 0, var(--bg) 320px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

.shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.controls,
article,
.kpis > div,
.auth-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 20px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; font-weight: 760; line-height: 1.15; }
h2 { font-size: 15px; font-weight: 740; line-height: 1.25; }
p, label, .section-head span { color: var(--muted); }

.topbar p,
.auth-panel p {
  margin-top: 5px;
}

.status-strip,
.checks,
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 24%, transparent);
}

.controls {
  margin-top: 16px;
  padding: 16px;
  display: grid;
  grid-template-columns: 160px 130px 220px minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: end;
}

.controls.notification-controls {
  grid-template-columns: minmax(240px, 1fr) auto;
}

.field-group,
.admin-form label,
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-group.flags {
  gap: 9px;
  align-self: center;
}

.checks label,
.field-group.flags label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

input[type="date"],
input[type="time"],
input[type="text"],
input[type="email"],
input[type="password"] {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--text);
  background: var(--panel-solid);
  outline: none;
  box-shadow: var(--shadow-soft);
}

input[type="date"]:focus,
input[type="time"]:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  accent-color: var(--accent);
}

button {
  height: 40px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 740;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

:root[data-theme="dark"] button {
  color: #06211e;
}

button:hover:not(:disabled) {
  filter: brightness(0.97);
}

button.secondary,
button.icon-button {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

button.small,
button.icon-button {
  height: 32px;
  padding: 0 11px;
}

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

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.kpis > div {
  min-height: 92px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}

.kpis strong {
  font-size: 32px;
  line-height: 1;
}

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

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

.grid.bottom {
  grid-template-columns: minmax(0, 1.5fr) minmax(380px, 0.8fr);
}

.grid.analytics-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, 0.8fr);
}

article {
  min-width: 0;
  overflow: hidden;
}

.section-head {
  min-height: 52px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--panel-raised) 72%, transparent);
}

.table-wrap {
  overflow: auto;
  max-height: 460px;
}

.table-wrap.compact {
  max-height: 260px;
}

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

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

th {
  position: sticky;
  top: 0;
  background: var(--panel-raised);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  z-index: 1;
}

td {
  color: var(--text);
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--accent-soft) 42%, transparent);
}

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.reason-list {
  padding: 12px 16px 18px;
  display: grid;
  gap: 8px;
}

.reason {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 0;
}

.reason strong {
  color: var(--info);
}

.health-block {
  display: grid;
  gap: 5px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.health-block strong {
  color: var(--text);
}

.health-block span {
  color: var(--muted);
}

pre {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  max-height: 460px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  background: var(--panel-raised);
}

.admin-form,
.auth-form {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.admin-form label,
.auth-form label {
  color: var(--muted);
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-shell {
  width: min(440px, 100%);
}

.auth-panel {
  overflow: hidden;
}

.auth-head {
  padding: 20px 18px 4px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.auth-panel h1 {
  font-size: 24px;
}

@media (max-width: 1050px) {
  .controls,
  .grid,
  .grid.bottom,
  .kpis {
    grid-template-columns: 1fr;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .status-strip,
  .actions {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 14px;
  }
  .topbar,
  .controls,
  .kpis > div {
    padding: 14px;
  }
  h1 {
    font-size: 21px;
  }
  .actions button {
    flex: 1 1 160px;
  }
  th, td {
    padding: 10px;
  }
}
