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

:root {
  --primary:      #1a73e8;
  --primary-dark: #1558b0;
  --success:      #1e8a4a;
  --success-dark: #166638;
  --danger:       #d93025;
  --bg:           #f8f9fa;
  --surface:      #ffffff;
  --border:       #dadce0;
  --text:         #202124;
  --text-2:       #5f6368;
  --radius:       12px;
  --shadow:       0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}

body {
  font-family: 'Google Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Password gate ────────────────────────────────────────────────────────── */
#gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.gate-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-card .logo     { font-size: 28px; font-weight: 700; color: var(--primary); margin-bottom: 8px; letter-spacing: -.5px; }
.gate-card .subtitle { font-size: 14px; color: var(--text-2); margin-bottom: 32px; }

.gate-card input[type="password"] {
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 16px; color: var(--text); outline: none;
  transition: border-color .2s; margin-bottom: 12px;
}
.gate-card input[type="password"]:focus     { border-color: var(--primary); }
.gate-card input[type="password"].error     { border-color: var(--danger); animation: shake .35s ease; }
.gate-card .error-msg { font-size: 13px; color: var(--danger); min-height: 18px; margin-bottom: 12px; text-align: left; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60%  { transform: translateX(-6px); }
  40%,80%  { transform: translateX(6px); }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; width: 100%; justify-content: center; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }

.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--bg); }

.btn-danger-text { background: transparent; border: none; color: var(--danger); padding: 0; font-size: 13px; font-weight: 500; cursor: pointer; }
.btn-danger-text:hover { text-decoration: underline; }

.btn-sm { padding: 7px 14px; font-size: 13px; width: auto; }

/* small trash icon button */
.btn-icon-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 4px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: .55; transition: opacity .15s, color .15s, background .15s;
}
.btn-icon-delete:hover { opacity: 1; color: var(--danger); background: #fce8e6; }

/* square icon button (card actions: update / download / remove) */
.btn-icon {
  background: transparent; border: 1.5px solid var(--border); cursor: pointer;
  color: var(--text-2); padding: 7px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s, border-color .15s;
}
.btn-icon:hover { color: var(--primary); border-color: var(--primary); background: var(--bg); }
.btn-icon.btn-icon-danger:hover { color: var(--danger); border-color: var(--danger); background: #fce8e6; }

.uploading-label { font-size: 13px; color: var(--text-2); font-style: italic; }

/* ── Dashboard layout ─────────────────────────────────────────────────────── */
#dashboard { display: none; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 52px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  position: sticky; top: 0; z-index: 10;
}

.topbar-brand { justify-self: start; }
.brand        { font-size: 18px; font-weight: 700; color: var(--primary); }

.topbar-nav {
  display: flex; gap: 2px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 3px;
}
.topbar-nav-item {
  padding: 4px 18px; border-radius: 16px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  text-decoration: none; transition: background .15s, color .15s; white-space: nowrap;
}
.topbar-nav-item.active { background: var(--primary); color: #fff; }
.topbar-nav-item:not(.active):hover { background: var(--border); color: var(--text); }

.topbar-right { justify-self: end; display: flex; align-items: center; gap: 8px; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; }
.page-actions { display: flex; justify-content: flex-end; margin-bottom: 16px; }

.empty-msg {
  text-align: center; color: var(--text-2); font-size: 15px;
  padding: 60px 20px;
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 80px 20px; color: var(--text-2); font-size: 14px;
}
#loading-overlay.visible { display: flex; }

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline card spinner (delete / Firestore ops) */
.btn.loading { opacity: .6; pointer-events: none; position: relative; }
.btn-icon-delete.loading { opacity: .4; pointer-events: none; animation: spin .7s linear infinite; }

/* ── Type sections ────────────────────────────────────────────────────────── */
.type-section { margin-bottom: 24px; }

.type-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}

.type-toggle {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 0; text-align: left; flex: 1; min-width: 0;
}
.type-toggle .type-label { font-size: 18px; font-weight: 700; color: var(--text); }
.type-toggle .chevron    { font-size: 13px; transition: transform .2s; color: var(--text-2); margin-left: 2px; }
.type-toggle.open .chevron { transform: rotate(180deg); }

.type-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.badge {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; font-size: 12px; font-weight: 500;
  color: var(--text-2); padding: 2px 10px;
}

/* ── Slot grid ────────────────────────────────────────────────────────────── */
.type-grid         { display: none; }
.type-grid.open    { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

/* ── Slot card ────────────────────────────────────────────────────────────── */
.slot-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}

/* preview area */
.preview-placeholder {
  width: 100%; height: 110px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; color: var(--text-2); font-size: 13px;
  transition: background .15s, border-color .15s;
  pointer-events: none; /* let drag events hit the pa-div */
}
.preview-placeholder svg { opacity: .3; }
.preview-placeholder .drop-hint { font-size: 11px; opacity: .6; }

.preview-wrap {
  position: relative; width: 100%; height: 110px;
  background: var(--bg); border-bottom: 1px solid var(--border); overflow: hidden;
  transition: outline .1s;
}
.preview-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

/* drag-over state — applied to the pa-div wrapper */
.pa-drop-zone {
  position: relative; display: block;
}
.pa-drop-zone.drag-over .preview-placeholder,
.pa-drop-zone.drag-over .preview-wrap {
  outline: 2.5px dashed var(--primary);
  outline-offset: -3px;
  background: #e8f0fe;
}
.pa-drop-zone.drag-over::after {
  content: "Drop to preview";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26,115,232,.13);
  color: var(--primary); font-size: 13px; font-weight: 600;
  pointer-events: none;
  border-radius: 0;
}

