:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #18202a;
  --muted: #697586;
  --line: #d9dee7;
  --primary: #146c94;
  --primary-dark: #0d526f;
  --danger: #a83232;
  --ok: #2f7d52;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
h1 { margin: 0 0 18px; font-size: 28px; }
h2 { margin: 0 0 14px; font-size: 20px; }
h3 { margin: 0 0 8px; font-size: 17px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; color: var(--text); }
.nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  background: #e9eef3;
  border-bottom: 1px solid var(--line);
}
.nav a {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.page { width: min(1180px, 100%); margin: 0 auto; padding: 20px 16px 60px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric, .panel, .small-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric { padding: 16px; }
.metric span { display: block; color: var(--muted); font-size: 14px; }
.metric strong { display: block; margin-top: 8px; font-size: 24px; }
.panel { padding: 16px; margin: 0 0 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.small-card { padding: 14px; }

.form, .row-form, .item-form {
  display: grid;
  gap: 12px;
}
.row-form { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
.item-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
label { display: grid; gap: 6px; font-weight: 650; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
textarea { min-height: 100px; resize: vertical; }
button {
  min-height: 42px;
  padding: 9px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }
.ghost { background: #e8edf2; color: var(--text); }
.danger { background: var(--danger); }
.alert {
  padding: 10px 12px;
  border-radius: 6px;
  background: #ffe7e7;
  color: #7d1f1f;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--surface);
}
th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; }
.result {
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  background: #111827;
  color: #e5e7eb;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
}
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-panel {
  width: min(420px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pairing-panel { text-align: center; }
.pairing-qr {
  display: block;
  width: min(520px, 100%);
  aspect-ratio: 1;
  object-fit: contain;
  margin: 16px auto;
  background: white;
  border: 1px solid var(--line);
}
.muted { color: var(--muted); }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .page { padding: 16px 10px 48px; }
  h1 { font-size: 24px; }
  .metric strong { font-size: 20px; }
  .panel { padding: 12px; }
}
