/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
  --color-primary:       #6c63ff;
  --color-primary-dim:   #4f48cc;
  --color-danger:        #e74c3c;
  --color-danger-dim:    #c0392b;
  --color-bg:            #0f0f1a;
  --color-surface:       #1a1a2e;
  --color-surface-2:     #22223a;
  --color-surface-3:     #2c2c4a;
  --color-text:          #e0e0f0;
  --color-text-muted:    #8080aa;
  --color-border:        #2a2a48;
  --radius-sm:           8px;
  --radius-md:           14px;
  --radius-full:         9999px;
  --topbar-h:            56px;
  --fab-size:            64px;
  --swipe-reveal:        80px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}

/* ── Top bar ────────────────────────────────────────────────────────────── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  z-index: 50;
}

#app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

#tally {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ── Inventory list container ───────────────────────────────────────────── */
#item-list-container {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0; left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--fab-size) + 48px);
}

#item-list {
  list-style: none;
}

/* ── Empty state ────────────────────────────────────────────────────────── */
#empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
  color: var(--color-text-muted);
}

#empty-state.visible {
  display: flex;
}

.empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

#empty-state p {
  font-size: 15px;
  line-height: 1.6;
}

#empty-state strong {
  color: var(--color-primary);
}

/* ── List item row ──────────────────────────────────────────────────────── */
.item-row {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.item-delete-bg {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: var(--swipe-reveal);
  background: var(--color-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.item-delete-bg button {
  background: none;
  border: none;
  color: white;
  font-size: 22px;
  width: 100%;
  height: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  min-height: 72px;
  background: var(--color-surface);
  transition: transform 0.2s ease;
  cursor: pointer;
  user-select: none;
}

.item-content:active {
  background: var(--color-surface-2);
}

.item-thumbnail {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface-3);
}

.item-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--color-surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--color-text-muted);
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-model {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-qty-badge {
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── FAB ────────────────────────────────────────────────────────────────── */
#fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 24px;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  font-size: 36px;
  line-height: 1;
  font-weight: 300;
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.55);
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#fab:active {
  transform: scale(0.9);
  box-shadow: 0 2px 10px rgba(108, 99, 255, 0.4);
}

/* ── Form overlay ───────────────────────────────────────────────────────── */
#form-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

#form-overlay.hidden {
  display: none;
}

/* ── Form sheet ─────────────────────────────────────────────────────────── */
#form-sheet {
  background: var(--color-surface);
  width: 100%;
  max-height: 95dvh;
  max-height: 95vh;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.28s ease;
  overflow: hidden;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

#form-header {
  display: flex;
  align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

#form-title {
  font-size: 17px;
  font-weight: 700;
}

#item-form {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
}

/* ── Form fields ────────────────────────────────────────────────────────── */
.field-group {
  margin-bottom: 16px;
}

.field-group label,
.section-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.required {
  color: var(--color-primary);
}

.field-group input[type="text"],
.field-group input[type="number"],
.field-group textarea {
  width: 100%;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--color-text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.field-group input:focus,
.field-group textarea:focus {
  border-color: var(--color-primary);
}

.field-group textarea {
  resize: none;
  line-height: 1.5;
}

/* ── Quantity control ───────────────────────────────────────────────────── */
.qty-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-control button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  flex-shrink: 0;
  transition: background 0.1s;
}

.qty-control button:active {
  background: var(--color-surface-2);
}

#f-quantity {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
}

/* ── Image grid ─────────────────────────────────────────────────────────── */
#image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface-3);
  cursor: pointer;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.thumb-selected-ring {
  position: absolute;
  inset: 0;
  border: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.thumb-star {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  pointer-events: none;
}


/* ── Add pictures button ────────────────────────────────────────────────── */
#add-pictures-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: var(--color-surface-3);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  touch-action: manipulation;
  transition: border-color 0.15s, color 0.15s;
  margin-bottom: 4px;
}

#add-pictures-btn:active {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.add-pic-icon {
  font-size: 18px;
}

#file-input {
  display: none;
}

/* ── Form action buttons ────────────────────────────────────────────────── */
#form-actions {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

#form-status {
  text-align: center;
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 8px 16px 0;
  min-height: 0;
}

#form-status.hidden { display: none; }