.preview-wrap.pending { outline: 2.5px dashed #f9ab00; outline-offset: -2px; }
.preview-wrap .pending-badge {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(249,171,0,.88); color: #202124;
  font-size: 11px; font-weight: 600; text-align: center;
  padding: 4px 8px; letter-spacing: .2px;
}

/* card body */
.card-body { padding: 10px 12px; flex: 1; display: flex; flex-direction: column; gap: 8px; }

.card-label-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-label     { font-size: 14px; font-weight: 600; line-height: 1.3; }
.card-id-hint   { font-size: 11px; color: var(--text-2); font-family: 'Courier New', monospace; margin-top: -6px; }

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

.card-meta { font-size: 11px; color: var(--text-2); margin-top: auto; }

/* progress bar */
.progress-wrap           { display: none; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-wrap.visible   { display: block; }
.progress-bar            { height: 100%; background: var(--primary); width: 0%; transition: width .1s linear; border-radius: 2px; }

/* ── Dialog ───────────────────────────────────────────────────────────────── */
dialog {
  border: none; border-radius: var(--radius); padding: 0;
  width: 100%; max-width: 420px;
  box-shadow: 0 8px 30px rgba(0,0,0,.18);
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
dialog::backdrop { background: rgba(0,0,0,.35); }

.dialog-inner  { padding: 28px 28px 24px; }
.dialog-inner h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.dialog-context  { font-size: 13px; color: var(--text-2); margin-bottom: 18px; min-height: 16px; }

.dialog-field        { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.dialog-field label  { font-size: 13px; font-weight: 600; }
.dialog-field input  {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); outline: none; transition: border-color .2s;
}
.dialog-field input:focus   { border-color: var(--primary); }
.field-hint                 { font-weight: 400; color: var(--text-2); }

.dialog-error   { font-size: 13px; color: var(--danger); min-height: 18px; margin-bottom: 6px; }

.dialog-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px;
}
.dialog-actions .btn-primary { width: auto; }

/* ── Description — display mode ──────────────────────────────────────────── */
.desc-display {
  display: flex; align-items: flex-start; gap: 4px;
}
.desc-text        { color: var(--text-2); line-height: 1.45; flex: 1; }
.desc-placeholder { color: var(--text-2); opacity: .4; font-style: italic; flex: 1; }
.desc-edit-btn {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  color: var(--text-2); opacity: 0; border-radius: 4px;
  transition: opacity .15s, color .15s; flex-shrink: 0; line-height: 1;
  display: inline-flex; align-items: center;
}
.desc-display:hover .desc-edit-btn,
.inline-field-display:hover .desc-edit-btn { opacity: .6; }
.desc-edit-btn:hover { opacity: 1 !important; color: var(--primary); }

/* ── Description — edit mode ──────────────────────────────────────────────── */
.desc-editing { display: flex; flex-direction: column; gap: 6px; }
.desc-textarea {
  font-size: 13px; color: var(--text); border: 1.5px solid var(--primary);
  border-radius: 6px; padding: 7px 10px; resize: vertical; outline: none;
  font-family: inherit; line-height: 1.45; width: 100%; min-height: 54px;
}
.desc-edit-actions { display: flex; gap: 6px; }

/* ── Type description bar (below type header) ─────────────────────────────── */
.type-description-bar { margin: -10px 0 18px 2px; }
.type-description-bar .desc-text        { font-size: 13px; }
.type-description-bar .desc-placeholder { font-size: 13px; }

/* ── Slot card description ────────────────────────────────────────────────── */
.card-description-wrap { }
.card-description-wrap .desc-text        { font-size: 12px; }
.card-description-wrap .desc-placeholder { font-size: 12px; }
.card-description-wrap .desc-textarea    { font-size: 12px; min-height: 46px; }

/* ── Dialog textarea ──────────────────────────────────────────────────────── */
.dialog-field textarea {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); outline: none; transition: border-color .2s;
  font-family: inherit; resize: vertical; min-height: 64px; width: 100%;
}
.dialog-field textarea:focus { border-color: var(--primary); }

/* ── Drag-and-drop reorder ─────────────────────────────────────────────────── */
.slot-card {
  position: relative;
  cursor: default;
}
.slot-card.dragging {
  opacity: .4;
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
}
.slot-card.drop-target {
  outline: 2.5px dashed var(--primary);
  outline-offset: -2px;
  background: #e8f0fe;
}

.drag-handle {
  position: absolute;
  top: 8px; left: 8px;
  color: var(--text-2);
  opacity: .35;
  cursor: grab;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
  z-index: 1;
  transition: opacity .15s;
}
.slot-card:hover .drag-handle { opacity: .7; }
.drag-handle:active { cursor: grabbing; }

/* ── Card field labels ──────────────────────────────────────────────────────── */
.card-field-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-2); margin-bottom: -4px;
}
.card-field-wrap { }

