/* ============================================================
   TOKENS
   ============================================================ */
:root {
  /* Surfaces */
  --bg:          #f2f3f5;
  --surface:     #ffffff;
  --surface-2:   #f9f9fb;

  /* Borders */
  --border:      #e4e5e9;
  --border-mid:  #d0d1d8;

  /* Text */
  --text:        #0e0f14;
  --text-2:      #4a4b58;
  --text-3:      #9395a8;

  /* Brand */
  --brand:       #0c0d18;
  --brand-mid:   #1a1b2e;

  /* Accent — warm gold */
  --accent:      #c2923a;
  --accent-dark: #9e7228;
  --accent-pale: #faf2e0;

  /* Condition */
  --good:        #15803d;
  --good-bg:     #dcfce7;
  --fair:        #b45309;
  --fair-bg:     #fef3c7;
  --poor:        #c2410c;
  --poor-bg:     #ffedd5;
  --critical:    #b91c1c;
  --critical-bg: #fee2e2;

  /* Radii */
  --r-sm:  6px;
  --r:     10px;
  --r-lg:  14px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow:    0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.05);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.06), 0 12px 32px rgba(0,0,0,0.08);

  /* Z-index */
  --z-sticky: 50;
  --z-toast:  200;
}

/* ============================================================
   RESET + BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: 88px;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  background: var(--brand);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04), 0 4px 20px rgba(0,0,0,0.3);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  max-width: 800px;
  margin: 0 auto;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.company-logo-header {
  height: 26px;
  width: auto;
  max-width: 72px;
  object-fit: contain;
  border-radius: 3px;
  flex-shrink: 0;
}

.header-username {
  display: none;
  font-size: 13px;
  color: rgba(255,255,255,0.45);
}

.header-signout {
  background: none;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  color: rgba(255,255,255,0.45);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.header-signout:hover {
  border-color: rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.7);
}

.logo {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.6px;
  color: var(--accent);
  line-height: 1;
}

.template-badge {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 4px 10px;
  border-radius: 4px;
}

/* ============================================================
   LAYOUT
   ============================================================ */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============================================================
   FORM SECTIONS
   ============================================================ */
.form-section {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--brand);
  border-left: 3px solid var(--accent);
  padding: 10px 16px 10px 13px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.82);
}

.section-fields { padding: 2px 0; }

/* ============================================================
   FIELDS
   ============================================================ */
.field {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.field:last-child { border-bottom: none; }

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}

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

/* ============================================================
   INPUTS
   ============================================================ */
.input-text,
.input-select,
.input-textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 16px;
  font-family: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--surface-2);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  line-height: 1.4;
}

.input-text:focus,
.input-select:focus,
.input-textarea:focus {
  outline: none;
  border-color: var(--brand-mid);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(26, 27, 46, 0.08);
}

.input-text::placeholder,
.input-textarea::placeholder {
  color: var(--text-3);
}

.input-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239395a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 38px;
  cursor: pointer;
}

.input-textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.55;
}

/* ============================================================
   RATING
   ============================================================ */
.rating-group {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.rating-option { cursor: pointer; }

.rating-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.rating-option span {
  display: inline-flex;
  align-items: center;
  padding: 7px 15px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  user-select: none;
}

/* Hover - unselected */
.rating-option:hover span {
  border-color: var(--border-mid);
  background: var(--surface);
}

/* Selected states - colored bg, dark text for legibility */
.rating-option:has(input[value="Good"]) input:checked + span {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(21,128,61,0.10);
}
.rating-option:has(input[value="Fair"]) input:checked + span {
  background: var(--fair-bg);
  border-color: var(--fair);
  color: var(--fair);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(180,83,9,0.10);
}
.rating-option:has(input[value="Poor"]) input:checked + span {
  background: var(--poor-bg);
  border-color: var(--poor);
  color: var(--poor);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(194,65,12,0.10);
}
.rating-option:has(input[value="Critical"]) input:checked + span {
  background: var(--critical-bg);
  border-color: var(--critical);
  color: var(--critical);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(185,28,28,0.10);
}

/* ============================================================
   CHECKLIST
   ============================================================ */
.checklist-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.checklist-option {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  border-radius: 4px;
  transition: color 0.1s;
}

.checklist-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--brand-mid);
}