#form-action-btns {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#form-action-btns button {
  flex: 1;
  height: 52px;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.1s, transform 0.1s;
  font-family: inherit;
}

#form-action-btns button:active {
  opacity: 0.8;
  transform: scale(0.97);
}

#cancel-btn {
  background: var(--color-surface-3);
  color: var(--color-text);
}

#save-btn {
  background: var(--color-primary);
  color: white;
}

/* ── Upload toast ───────────────────────────────────────────────────────── */
#upload-toast {
  position: fixed;
  bottom: max(88px, calc(80px + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  z-index: 400;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s;
}

#upload-toast.hidden {
  display: none;
}

/* ── Full-screen preview ────────────────────────────────────────────────── */
#preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

#preview-overlay.hidden {
  display: none;
}

#preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

#preview-close-btn {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  z-index: 1;
}

#preview-actions {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 0 24px;
}

#preview-actions button {
  flex: 1;
  max-width: 180px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
}

#preview-set-cover-btn {
  background: var(--color-surface-3);
  color: var(--color-text);
}

#preview-set-cover-btn.is-cover {
  opacity: 0.4;
  pointer-events: none;
}

#preview-delete-btn {
  background: var(--color-danger);
  color: white;
}

#preview-rotate-left-btn,
#preview-rotate-right-btn {
  flex: 0 0 48px;
  font-size: 22px;
  background: rgba(255,255,255,0.12);
  color: white;
}


/* ── Barcode button & result ────────────────────────────────────────────── */
#scan-barcode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px;
  background: var(--color-surface-3);
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, color 0.15s;
}

#scan-barcode-btn:active {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.scan-icon {
  font-size: 18px;
  line-height: 1;
}

#barcode-result {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 8px;
  min-width: 0;
}

#barcode-result.hidden {
  display: none;
}

#barcode-type-badge {
  background: var(--color-primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}

#barcode-value-text {
  font-size: 13px;
  color: var(--color-text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

#clear-barcode-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
  line-height: 1;
  touch-action: manipulation;
}

#clear-barcode-btn:active {
  color: var(--color-danger);
}

/* ── Scanner overlay ────────────────────────────────────────────────────── */
#scanner-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#scanner-overlay.hidden {
  display: none;
}

#scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#scanner-ui {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  pointer-events: none;
}

#scanner-viewfinder {
  width: 72vmin;
  height: 72vmin;
  max-width: 300px;
  max-height: 300px;
  position: relative;
  /* Darken everything outside the viewfinder */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.58);
  border-radius: 4px;
}

/* Corner brackets */
.vf-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: white;
  border-style: solid;
}

.vf-tl { top: 0;    left: 0;   border-width: 3px 0 0 3px; border-radius: 3px 0 0 0; }
.vf-tr { top: 0;    right: 0;  border-width: 3px 3px 0 0; border-radius: 0 3px 0 0; }
.vf-bl { bottom: 0; left: 0;   border-width: 0 0 3px 3px; border-radius: 0 0 0 3px; }
.vf-br { bottom: 0; right: 0;  border-width: 0 3px 3px 0; border-radius: 0 0 3px 0; }

/* Scan line animation */
#scanner-viewfinder::after {
  content: '';
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  border-radius: 1px;
  animation: scanLine 1.8s ease-in-out infinite;
}

@keyframes scanLine {
  0%   { top: 8px;   opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { top: calc(100% - 8px); opacity: 0; }
}

#scanner-status {
  color: white;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  padding: 0 24px;
}

#scanner-status.detected {
  color: #4cff91;
  font-weight: 700;
  font-size: 15px;
}

#scanner-cancel-btn {
  position: absolute;
  bottom: calc(32px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  padding: 12px 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  touch-action: manipulation;
  z-index: 1;
}

/* ── Tag manager button ─────────────────────────────────────────────────── */
#tag-mgr-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 17px;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 2px;
  line-height: 1;
  display: flex;
  align-items: center;
}

/* ── Topbar right cluster ───────────────────────────────────────────────── */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#auth-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
  transition: background 0.3s;
}

#auth-dot.ok { background: #27ae60; }

/* ── Tag filter bar ─────────────────────────────────────────────────────── */
#tag-filter-bar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  height: 44px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  z-index: 40;
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

#tag-filter-bar::-webkit-scrollbar { display: none; }