/* ── Inline title input ─────────────────────────────────────────────────────── */
.inline-field-display { display: flex; align-items: center; gap: 4px; }
.field-text        { font-size: 12px; color: var(--text); flex: 1; }
.field-placeholder { font-size: 12px; color: var(--text-2); opacity: .4; font-style: italic; flex: 1; }
.inline-field-input {
  font-size: 12px; color: var(--text);
  border: 1.5px solid var(--primary); border-radius: 6px;
  padding: 5px 8px; outline: none; font-family: inherit; width: 100%;
}

/* ── Type field rows (title / info below type header) ───────────────────────── */
.type-field-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 0 20px; margin-bottom: 4px;
}
.type-field-key {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-2); min-width: 36px; padding-top: 2px;
}
.type-field-val { flex: 1; }
.type-description-bar { margin: 0; }

/* ── Onboarding slide metadata on card ──────────────────────────────────────── */
.onboarding-meta {
  background: #f1f5ff; border-radius: 6px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.ob-row { display: flex; gap: 6px; align-items: flex-start; }
.ob-key { font-size: 10px; font-weight: 700; text-transform: uppercase;
          letter-spacing: .5px; color: var(--text-2); min-width: 46px; padding-top: 1px; }
.ob-val { font-size: 12px; color: var(--text); line-height: 1.4; display: flex; align-items: center; gap: 5px; }
.color-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%;
             border: 1px solid rgba(0,0,0,.15); flex-shrink: 0; }

/* ── Onboarding section label on card ───────────────────────────────────────── */
.ob-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; color: var(--primary);
  border-top: 1px solid var(--border); padding-top: 10px; margin-top: 2px;
}

/* ── Color input row ────────────────────────────────────────────────────────── */
.color-input-row { display: flex; align-items: center; gap: 8px; }
.color-preview-dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0,0,0,.15); }
.color-val { display: flex; align-items: center; gap: 5px; }

