:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --ink: #14181f;
  --muted: #626b78;
  --line: #d9dee5;
  --surface: #ffffff;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --danger: #b91c1c;
  --good: #15803d;
  --shadow: 0 18px 45px rgba(20, 24, 31, 0.07);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover {
  border-color: #aab4c0;
}

button:active {
  transform: translateY(1px);
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  width: min(280px, 100%);
}

.shell {
  display: grid;
  grid-template-columns: 72px 1fr;
  min-height: 100dvh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100dvh;
  border-right: 1px solid var(--line);
  background: #eef1f4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  padding: 18px 12px;
}

.brand-mark,
.nav-item {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 750;
}

.brand-mark {
  background: var(--ink);
  color: #fff;
  letter-spacing: 0;
}

.rail nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  color: var(--muted);
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 8px 22px rgba(20, 24, 31, 0.08);
}

.workspace {
  padding: 28px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.95;
  letter-spacing: 0;
  max-width: 760px;
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 0;
  letter-spacing: 0;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--accent);
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(20, 24, 31, 0.06);
}

.live-indicator span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.12);
}

.live-indicator strong {
  font-size: 0.9rem;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  line-height: 1;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.branch-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.branch-form input {
  width: min(180px, 100%);
}

.branch-list,
.device-list,
.attendance-list,
.queue-list {
  min-height: 180px;
}

.row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(4, minmax(70px, 110px));
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row.compact {
  grid-template-columns: minmax(170px, 1fr) minmax(80px, 120px) minmax(92px, 140px);
}

.row.branch-row {
  grid-template-columns: minmax(260px, 1.5fr) repeat(4, minmax(82px, 0.35fr));
  align-items: start;
  gap: 14px 18px;
  padding: 16px 18px;
}

.row.command {
  grid-template-columns: minmax(160px, 1fr) minmax(90px, 140px) minmax(120px, 1fr) minmax(100px, 140px);
}

.primary {
  font-weight: 760;
  overflow-wrap: anywhere;
}

.secondary {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.pill {
  justify-self: start;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 750;
  background: #edf2f7;
  color: #334155;
}

.pill.online,
.pill.completed,
.pill.processed,
.pill.finished {
  background: #dcfce7;
  color: var(--good);
}

.pill.offline,
.pill.failed,
.pill.invalid {
  background: #fee2e2;
  color: var(--danger);
}

.pill.queued,
.pill.sent,
.pill.retry,
.pill.running {
  background: #fef3c7;
  color: var(--warn);
}

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

.branch-devices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.branch-devices span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 8px;
}

.branch-devices button {
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.72rem;
  border-color: #fecaca;
  background: #fff;
  color: var(--danger);
}

.branch-stat {
  min-width: 0;
}

.branch-stat strong {
  display: block;
  font-size: 1.05rem;
  line-height: 1.1;
}

.branch-tools {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 10px 14px;
  align-items: center;
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid #eef1f4;
}

.assign-device {
  display: grid;
  grid-template-columns: minmax(240px, 420px) auto;
  gap: 8px;
  align-items: center;
  justify-content: start;
  min-width: 0;
}

.branch-device-select {
  min-width: 220px;
}

.assign-device select,
.sync-controls select {
  width: 100%;
}

.sync-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  justify-content: flex-end;
  min-width: 360px;
}

.branch-sync-scope {
  width: auto;
  flex: 0 0 136px;
  min-width: 136px;
}

.force-entry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.force-entry input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.sync-message {
  grid-column: 1 / -1;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  background: #eef1f4;
  color: var(--muted);
}

.sync-message.ok {
  background: #dcfce7;
  color: var(--good);
}

.sync-message.warn {
  background: #fef3c7;
  color: var(--warn);
}

.sync-message.bad {
  background: #fee2e2;
  color: var(--danger);
}

.device-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.empty,
.error {
  padding: 34px 18px;
  color: var(--muted);
}

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

.skeleton:empty {
  position: relative;
  overflow: hidden;
}

.skeleton:empty::before {
  content: "";
  display: block;
  height: 180px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent),
    repeating-linear-gradient(#eef1f4 0 18px, transparent 18px 46px);
  background-size: 220px 100%, 100% 100%;
  animation: shimmer 1.3s infinite;
}

@keyframes shimmer {
  from { background-position: -220px 0, 0 0; }
  to { background-position: calc(100% + 220px) 0, 0 0; }
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail nav {
    display: flex;
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

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

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

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

  .row,
  .row.compact,
  .row.command {
    grid-template-columns: 1fr;
  }

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

  .row.branch-row > :first-child,
  .branch-tools {
    grid-column: 1 / -1;
  }

  .branch-tools {
    grid-template-columns: 1fr;
  }

  .sync-controls {
    justify-content: flex-start;
    min-width: 0;
  }
}

@media (max-width: 540px) {
  input,
  select {
    width: 100%;
  }

  .branch-form,
  .assign-device {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .row.branch-row {
    grid-template-columns: 1fr;
  }

  .branch-device-select,
  .branch-sync-scope {
    min-width: 0;
  }

  .sync-controls {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
}