/* ============================================================
   TOGGLE
   ============================================================ */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-input {
  position: relative;
  width: 46px;
  height: 26px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 13px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-input:checked { background: var(--good); }

.toggle-input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s cubic-bezier(0.34, 1.2, 0.64, 1);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

.toggle-input:checked::after { transform: translateX(20px); }

/* ============================================================
   SIGNATURE
   ============================================================ */
.sig-wrap {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.sig-canvas {
  display: block;
  width: 100%;
  height: 120px;
  cursor: crosshair;
  touch-action: none;
}

.sig-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  pointer-events: none;
  user-select: none;
}

.sig-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.sig-clear:hover {
  border-color: var(--text-3);
  color: var(--text);
}

/* ============================================================
   PHOTOS
   ============================================================ */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  padding: 14px 16px 0;
}

.photo-thumb-wrap {
  position: relative;
  aspect-ratio: 1;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--r-sm);
  display: block;
}

.photo-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.65);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
}

.photo-remove:hover { background: rgba(0,0,0,0.85); }


/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 22px;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s, border-color 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.btn:active { transform: scale(0.97); }

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
}

.btn-primary {
  background: var(--accent);
  color: var(--brand);
}

.btn-primary:hover {
  background: var(--accent-dark);
  box-shadow: 0 4px 16px rgba(194,146,58,0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1.5px solid var(--border-mid);
}

.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--brand-mid);
  color: var(--text);
}

.btn-secondary {
  background: rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.80);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 14px;
}

.btn-outline {
  background: transparent;
  color: var(--text-2);
  border: 1.5px dashed var(--border);
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: var(--z-sticky);
  padding-bottom: env(safe-area-inset-bottom);
}

.footer-inner {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  max-width: 800px;
  margin: 0 auto;
}

.footer-inner .btn-primary { flex: 1; }
.footer-inner #share-btn { flex-shrink: 0; }


/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--brand);
  color: rgba(255,255,255,0.92);
  padding: 11px 20px;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 500;
  z-index: var(--z-toast);
  max-width: calc(100% - 32px);
  text-align: center;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.toast:not([hidden]) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

/* ============================================================
   TEMPLATE SELECTOR
   ============================================================ */
.template-selector {
  display: flex;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--r) var(--r);
  padding: 5px;
  box-shadow: var(--shadow);
}

.template-tab {
  flex: 1;
  padding: 9px 16px;
  border: none;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  letter-spacing: -0.01em;
}

.template-tab.active {
  background: var(--brand);
  color: rgba(255,255,255,0.92);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.template-tab:not(.active):hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ============================================================
   CUSTOM FIELDS
   ============================================================ */
.custom-field-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 8px 12px;
  align-items: start;
}

.custom-field-row:last-child { border-bottom: none; }

.cf-label-input {
  grid-column: 1;
  grid-row: 1;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 11px;
}

.cf-remove-btn {
  grid-column: 2;
  grid-row: 1;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.cf-remove-btn:hover {
  background: var(--critical-bg);
  border-color: var(--critical);
  color: var(--critical);
}

.cf-value-input {
  grid-column: 1 / -1;
  grid-row: 2;
  min-height: 68px;
}

/* Shared "add row" button used by both custom fields and photos */
.add-row-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 10px 16px 14px;
  padding: 11px;
  width: calc(100% - 32px);
  background: var(--surface-2);
  color: var(--text-2);
  border: 1.5px dashed var(--border-mid);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.add-row-btn:hover {
  border-color: var(--brand-mid);
  color: var(--text);
  background: var(--surface);
}

/* ============================================================
   HEADER NAV
   ============================================================ */
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-nav {
  display: flex;
  gap: 2px;
}

.header-nav-link {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.45);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.header-nav-link:hover {
  color: rgba(255,255,255,0.75);
  background: rgba(255,255,255,0.08);
}

.header-nav-link.active {
  color: rgba(255,255,255,0.95);
  background: transparent;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  padding-bottom: 5px;
}

/* ============================================================
   TEMPLATE LIST PAGE
   ============================================================ */
.tpl-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-system {
  background: var(--surface-2);
  color: var(--text-3);
  border: 1px solid var(--border);
}

.badge-company {
  background: var(--accent-pale);
  color: var(--accent-dark);
}

.badge-archived {
  background: var(--surface-2);
  color: var(--text-3);
  border: 1px solid var(--border);
}

.tpl-action-btn {
  font-size: 13px;
  padding: 5px 14px;
  border-radius: var(--r-sm);
  text-decoration: none;
  line-height: 1;
}

.btn-danger-ghost {
  color: var(--critical);
  border-color: rgba(185,28,28,0.2);
}

.btn-danger-ghost:hover {
  background: var(--critical-bg);
  border-color: var(--critical);
  color: var(--critical);
}

/* ============================================================
   TEMPLATE EDITOR
   ============================================================ */
.te-back {
  margin-bottom: 4px;
}

.te-back a {
  font-size: 13px;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.12s;
}

.te-back a:hover { color: var(--text-2); }

.te-meta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.te-meta-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.te-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.te-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--brand);
  border-left: 3px solid var(--accent);
  padding: 8px 10px 8px 9px;
}