/* ── Dialog divider ─────────────────────────────────────────────────────────── */
.dialog-divider {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-2); border-top: 1px solid var(--border);
  padding-top: 14px; margin: 6px 0 12px;
}

/* ── Settings page ────────────────────────────────────────────────────────── */
.settings-section {
  margin-bottom: 24px;
}
.settings-section-heading {
  font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 4px;
}
.settings-section-desc {
  font-size: 13px; color: var(--text-2); margin-bottom: 20px; max-width: 600px; line-height: 1.5;
}
.settings-loading, .settings-error {
  text-align: center; padding: 60px 20px; color: var(--text-2); font-size: 15px;
}
.settings-error { color: var(--danger); }

/* cfg-* — shared between settings.js and style.css */
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cfg-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.cfg-card-title {
  font-size: 11px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .6px; margin-bottom: 16px;
}
.cfg-field { margin-bottom: 14px; }
.cfg-field label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.cfg-input {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); background: var(--surface);
  outline: none; transition: border-color .15s;
}
.cfg-input:focus { border-color: var(--primary); }
.cfg-hint { font-size: 11px; color: var(--text-2); margin-top: 5px; line-height: 1.4; }

.cfg-toggle-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px;
}
.cfg-toggle-label { font-size: 13px; font-weight: 500; color: var(--text); }
.cfg-toggle-hint  { font-size: 12px; color: var(--text-2); margin-top: 3px; max-width: 200px; }

.toggle-switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; margin-top: 1px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: var(--border); border-radius: 12px; transition: background .2s; cursor: pointer; }
.toggle-switch input:checked + .toggle-track { background: var(--success); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); pointer-events: none;
}
.toggle-switch input:checked ~ .toggle-thumb { left: 23px; }

.cfg-save-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.cfg-status   { font-size: 13px; }
.cfg-status.success { color: var(--success); }
.cfg-status.error   { color: var(--danger); }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #323232; color: #fff;
  padding: 12px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 500; z-index: 200;
  transition: transform .3s ease; white-space: nowrap; pointer-events: none;
}
#toast.show    { transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--success); }
#toast.error   { background: var(--danger); }

/* ── Debug panel ─────────────────────────────────────────────────────────── */
#debug-panel { display: none; position: fixed; top: 60px; right: 16px; width: 380px; max-height: calc(100vh - 72px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.18); padding: 16px; z-index: 200; }
#debug-panel.visible { display: block; }
.debug-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 600; font-size: 14px; }
.debug-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.btn-outline.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.debug-card h3 { margin: 0 0 6px; font-size: 15px; }
.debug-desc { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.debug-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.debug-input { flex: 1; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; }
.debug-toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.debug-toggle input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
#log-output { font-family: monospace; font-size: 12px; max-height: 420px; overflow-y: auto; border-radius: 6px; background: #0d0d0d; padding: 10px; margin-top: 6px; }
#log-output:not(:has(*)) { display: none; }
.log-empty { color: #555; font-style: italic; padding: 2px 0; }
.log-ts { color: #555; margin-right: 6px; }
.log-info    { color: #aaa; padding: 2px 0; }
.log-warning { color: #f5a623; padding: 2px 0; }
.log-error   { color: #e74c3c; padding: 2px 0; font-weight: 600; }

/* ── Environment toggle (pill) ─────────────────────────────────────────────── */
.env-toggle {
  display: inline-flex; align-items: center;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 3px;
}
.env-toggle-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 600; padding: 4px 12px;
  border-radius: 16px; color: var(--text-2); transition: background .15s, color .15s;
  white-space: nowrap;
}
.env-toggle-btn.active-live { background: var(--success); color: #fff; }
.env-toggle-btn.active-dev  { background: #d97706; color: #fff; }

/* ── DEV badge ─────────────────────────────────────────────────────────────── */
.env-badge-dev {
  display: none;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  background: #fef3c7; color: #92400e; border: 1.5px solid #f59e0b;
  border-radius: 6px; padding: 2px 8px;
}
.env-is-dev .env-badge-dev { display: inline-block; }
.env-is-dev .topbar        { border-bottom-color: #f59e0b; }
