:root {
  --ink: #182124;
  --muted: #637071;
  --line: #dce4e1;
  --paper: #ffffff;
  --bg: #f5f7f6;
  --primary: #12343b;
  --primary-2: #1d5b63;
  --accent: #f4d35e;
  --ok: #20745a;
  --warn: #a66b00;
  --bad: #b43b42;
  --soft-ok: #e9f5ef;
  --soft-warn: #fff4d6;
  --soft-bad: #fdecee;
  font-family: Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(18, 52, 59, 0.07), transparent 220px),
    var(--bg);
}

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

button {
  min-height: 42px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-shell {
  min-height: 100vh;
}

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

.boot-screen {
  gap: 16px;
  grid-auto-flow: column;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-row.compact {
  gap: 10px;
  min-width: 220px;
}

.brand-row.compact span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--primary);
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 6px;
  font-size: 26px;
}

h2 {
  margin-bottom: 5px;
  font-size: 24px;
}

h3 {
  margin-bottom: 14px;
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.login-panel,
.setup-panel,
.form-panel,
.info-panel,
.metric,
.empty-box {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(24, 33, 36, 0.07);
}

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

.setup-panel {
  width: min(100%, 720px);
}

.steps {
  margin: 22px 0;
  padding-left: 24px;
  color: var(--ink);
  line-height: 1.8;
}

code {
  padding: 2px 6px;
  border-radius: 4px;
  background: #eef2f2;
}

.warning-box,
.notice-box,
.pending-box {
  margin: 18px 0;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.5;
}

.warning-box,
.pending-box {
  border: 1px solid #f0d48d;
  background: var(--soft-warn);
  color: #6f4a00;
}

.notice-box {
  border: 1px solid #bdd8cf;
  background: var(--soft-ok);
  color: #164f3d;
}

.device-note {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(29, 91, 99, 0.12);
}

.primary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

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

.primary-btn:hover {
  background: #0d282e;
}

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

.ghost-btn:hover {
  border-color: var(--primary-2);
}

.small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.nav-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 9px 12px;
  min-height: 38px;
  cursor: pointer;
}

.nav-tabs button.active {
  background: var(--primary);
  color: #fff;
}

.main-view {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head p {
  margin-bottom: 0;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--line);
  border: 1px solid var(--line);
  margin-bottom: 16px;
}

.status-band > div {
  background: #fff;
  padding: 18px;
}

.status-band span,
.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.status-band strong,
.metric strong {
  font-size: 24px;
}

.clock-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.clock-btn {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fff;
  text-align: left;
  padding: 22px;
  cursor: pointer;
}

.clock-btn span {
  display: block;
  font-size: 18px;
  margin-bottom: 18px;
}

.clock-btn strong {
  display: block;
  font-size: 42px;
  letter-spacing: 0;
}

.clock-btn.in {
  background: linear-gradient(135deg, #20745a, #12343b);
}

.clock-btn.out {
  background: linear-gradient(135deg, #a6533f, #6b2b3a);
}

.info-grid,
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.metric-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric,
.info-panel {
  padding: 16px;
}

dl {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.toolbar-row label {
  width: min(100%, 220px);
}

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

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

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

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

th {
  background: #f1f5f3;
  color: #3f4b4d;
  font-size: 13px;
  font-weight: 700;
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

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

.badge.warn {
  color: var(--warn);
  background: var(--soft-warn);
}

.badge.bad {
  color: var(--bad);
  background: var(--soft-bad);
}

.badge.muted {
  color: var(--muted);
  background: #eef2f2;
}

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

.form-panel {
  padding: 18px;
}

.form-note {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
}

.form-panel.wide {
  width: min(100%, 820px);
}

.form-panel .primary-btn,
.form-panel .ghost-btn {
  margin-top: 14px;
}

.import-panel {
  margin-top: 18px;
  box-shadow: none;
}

.face-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.face-item {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.face-item.inactive {
  opacity: 0.55;
}

.face-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #eef2f2;
}

.face-item small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.empty-box {
  padding: 20px;
  color: var(--muted);
}

.busy-layer {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  align-content: center;
  background: rgba(255, 255, 255, 0.76);
  z-index: 50;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 4px solid #c9d4d2;
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

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

@media (max-width: 880px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .nav-tabs {
    grid-column: 1 / -1;
    order: 3;
    padding-top: 4px;
  }

  .main-view {
    padding: 16px;
  }

  .metric-grid,
  .info-grid,
  .split-layout {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .login-layout,
  .setup-layout {
    padding: 14px;
    place-items: stretch;
    align-items: center;
  }

  .login-panel,
  .setup-panel {
    padding: 20px;
  }

  .form-grid,
  .status-band,
  .clock-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .page-head {
    display: grid;
  }

  .clock-btn {
    min-height: 122px;
  }

  .clock-btn strong {
    font-size: 36px;
  }

  dl {
    grid-template-columns: 1fr;
  }
}