#tag-filter-bar.visible {
  transform: translateY(0);
}

#item-list-container.has-filter-bar {
  top: calc(var(--topbar-h) + 44px);
}

#item-list-container.select-mode {
  padding-bottom: 120px;
}

.tag-filter-chip {
  flex-shrink: 0;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tag-filter-chip.active {
  background: var(--color-surface-3);
  color: var(--color-text);
  border-color: var(--color-surface-3);
}

.tag-filter-chip.tag-active {
  color: white;
  border-color: transparent;
}

.tag-filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Item tag pills ─────────────────────────────────────────────────────── */
.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.item-tag-pill {
  height: 17px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
  color: white;
  line-height: 17px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── Select mode ────────────────────────────────────────────────────────── */
.item-select-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-right: 2px;
  transition: background 0.15s, border-color 0.15s;
}

.item-row.selected .item-select-check {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.item-row.selected .item-content {
  background: rgba(108, 99, 255, 0.1);
}

/* ── Select panel ───────────────────────────────────────────────────────── */
#select-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 300;
  padding-bottom: env(safe-area-inset-bottom);
}

#select-panel.hidden { display: none; }

#select-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 4px;
}

#select-count {
  font-size: 13px;
  color: var(--color-text-muted);
}

#select-done-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
  padding: 4px 0;
}

#select-tags-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-height: 50px;
}

#select-tags-row::-webkit-scrollbar { display: none; }

.select-tag-chip {
  flex-shrink: 0;
  height: 34px;
  padding: 0 16px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  font-size: 14px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
  opacity: 0.55;
  transition: opacity 0.15s, box-shadow 0.15s;
}

.select-tag-chip.all-have-it {
  opacity: 1;
  box-shadow: 0 0 0 2px white;
}

.select-tag-chip.some-have-it {
  opacity: 0.8;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.4);
}

.select-no-tags {
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ── Tag manager ────────────────────────────────────────────────────────── */
#tag-mgr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 600;
  display: flex;
  align-items: flex-end;
}

#tag-mgr-overlay.hidden { display: none; }

#tag-mgr-sheet {
  width: 100%;
  max-height: 80vh;
  background: var(--color-surface);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

#tag-mgr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

#tag-mgr-header span {
  font-size: 17px;
  font-weight: 600;
}

#tag-mgr-close-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--color-surface-3);
  border: none;
  color: var(--color-text);
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex; align-items: center; justify-content: center;
}

#tag-mgr-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.tag-mgr-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--color-border);
}

.tag-mgr-swatch {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-mgr-name {
  flex: 1;
  font-size: 15px;
}

.tag-mgr-delete-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 18px;
  cursor: pointer;
  touch-action: manipulation;
  padding: 4px 6px;
  line-height: 1;
}

.tag-mgr-empty {
  padding: 16px 20px;
  color: var(--color-text-muted);
  font-size: 14px;
}

#tag-new-form {
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#tag-new-name {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 16px;
  padding: 10px 12px;
  font-family: inherit;
}

#tag-new-name:focus {
  outline: none;
  border-color: var(--color-primary);
}

#tag-color-swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tag-color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.1s, transform 0.1s;
  outline: none;
}

.tag-color-swatch.selected {
  border-color: white;
  transform: scale(1.15);
}

#tag-new-add-btn {
  height: 44px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
}

/* ── Auth overlay ───────────────────────────────────────────────────────── */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.auth-overlay.hidden { display: none; }

.auth-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 32px 28px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-box h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.auth-box > p {
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.auth-box input[type="tel"],
.auth-box input[type="text"] {
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--color-text);
  font-size: 16px;
  width: 100%;
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}

.auth-box input:focus {
  border-color: var(--color-primary);
}

#auth-code {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 28px;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 12px 8px;
}

.auth-btn {
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  touch-action: manipulation;
  transition: opacity 0.1s;
}

.auth-btn:active   { opacity: 0.85; }
.auth-btn:disabled { opacity: 0.45; cursor: default; }

.auth-back-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  padding: 4px;
  touch-action: manipulation;
}

.auth-back-btn:active { color: var(--color-text); }

.auth-error {
  font-size: 13px;
  color: var(--color-danger);
  margin: 0;
}

.auth-error.hidden { display: none; }

/* ── Scrollbar styling ──────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 2px;
}
