:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1a1d23;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 1rem; }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a {
  padding: .5rem .85rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: #eef2ff; color: var(--primary); }
.topbar .user { color: var(--muted); font-size: .85rem; }

.container { max-width: 1040px; margin: 1.5rem auto; padding: 0 1.25rem; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.page-head h1 { font-size: 1.4rem; margin: 0; }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }

/* ---- cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.card h3 { margin: 0 0 .15rem; font-size: 1rem; }
.card .sub { color: var(--muted); font-size: .8rem; }
.card .details { margin: .75rem 0; font-size: .85rem; color: var(--muted); }
.card .details strong { color: var(--text); font-weight: 600; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.card-unassigned { border-color: var(--amber); border-left-width: 3px; }

/* ---- badges ---- */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  color: #fff;
}
.badge-active { background: var(--green); }
.badge-inactive { background: var(--red); }
.badge-connected { background: var(--green); }
.badge-disconnected { background: var(--red); }

/* ---- limit bar ---- */
.limit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
}
.limit-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: .6rem; }
.limit-track { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.limit-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.limit-fill.full { background: var(--red); }
.limit-note { color: var(--muted); font-size: .82rem; margin: .5rem 0 0; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
td input[type="number"] { width: 4rem; padding: .3rem .4rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

/* ---- forms ---- */
.field { margin-bottom: .85rem; }
.field label { display: block; font-weight: 500; margin-bottom: .3rem; font-size: .85rem; }
.field input, .field select {
  width: 100%;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
}

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.modal h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.qr-box { display: flex; justify-content: center; margin: 1rem 0; }
.qr-box img { width: 260px; height: 260px; border: 1px solid var(--border); border-radius: 8px; }
.qr-status { display: flex; align-items: center; gap: .5rem; justify-content: center; color: var(--muted); font-size: .9rem; }

/* ---- misc ---- */
.banner {
  display: flex; gap: .6rem; align-items: center;
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .88rem;
}
.banner-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 2rem; width: 100%; max-width: 360px; }
.login-box h1 { margin: 0 0 1.25rem; font-size: 1.3rem; text-align: center; }
.form-error { color: var(--red); font-size: .85rem; margin-bottom: .75rem; }
.muted { color: var(--muted); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar select { padding: .35rem .5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); }
.pager { display: flex; gap: .5rem; justify-content: center; margin-top: 1rem; }
