:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #dde5f0;
  --text: #101827;
  --muted: #61708a;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --sidebar: #0b1020;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: #ffffff;
  padding: 28px 20px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 8px;
  display: inline-flex;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #9aa8c1;
  font-size: 13px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: #b9c4d6;
  cursor: pointer;
  padding: 12px 14px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #172033;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 34px;
}

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

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

.api-status {
  background: #fee2e2;
  border-radius: 999px;
  color: #991b1b;
  font-size: 12px;
  font-weight: 900;
  padding: 8px 11px;
}

.api-status.connected {
  background: #dcfce7;
  color: #166534;
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

.login-panel {
  display: grid;
  min-height: 65vh;
  place-items: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 440px;
  padding: 28px;
  width: 100%;
}

.login-card h2 {
  font-size: 24px;
  margin-bottom: 22px;
}

.form-message {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  padding-top: 10px;
}

.dashboard[hidden],
.login-panel[hidden] {
  display: none;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: 30px;
  margin-top: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace {
  display: grid;
  gap: 20px;
  grid-template-columns: 380px minmax(0, 1fr);
}

.ads-workspace {
  align-items: start;
}

.editor,
.list-panel,
.qr-panel,
.print-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.editor {
  padding: 22px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field span,
.check-field span {
  color: #263349;
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  height: 42px;
  outline: 0;
  padding: 0 12px;
  width: 100%;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.field.compact {
  margin: 18px 0 0;
}

.check-field {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.check-field input {
  height: 18px;
  width: 18px;
}

.primary-button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  height: 42px;
  padding: 0 16px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
  width: 100%;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: #eaf0ff;
  color: #1e3a8a;
}

.primary-button.small,
.ghost-button.small {
  width: auto;
}

.list-panel {
  min-width: 0;
  padding: 22px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  padding: 13px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 900;
}

.selected-row {
  background: #f8fbff;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  padding: 4px 9px;
}

.status-pill.enabled {
  background: #dcfce7;
  color: #166534;
}

.status-pill.disabled {
  background: #fee2e2;
  color: #991b1b;
}

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

.text-button {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  padding: 0;
}

.text-button.danger {
  color: var(--danger);
}

.mono {
  font-family: Menlo, Consolas, monospace;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qr-layout {
  display: grid;
  gap: 20px;
}

.qr-panel {
  align-items: stretch;
  display: grid;
  gap: 24px;
  grid-template-columns: 260px minmax(0, 1fr);
  padding: 22px;
}

.print-card {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 320px;
  padding: 22px;
  text-align: center;
}

.print-store {
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
  margin-bottom: 8px;
}

.print-card h2 {
  font-size: 24px;
  margin-bottom: 18px;
}

.print-hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
}

.qr-preview {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  height: 180px;
  justify-content: center;
  width: 180px;
}

#qrCanvas {
  background: #ffffff;
  height: 180px;
  image-rendering: pixelated;
  width: 180px;
}

.qr-detail h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.qr-detail p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.stats-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.8fr);
  margin-bottom: 20px;
}

.bars {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(7, minmax(48px, 1fr));
  min-height: 210px;
}

.bar-item {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: end;
}

.bar-stack {
  align-items: end;
  display: flex;
  gap: 4px;
  height: 150px;
}

.bar {
  border-radius: 5px 5px 0 0;
  display: block;
  width: 12px;
}

.bar.open {
  background: var(--accent);
}

.bar.success {
  background: var(--success);
}

.bar-item strong,
.bar-item span {
  font-size: 12px;
}

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

.reason-list {
  display: grid;
  gap: 10px;
}

.reason-item {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  padding: 12px;
}

.reason-item span {
  color: #263349;
  font-weight: 800;
}

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

.ad-summary div {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.ad-summary span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 800;
}

.ad-summary strong {
  display: block;
  font-size: 26px;
  margin-top: 8px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  background: #0f172a;
  border-radius: 8px;
  bottom: 24px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  left: 50%;
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 20;
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 1100px) {
  .app-shell,
  .workspace,
  .qr-panel,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

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

@media (max-width: 680px) {
  .main {
    padding: 22px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .metrics,
  .ad-summary {
    grid-template-columns: 1fr;
  }
}
