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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6ec;
  --border-strong: #c9cdd8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff4ff;
  --primary-glow: rgba(37,99,235,.18);
  --success: #059669;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --text: #0f1117;
  --text-2: #374151;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.07);
  --nav-h: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ── */
.nav {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-h);
  position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 12px rgba(30,58,138,.25);
}
.nav-brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: #fff;
  letter-spacing: -.01em;
  display: flex; align-items: center; gap: .4rem;
}
.nav-brand:hover { text-decoration: none; opacity: .92; }
.nav-links { display: flex; gap: .5rem; align-items: center; }
.nav-links a, .nav-links button {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  cursor: pointer;
  font-size: .875rem; font-weight: 500;
  color: rgba(255,255,255,.92);
  padding: .35rem .75rem;
  transition: background .15s, border-color .15s;
}
.nav-links a:hover, .nav-links button:hover {
  background: rgba(255,255,255,.22);
  color: #fff;
  text-decoration: none;
}
.nav-links a.nav-admin {
  background: rgba(255,255,255,.2);
  border-color: rgba(255,255,255,.35);
  font-weight: 700;
}

/* ── Container ── */
.container { max-width: 880px; margin: 0 auto; padding: 1.75rem 1rem 3rem; }

/* ── Page header ── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.5rem; flex-wrap: wrap; gap: .75rem;
}
.page-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
.page-subtitle { font-size: .875rem; color: var(--muted); margin-top: .15rem; }

/* ── Breadcrumb ── */
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ── Alert ── */
.alert {
  padding: .85rem 1.1rem; border-radius: var(--radius-sm);
  margin-bottom: 1.25rem; font-size: .9rem;
  display: flex; align-items: flex-start; gap: .6rem;
}
.alert::before { font-size: 1rem; flex-shrink: 0; margin-top: .05rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-success::before { content: '✓'; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-error::before   { content: '!'; font-weight: 700; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow .15s;
}
.card-body { padding: 1.25rem 1.5rem; }

/* ── Unit list ── */
.unit-list { display: flex; flex-direction: column; gap: .5rem; }

/* Public unit row — fully clickable */
a.unit-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-decoration: none; color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
a.unit-row:hover {
  border-color: var(--primary);
  box-shadow: 0 3px 12px var(--primary-glow);
  transform: translateY(-1px);
  text-decoration: none;
}

/* Admin unit row */
.unit-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .1s;
  gap: .75rem;
}
.unit-row:hover {
  border-color: var(--primary);
  box-shadow: 0 3px 12px var(--primary-glow);
  transform: translateY(-1px);
}
.unit-row--admin { }
.unit-row-link {
  flex: 1; min-width: 0; text-decoration: none; color: var(--text);
  display: block;
}
.unit-row-link:hover { text-decoration: none; }
.unit-label { font-weight: 700; font-size: 1rem; }
.unit-color { font-size: .85rem; color: var(--muted); margin-top: .1rem; }
.unit-chevron { color: var(--muted-2); font-size: 1.3rem; font-weight: 300; }

/* ── Paint entry card ── */
.paint-entry-card {
  margin-bottom: 1rem;
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-sm);
}
.paint-entry-card:nth-child(2) { border-left-color: #7c3aed; }
.paint-entry-card:nth-child(3) { border-left-color: #059669; }
.paint-entry-card:nth-child(4) { border-left-color: #d97706; }
.paint-entry-card:nth-child(5) { border-left-color: #db2777; }
.paint-entry-card:nth-child(n+6) { border-left-color: var(--border-strong); }

.paint-entry-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: .5rem; padding: 1rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.paint-entry-title { font-size: 1.1rem; font-weight: 800; letter-spacing: -.01em; }
.paint-entry-name { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.color-swatch {
  width: 2.5rem; height: 2.5rem; border-radius: 8px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.18);
}
.color-swatch-none {
  border-style: dashed;
  background: repeating-linear-gradient(45deg, transparent 0 5px, rgba(0,0,0,.06) 5px 10px);
}
.paint-entry-hex { font-size: .8rem; color: var(--text-3); font-family: monospace; margin-top: .1rem; }
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .65rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #bfdbfe; }

.paint-meta {
  display: flex; flex-wrap: wrap; gap: .5rem 2rem;
  padding: .85rem 1.25rem; font-size: .9rem;
}
.paint-meta dt {
  color: var(--muted); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; font-weight: 600; margin-bottom: .1rem;
}
.paint-meta dd { font-weight: 600; color: var(--text-2); }

.formula-block {
  padding: .85rem 1.25rem;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: .82rem;
  background: #f8f8ff;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  color: var(--text-2);
  line-height: 1.7;
}
.notes-block {
  padding: .85rem 1.25rem;
  font-size: .9rem; color: var(--muted);
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem; border-radius: 8px;
  font-size: .875rem; font-weight: 600; border: none; cursor: pointer;
  text-decoration: none; transition: background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap; line-height: 1.2;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,.3);
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 3px 10px rgba(37,99,235,.35);
  text-decoration: none; color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--muted-2); text-decoration: none; color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 1px 4px rgba(220,38,38,.25); }
.btn-danger:hover { background: var(--danger-dark); text-decoration: none; color: #fff; }

.btn-success { background: #059669; color: #fff; box-shadow: 0 1px 4px rgba(5,150,105,.25); }
.btn-success:hover { background: #047857; text-decoration: none; color: #fff; }

.btn-sm { padding: .3rem .7rem; font-size: .78rem; border-radius: 6px; }
.btn-ghost {
  background: none; border: none; box-shadow: none;
  color: var(--muted); padding: .3rem .5rem;
}
.btn-ghost:hover { color: var(--primary); background: var(--primary-light); }

/* ── Admin action row ── */
.action-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* ── Sticky header ── */
.sticky-header {
  position: sticky; top: var(--nav-h); z-index: 100;
  background: var(--bg);
  padding-top: .85rem; padding-bottom: .85rem;
  margin-bottom: .75rem;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* ── Form ── */
.form-card { max-width: 540px; }
.form-group { margin-bottom: 1.1rem; }
.form-label { display: block; font-size: .82rem; font-weight: 700; margin-bottom: .4rem; color: var(--text-2); letter-spacing: .01em; text-transform: uppercase; }
.form-control {
  width: 100%; padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem; color: var(--text); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.4;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea.form-control { resize: vertical; min-height: 88px; }
.form-check { display: flex; align-items: center; gap: .5rem; }
.form-check input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--primary); }
.form-error { font-size: .78rem; color: var(--danger); margin-top: .3rem; font-weight: 500; }
.form-footer { margin-top: 1.25rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.form-row-inline { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row-inline .form-group { flex: 1; min-width: 130px; }

/* ── Inline add / copy panels ── */
.inline-panel {
  background: var(--surface);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--primary-glow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.inline-panel .panel-header {
  background: var(--primary-light);
  border-bottom: 1px solid #bfdbfe;
  padding: .75rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
}
.inline-panel .panel-header strong { color: var(--primary-dark); font-size: .95rem; }
.inline-panel .panel-body { padding: 1.25rem; }

.copy-panel {
  border-color: #7c3aed;
  box-shadow: 0 4px 20px rgba(124,58,237,.12);
}
.copy-panel .panel-header { background: #f5f3ff; border-bottom-color: #ddd6fe; }
.copy-panel .panel-header strong { color: #5b21b6; }

/* ── Copy scheme unit grid ── */
.unit-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: .4rem;
  max-height: 260px;
  overflow-y: auto;
  padding: .5rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.unit-check-item {
  display: flex; align-items: center; gap: .45rem;
  padding: .45rem .6rem;
  border-radius: 6px;
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}
.unit-check-item:hover { background: var(--primary-light); }
.unit-check-item input[type=checkbox] { accent-color: var(--primary); flex-shrink: 0; }
.unit-check-item.checked { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }

.copy-mode-row { display: flex; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.copy-mode-opt {
  display: flex; align-items: center; gap: .45rem;
  padding: .45rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: .875rem; font-weight: 500;
  transition: background .12s, border-color .12s;
}
.copy-mode-opt:has(input:checked) { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }
.copy-mode-opt input[type=radio] { accent-color: var(--primary); }

/* Search-filter for unit grid */
.unit-search { margin-bottom: .6rem; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); }
.login-card { width: 100%; max-width: 380px; }
.login-title { font-size: 1.5rem; font-weight: 800; text-align: center; margin-bottom: 1.5rem; color: var(--text); }

/* ── Photo gallery ── */
.photo-gallery {
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}
.photo-item { display: flex; flex-direction: column; align-items: center; width: 128px; }
.photo-thumb {
  width: 128px; height: 128px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: opacity .15s, transform .15s, border-color .15s, box-shadow .15s;
}
.photo-thumb:hover {
  opacity: .95; transform: scale(1.03);
  border-color: var(--primary);
  box-shadow: 0 4px 12px var(--primary-glow);
}
.photo-caption { font-size: .72rem; color: var(--muted); margin-top: .3rem; text-align: center; max-width: 128px; overflow-wrap: break-word; }

/* ── Upload section ── */
.photo-upload-section {
  border-top: 1px solid var(--border);
  padding: .85rem 1.25rem;
  background: var(--surface-2);
}
.upload-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.upload-label {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .85rem;
  border: 2px dashed var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem; font-weight: 500;
  color: var(--muted);
  transition: border-color .15s, color .15s, background .15s;
  white-space: nowrap;
}
.upload-label:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.upload-icon { font-size: 1.05rem; }

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 2.5rem 1.5rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .95rem; }

/* ── Filter toggles ── */
.filter-toggles {
  display: flex; gap: .35rem; flex-wrap: wrap; align-items: center;
}
.filter-btn {
  padding: .35rem .85rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .82rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Section divider ── */
.section-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted-2);
  margin: 1.5rem 0 .6rem; padding-left: .15rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .container { padding: 1rem .75rem 2.5rem; }
  .page-title { font-size: 1.25rem; }
  a.unit-row, .unit-row { padding: .9rem 1rem; }
  .photo-item { width: 100px; }
  .photo-thumb { width: 100px; height: 100px; }
  .photo-caption { max-width: 100px; }
  .upload-row { flex-direction: column; align-items: flex-start; }
  .upload-row .form-control { max-width: 100% !important; width: 100%; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 34px; }
  .sticky-header { top: var(--nav-h); }
  .action-row { gap: .35rem; }
  .unit-check-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .paint-entry-title { font-size: 1rem; }
}