.te-section-title-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: rgba(255,255,255,0.82);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  min-width: 0;
}

.te-section-title-input::placeholder { color: rgba(255,255,255,0.28); }

.te-section-btns { display: flex; gap: 3px; flex-shrink: 0; }

.te-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 5px;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
  font-family: inherit;
  padding: 0;
  line-height: 1;
}

.te-icon-btn:hover {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.88);
  border-color: rgba(255,255,255,0.25);
}

.te-icon-btn-remove {
  color: rgba(255,160,140,0.65);
  border-color: rgba(255,80,60,0.18);
}

.te-icon-btn-remove:hover {
  background: rgba(220,60,40,0.18);
  color: rgb(255,130,115);
  border-color: rgba(255,80,60,0.4);
}

.te-section-fields { border-bottom: 1px solid var(--border); }

.te-field-row { border-bottom: 1px solid var(--border); }
.te-field-row:last-child { border-bottom: none; }

.te-field-main {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
}

.te-label-input {
  flex: 1;
  font-size: 14px;
  padding: 7px 10px;
  min-width: 0;
}

.te-type-select {
  font-size: 13px;
  padding: 7px 28px 7px 10px;
  flex-shrink: 0;
  width: 118px;
  color: var(--text-2);
}

.te-field-actions { display: flex; gap: 2px; flex-shrink: 0; }

.te-field-actions .te-icon-btn {
  background: var(--surface-2);
  color: var(--text-3);
  border-color: var(--border);
  width: 26px;
  height: 26px;
}

.te-field-actions .te-icon-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-mid);
}

.te-field-actions .te-icon-btn-remove:hover {
  background: var(--critical-bg);
  color: var(--critical);
  border-color: rgba(185,28,28,0.3);
}

.te-options-wrap {
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.te-options-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
  padding-top: 10px;
}

.te-options-input {
  font-size: 13px;
  min-height: 76px;
  line-height: 1.6;
}

.te-add-field-btn {
  margin: 0 12px 12px;
  width: calc(100% - 24px);
  font-size: 13px;
  padding: 9px;
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.settings-field {
  margin-bottom: 14px;
}

.settings-field:last-child { margin-bottom: 0; }

.settings-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.settings-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 16px;
}

.settings-colors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  padding: 2px;
  background: var(--surface-2);
  flex-shrink: 0;
}

.color-hex {
  font-size: 14px;
  font-family: monospace;
  letter-spacing: 0.02em;
  flex: 1;
}

/* Theme presets */
.theme-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.theme-swatch:hover {
  border-color: var(--border-mid);
}

.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(194,146,58,0.2);
}

.theme-swatch-primary {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  width: 44px;
  height: 32px;
  border-radius: 4px;
  overflow: hidden;
}

.theme-swatch-accent {
  width: 14px;
  height: 10px;
  display: block;
}

.theme-swatch-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* Logo upload */
.logo-upload-area {
  border: 1.5px dashed var(--border-mid);
  border-radius: var(--r);
  background: var(--surface-2);
  overflow: hidden;
}

.logo-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.15s;
}

.logo-upload-label:hover { background: var(--surface); }

#logo-preview {
  position: relative;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#logo-preview img {
  max-height: 80px;
  max-width: 200px;
  object-fit: contain;
  display: block;
}

.logo-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.logo-remove-btn:hover {
  background: var(--critical-bg);
  color: var(--critical);
  border-color: var(--critical);
}

.hidden { display: none !important; }

/* ============================================================
   MEMBERS PAGE / DRAWER
   ============================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  backdrop-filter: blur(2px);
}

.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 101;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 16px;
  font-weight: 600;
}

.drawer-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-2);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
}

.drawer-close:hover { background: var(--border); }

.drawer-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.drawer-note {
  font-size: 13px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  line-height: 1.5;
}

/* ============================================================
   DESKTOP
   ============================================================ */
