:root {
  --brand: oklch(0.52 0.2 15);
  --brand-hover: oklch(0.46 0.2 15);
  --bg: oklch(0.99 0 0);
  --sidebar: oklch(0.97 0.005 15);
  --surface: oklch(1 0 0);
  --ink: oklch(0.22 0.02 15);
  --muted: oklch(0.45 0.02 15);
  --border: oklch(0.9 0.005 15);
  --success: oklch(0.55 0.14 145);
  --danger: oklch(0.52 0.18 25);
  --chip-neutral: oklch(0.94 0.005 15);
  --chip-brand: oklch(0.93 0.03 15);
  --chip-success: oklch(0.93 0.04 145);
  --selected: oklch(0.96 0.02 15);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --topbar-h: 48px;
  --sidebar-w: 260px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
}

a:hover {
  color: var(--brand-hover);
}

/* ── App shell ── */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar__logo {
  display: block;
  height: 24px;
  width: auto;
}

.topbar__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
}

.sidebar__empty {
  padding: 16px 20px;
  margin: 0;
}

.sidebar-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.sidebar-item:hover {
  background: oklch(0.95 0.01 15);
}

.sidebar-item.is-selected {
  background: var(--selected);
}

.sidebar-item.is-inactive {
  opacity: 0.55;
}

.sidebar-item__name {
  flex: 1 1 100%;
  font-weight: 500;
  font-size: 13px;
  line-height: 1.35;
}

.sidebar-item__closed {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.main {
  padding: 28px 32px;
  overflow-y: auto;
}

/* ── Chips ── */

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip-neutral);
  color: var(--muted);
}

.chip--neutral {
  background: var(--chip-neutral);
  color: var(--muted);
}

.chip--brand {
  background: var(--chip-brand);
  color: var(--brand);
}

.chip--success {
  background: var(--chip-success);
  color: var(--success);
}

/* ── Detail ── */

.detail__header {
  margin-bottom: 16px;
}

.detail__title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.detail__title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.25;
  flex: 1 1 auto;
  min-width: 0;
}

.detail__header .detail__subtitle {
  margin-top: 4px;
}

.detail__subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.detail__warning {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: oklch(0.55 0.12 75);
}

.progress {
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress__bar {
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.detail__actions {
  margin-top: 28px;
}

.detail__closed-badge {
  margin-top: 24px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

/* ── Table ── */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.bindings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.bindings-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.bindings-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: oklch(0.98 0.003 15);
  border-bottom: 1px solid var(--border);
}

.bindings-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.bindings-table tbody tr:nth-child(even) {
  background: oklch(0.995 0.002 15);
}

.bindings-table tbody tr:last-child td {
  border-bottom: none;
}

.serial {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 12px;
  background: oklch(0.96 0.005 15);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn--primary {
  background: var(--brand);
  color: oklch(0.99 0 0);
  border-color: var(--brand);
}

.btn--primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: oklch(0.99 0 0);
}

.btn--secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}

.btn--secondary:hover {
  background: oklch(0.97 0.005 15);
  color: var(--ink);
}

.btn--danger {
  background: var(--surface);
  color: var(--danger);
  border-color: oklch(0.88 0.04 25);
}

.btn--danger:hover {
  background: oklch(0.97 0.02 25);
}

.btn--sm {
  padding: 6px 12px;
  font-size: 13px;
  flex-shrink: 0;
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  color: var(--ink);
  background: var(--bg);
}

.btn--block {
  width: 100%;
}

/* ── Auth / form pages ── */

.auth-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-layout__header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-layout__logo {
  display: inline-block;
  height: 28px;
  width: auto;
}

.auth-layout__tagline {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--muted);
}

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

.card__title {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 600;
}

.card__lead {
  margin: -8px 0 20px;
  font-size: 14px;
  color: var(--muted);
}

.card__footer {
  margin: 20px 0 0;
  text-align: center;
  font-size: 13px;
}

.link {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}

.link:hover {
  text-decoration: underline;
}

.form__field {
  margin-bottom: 16px;
}

.form__field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

.form__field input {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s ease;
}

.form__field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px oklch(0.52 0.2 15 / 0.12);
}

.form__error {
  margin: 0 0 16px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--danger);
  background: oklch(0.97 0.02 25);
  border-radius: 8px;
}

/* ── Created / QR ── */

.qr-block {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.qr-block__img {
  display: block;
  width: 240px;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.deep-link-box {
  margin-bottom: 16px;
}

.deep-link-box__input {
  width: 100%;
  padding: 10px 12px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.created-card__actions {
  display: flex;
  gap: 10px;
}

.created-card__actions .btn {
  flex: 1;
}

.copy-feedback {
  margin: 10px 0 0;
  font-size: 13px;
  text-align: center;
  color: var(--success);
}

.qr-panel__lead {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.qr-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.qr-dialog {
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  max-width: min(420px, calc(100vw - 32px));
}

.qr-dialog::backdrop {
  background: oklch(0.15 0.02 15 / 0.45);
}

.qr-dialog__body {
  margin: 0;
}

.qr-dialog__card {
  margin: 0;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.qr-dialog__header {
  margin-bottom: 8px;
}

.qr-dialog__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
}

/* ── Empty states ── */

.empty,
.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.empty-state--compact {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Responsive ── */

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

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .main {
    padding: 20px 16px;
  }

  .topbar__title {
    display: none;
  }

  .created-card__actions {
    flex-direction: column;
  }

  .bindings-table th:nth-child(4),
  .bindings-table td:nth-child(4) {
    display: none;
  }
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
