:root {
  --green: #7cb83f;
  --green-dark: #5ea22c;
  --blue: #1f6fb2;
  --blue-dark: #14345c;
  --coral: #ef6a5f;
  --radius-pill: 999px;
  --radius-card: 14px;

  --bg: #f4f7f3;
  --surface: #ffffff;
  --text: #1c2733;
  --text-muted: #666666;
  --border: #e6e6e6;
  --input-bg: #ffffff;
  --input-border: #cccccc;
  --table-border: #eeeeee;
  --shadow: rgba(0, 0, 0, 0.08);

  --flash-error-bg: #fdeceb;
  --flash-error-text: #b3382c;
  --flash-success-bg: #eef7e6;
  --flash-success-text: #3f6b1e;

  --badge-active-bg: #eef7e6;
  --badge-active-text: #5ea22c;
  --badge-inactive-bg: #f2f2f2;
  --badge-inactive-text: #888888;

  --info-bg: #eaf3fb;
  --info-text: #14345c;

  --neutral-btn-bg: #e6e6e6;
  --neutral-btn-text: #1c2733;
}

:root[data-theme="dark"] {
  --bg: #12161f;
  --surface: #1b212e;
  --text: #e7ebf0;
  --text-muted: #a3adba;
  --border: #2b3242;
  --input-bg: #12161f;
  --input-border: #3a4356;
  --table-border: #2b3242;
  --shadow: rgba(0, 0, 0, 0.4);

  --flash-error-bg: #3a1f1e;
  --flash-error-text: #ff9c90;
  --flash-success-bg: #1f3320;
  --flash-success-text: #a4dc85;

  --badge-active-bg: #1f3320;
  --badge-active-text: #a4dc85;
  --badge-inactive-bg: #2b3242;
  --badge-inactive-text: #a3adba;

  --info-bg: #1a2c3d;
  --info-text: #a9d3f5;

  --neutral-btn-bg: #2b3242;
  --neutral-btn-text: #e7ebf0;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161f;
    --surface: #1b212e;
    --text: #e7ebf0;
    --text-muted: #a3adba;
    --border: #2b3242;
    --input-bg: #12161f;
    --input-border: #3a4356;
    --table-border: #2b3242;
    --shadow: rgba(0, 0, 0, 0.4);

    --flash-error-bg: #3a1f1e;
    --flash-error-text: #ff9c90;
    --flash-success-bg: #1f3320;
    --flash-success-text: #a4dc85;

    --badge-active-bg: #1f3320;
    --badge-active-text: #a4dc85;
    --badge-inactive-bg: #2b3242;
    --badge-inactive-text: #a3adba;

    --info-bg: #1a2c3d;
    --info-text: #a9d3f5;

    --neutral-btn-bg: #2b3242;
    --neutral-btn-text: #e7ebf0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--green);
  letter-spacing: 1px;
}

.brand span { color: var(--blue); }

.topbar nav {
  display: flex;
  align-items: center;
}

.topbar nav a {
  text-decoration: none;
  font-weight: 600;
  color: #ffffff;
  background: var(--blue);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  margin-left: 8px;
}

.topbar nav a.logout { background: var(--coral); }

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  padding: 0;
}
.theme-toggle:hover { background: var(--bg); }

.flash {
  max-width: 640px;
  margin: 16px auto 0;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 600;
}
.flash.error { background: var(--flash-error-bg); color: var(--flash-error-text); border: 1px solid var(--coral); }
.flash.success { background: var(--flash-success-bg); color: var(--flash-success-text); border: 1px solid var(--green); }

.hero-page {
  min-height: calc(100vh - 65px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a4f9c 0%, #2b7fa0 55%, #379a6e 100%);
  padding: 40px 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
  margin-top: 0;
  color: var(--blue-dark);
  font-size: 1.5rem;
}

:root[data-theme="dark"] .auth-card h1 { color: #7db4e8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-card h1 { color: #7db4e8; }
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
}
.field input,
.field select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--input-bg);
  color: var(--text);
}

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  font-weight: 700;
  padding: 11px 24px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--green); color: #ffffff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--blue); color: #ffffff; }
.btn-danger { background: var(--coral); color: #ffffff; }
.btn-neutral { background: var(--neutral-btn-bg); color: var(--neutral-btn-text); }
.btn-block { width: 100%; }

.auth-links {
  margin-top: 16px;
  text-align: center;
  font-size: 0.9rem;
}
.auth-links a { color: var(--blue); font-weight: 600; text-decoration: none; }

.page {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 { color: var(--blue-dark); margin: 0; }
:root[data-theme="dark"] .page-header h1 { color: #7db4e8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .page-header h1 { color: #7db4e8; }
}

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 18px var(--shadow);
  padding: 24px;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--table-border);
}
th { color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.active { background: var(--badge-active-bg); color: var(--badge-active-text); }
.badge.inactive { background: var(--badge-inactive-bg); color: var(--badge-inactive-text); }

.device-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 8px;
  vertical-align: middle;
}
.device-dot.registered { background: var(--badge-active-text); }
.device-dot.unregistered { background: var(--badge-inactive-text); }

.device-legend {
  display: flex;
  gap: 18px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.device-legend span { display: inline-flex; align-items: center; gap: 6px; }
.device-status-card { margin-top: 20px; }

.row-actions { display: flex; gap: 8px; }
.row-actions form { display: inline; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

.form-card { max-width: 480px; }

.password-field { position: relative; }
.password-field input { padding-right: 42px; }
.toggle-password {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 6px;
  line-height: 1;
}

.info-box {
  background: var(--info-bg);
  border: 1px solid var(--blue);
  border-radius: 10px;
  padding: 16px 20px;
  color: var(--info-text);
}

.download-card { text-align: center; max-width: 420px; }
.download-icon { font-size: 3rem; margin-bottom: 8px; }
.download-sub { color: var(--text-muted); margin-bottom: 24px; }
.download-note { color: var(--text-muted); font-size: 0.85rem; margin-top: 16px; }
.btn[disabled] { cursor: not-allowed; opacity: 0.7; }