@media (min-width: 600px) {
  main { padding: 24px 20px; gap: 12px; }

  .header-inner { padding: 16px 20px; }

  .header-username { display: inline; }

  .section-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .field-textarea,
  .field-checklist,
  .field-rating {
    grid-column: 1 / -1;
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
/* ============================================================
   TEMPLATE MISMATCH MODAL
   ============================================================ */
.tpl-mismatch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 400;
  padding: 24px;
}

.tpl-mismatch-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 28px 24px 20px;
  max-width: 420px;
  width: 100%;
}

.tpl-mismatch-modal h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-1);
}

.tpl-mismatch-modal p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-2);
  margin-bottom: 16px;
}

.tpl-mismatch-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 20px;
}

.tpl-mismatch-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.tpl-mismatch-cancel {
  display: block;
  width: 100%;
  padding: 8px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  text-align: center;
  border-radius: var(--r);
  transition: color 0.15s;
}

.tpl-mismatch-cancel:hover { color: var(--text-1); }

.sys-cat-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.sys-cat-filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-right: 2px;
}
.sys-cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.sys-cat-chip input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.sys-tpl-check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.sys-tpl-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.sys-tpl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 16px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}


/* ============================================================
   DRAFT BAR (index.html inline strip)
   ============================================================ */
.draft-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 14px;
  box-shadow: var(--shadow-sm);
}

.draft-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
}

.draft-bar-link {
  color: var(--text-3);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.12s;
}

.draft-bar-link:hover { color: var(--text-2); }

.draft-bar-sep {
  color: var(--border-mid);
  font-size: 16px;
  line-height: 1;
}

.draft-bar-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   DRAFTS PAGE
   ============================================================ */
.drafts-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.drafts-page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.draft-group { display: flex; flex-direction: column; gap: 8px; }

.draft-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.draft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.draft-card:hover {
  border-color: var(--border-mid);
  box-shadow: var(--shadow);
}

.draft-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.draft-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draft-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--text-3);
}

.draft-card-dot {
  color: var(--border-mid);
}

.draft-review-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--fair-bg);
  color: var(--fair);
  border-radius: 20px;
  padding: 3px 9px;
  white-space: nowrap;
}

.draft-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.draft-card-bin {
  opacity: 0.7;
}

/* ---- Person sections (drafts page) ---- */
.draft-person-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.draft-person-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--brand);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.draft-person-initials {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.draft-person-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.88);
  flex: 1;
}

.draft-person-you {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  margin-left: 6px;
}

.draft-subsection {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}

.draft-subsection:last-child { border-bottom: none; }

.draft-subsection-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 10px;
}

/* Refactored card: no padding on wrapper, main row has it */
.draft-card {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s;
  margin-bottom: 6px;
}

.draft-card:last-child { margin-bottom: 0; }
.draft-card:hover { border-color: var(--border-mid); }

.draft-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}

@media (max-width: 600px) {
  .draft-card-main {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .draft-card-body {
    flex: 1 1 100%;
  }

  .draft-card-actions {
    flex-shrink: 1;
    flex-wrap: wrap;
  }

  .draft-history-btn {
    margin-left: 0;
  }
}

.draft-card-actions.greyed-out .btn,
.draft-card-actions.greyed-out a.btn {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Comment chain ---- */
.draft-chain {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.draft-chain-item {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}

.draft-chain-actor {
  font-weight: 600;
  color: var(--text);
}

.draft-chain-time {
  color: var(--text-3);
  font-size: 11px;
}

.draft-chain-note {
  display: block;
  color: var(--text-2);
  font-style: italic;
  margin-top: 2px;
}

.draft-chain-modal {
  border-top: none;
  background: none;
  padding: 0;
}

.draft-chain-modal .draft-chain-item {
  font-size: 13px;
  padding: 10px 0 10px 12px;
  border-left: 2px solid var(--border);
}

.draft-history-btn {
  margin-left: auto;
  color: var(--text-3);
  border: 1px solid var(--border);
}

.draft-history-btn:hover {
  color: var(--text-2);
}

/* Bin section still uses the group/group-title pattern */
.draft-card-bin {
  opacity: 0.7;
}

.draft-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-3);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border-mid);
  border-radius: var(--r);
}

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