:root {
  color-scheme: light dark;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eaf3f8;
  --text: #16212f;
  --muted: #5f6d7c;
  --line: #d8e0e8;
  --primary: #11665d;
  --primary-strong: #0b4e47;
  --accent: #a03d5b;
  --danger: #b42318;
  --ok: #16794f;
  --shadow: 0 16px 40px rgba(33, 43, 39, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1c2320;
    --surface-2: #202d29;
    --text: #ecf2ee;
    --muted: #aab8b1;
    --line: #33423d;
    --primary: #55b9aa;
    --primary-strong: #8fd8cd;
    --accent: #e1a357;
    --danger: #ff8c7d;
    --ok: #7dd5a8;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: var(--primary);
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.ghost {
  background: transparent;
}

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

.center,
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel,
.panel,
.item-card,
.detection,
.stat,
.setup,
.setup-step,
.guide {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.app-shell {
  width: min(1260px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

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

h1 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  margin-bottom: 0;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.tabs {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding-bottom: 12px;
}

.tabs button {
  flex: 0 0 auto;
}

.tabs .active {
  background: var(--surface-2);
  border-color: var(--primary);
  color: var(--primary-strong);
  font-weight: 700;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.status-strip span {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ok-text {
  color: var(--ok);
}

.danger-text {
  color: var(--danger);
}

.content {
  display: grid;
  gap: 18px;
}

.setup,
.guide {
  padding: 18px;
}

.setup-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.setup-step {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  padding: 14px;
}

.setup-step.done {
  background: var(--surface-2);
}

.step-number {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.guide {
  border-left: 5px solid var(--primary);
  box-shadow: none;
}

.guide p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat {
  padding: 16px;
}

.stat span,
label span,
small,
.hint,
.empty {
  color: var(--muted);
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.3rem;
  word-break: break-word;
}

.toolbar,
.button-row,
.section-title,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.section-title {
  justify-content: space-between;
}

.split {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 18px;
  align-items: start;
}

.split.wide {
  grid-template-columns: minmax(320px, 480px) 1fr;
}

.panel {
  padding: 18px;
}

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

.advanced summary {
  min-height: 36px;
  cursor: pointer;
  font-weight: 700;
}

.advanced[open] {
  display: grid;
  gap: 12px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

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

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

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

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

.form-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cards,
.detection-cards {
  display: grid;
  gap: 12px;
}

.item-card,
.detection {
  padding: 16px;
}

.item-card {
  display: grid;
  gap: 12px;
}

.detection {
  display: grid;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 2px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.badge.ok {
  color: var(--ok);
}

.badge.danger {
  color: var(--danger);
}

.notice {
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  background: var(--surface);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

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

th {
  background: var(--surface-2);
  white-space: nowrap;
}

td small {
  display: block;
  max-width: 420px;
  overflow-wrap: anywhere;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
}

.settings {
  max-width: 860px;
}

.switches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.loader {
  width: 36px;
  height: 36px;
  border: 4px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

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

  .split,
  .split.wide,
  .form-row.two {
    grid-template-columns: 1fr;
  }

  .toolbar button,
  .button-row button,
  .button-row .button {
    flex: 1 1 140px;
  }

  button,
  .button,
  input,
  select,
  textarea {
    min-height: 46px;
  }

  .setup-steps {
    grid-template-columns: 1fr;
  }
}
