/* ── Fonts ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap');

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

:root {
  --bg:           #f7f5f0;
  --surface:      #ffffff;
  --surface2:     #f0ede6;
  --border:       #e0dcd4;
  --border-dark:  #c8c4bc;
  --amber:        #b8860b;
  --amber-light:  #d4a020;
  --amber-bg:     #fdf8ee;
  --text:         #1a1814;
  --text-muted:   #6b6760;
  --text-faint:   #a09c98;
  --green:        #2d6a2d;
  --green-bg:     #f0f8f0;
  --red:          #b91c1c;
  --red-bg:       #fef2f2;
  --blue:         #1e40af;
  --blue-bg:      #eff6ff;
  --radius:       6px;
  --shadow:       0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
}

html { font-size: 15px; }

body {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.nav-logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  flex: 1;
}
.nav-logo:hover { text-decoration: none; color: var(--amber); }
.nav-links { display: flex; align-items: center; gap: 12px; }
.nav-user {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0 8px;
  border-right: 1px solid var(--border);
}
.nav-logout {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.nav-logout:hover { color: var(--red); text-decoration: none; }

/* ── Main content ───────────────────────────────────────── */
.main-content { max-width: 1400px; margin: 0 auto; padding: 2rem; }

/* ── Flash messages ─────────────────────────────────────── */
.flash-container { margin-bottom: 1.5rem; }
.flash {
  background: var(--amber-bg);
  border: 1px solid #e8c84a;
  border-left: 4px solid var(--amber);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); text-decoration: none; }
.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}
.btn-primary:hover { background: var(--amber-light); border-color: var(--amber-light); }
.btn-danger { color: var(--red); border-color: #fca5a5; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-link {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  text-decoration: underline;
}
.btn-link:hover { color: var(--amber); }
.btn-link-danger:hover { color: var(--red); }
.inline-form { display: inline; }

/* ── Login page ─────────────────────────────────────────── */
.login-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2.5rem;
  width: 380px;
  box-shadow: var(--shadow-md);
}
.login-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  margin-bottom: 4px;
  color: var(--text);
}
.login-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.8rem;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 1.2rem; }
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text);
}
.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.8rem;
  display: block;
  margin-top: 2px;
}
.required { color: var(--red); }
input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.12s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(184,134,11,0.1);
}
textarea { resize: vertical; }
textarea.mono { font-family: 'IBM Plex Mono', monospace; font-size: 0.82rem; }
input[type="file"] {
  padding: 6px;
  border: 1px dashed var(--border-dark);
  cursor: pointer;
}
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 1.5rem; }
.form-layout { max-width: 780px; }
.form-layout.narrow { max-width: 500px; }

/* ── Page header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.8rem;
  flex-wrap: wrap;
}
.page-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.2;
}
.page-sub { color: var(--text-muted); margin-top: 4px; font-size: 0.9rem; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Breadcrumb ─────────────────────────────────────────── */
.breadcrumb {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--amber); }
.bc-sep { color: var(--text-faint); }

/* ── Category grid (home page) ──────────────────────────── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.category-card:hover { box-shadow: var(--shadow-md); }
.category-link { display: block; text-decoration: none; color: inherit; flex: 1; }
.category-link:hover { text-decoration: none; }
.category-card-body { padding: 1.2rem; flex: 1; }
.category-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  margin-bottom: 6px;
  color: var(--text);
}
.category-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}
.category-count {
  font-size: 0.78rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.category-actions {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

/* ── Position grid (category page) ─────────────────────── */
.position-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.position-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.position-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--amber);
  text-decoration: none;
}
.pos-thumb {
  aspect-ratio: 4/3;
  overflow: hidden;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.pos-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pos-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.82rem;
}
.pos-card-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.pos-title { font-size: 0.95rem; font-weight: 500; color: var(--text); }
.pos-meta { font-size: 0.78rem; color: var(--text-faint); display: flex; gap: 10px; }
.pos-conclusion-preview { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }

/* ── Position detail layout ─────────────────────────────── */
.position-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

/* ── Section labels ─────────────────────────────────────── */
.section-label {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.section-hint { font-weight: 400; font-size: 0.72rem; text-transform: none; letter-spacing: 0; }

/* ── Verdict box ────────────────────────────────────────── */
.verdict-box {
  background: var(--green-bg);
  border: 1px solid #a7d7a7;
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.4rem;
}
.verdict-box .section-label { color: var(--green); }
.verdict-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-line;
}

/* ── Gallery ────────────────────────────────────────────── */
.gallery-section { margin-bottom: 1.4rem; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.gallery-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.gallery-img-wrap { position: relative; }
.img-number {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 3px;
  z-index: 1;
  letter-spacing: 0.04em;
  pointer-events: none;
}
.gallery-img-wrap a { display: block; }
.gallery-img-wrap img {
  width: 100%;
  display: block;
  transition: opacity 0.15s;
}
.gallery-img-wrap img:hover { opacity: 0.9; }
.img-caption {
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* ── XG Analysis ────────────────────────────────────────── */
.xg-section { margin-bottom: 1.4rem; }
.xg-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ── Initial thinking toggle ────────────────────────────── */
.initial-thinking-box {
  margin-bottom: 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.toggle-thinking {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border: none;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: left;
}
.toggle-thinking:hover { background: var(--border); }
.toggle-label { font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; }
.toggle-icon { font-size: 0.75rem; color: var(--text-faint); }
.thinking-content {
  padding: 1rem 1.2rem;
  font-size: 0.92rem;
  line-height: 1.7;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* ── Image size form in admin ───────────────────────────── */
.size-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.size-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.size-form select { width: auto; padding: 4px 8px; font-size: 0.82rem; }

/* ── Discussion panel ───────────────────────────────────── */
.discussion-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 68px;
  max-height: calc(100vh - 90px);
  overflow: hidden;
}
.discussion-heading {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.comment-count { color: var(--text-faint); }

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--surface2);
}
.filter-label { font-size: 0.75rem; color: var(--text-faint); margin-right: 4px; }
.filter-btn {
  padding: 2px 8px;
  border: 1px solid var(--border-dark);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.1s;
}
.filter-btn:hover, .filter-btn.active {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

/* Comment list */
.comment-list {
  overflow-y: auto;
  flex: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.comment-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.88rem;
  transition: border-color 0.15s;
}
.comment-item.selected {
  border-color: var(--amber);
  background: var(--amber-bg);
}
.comment-item.filtered-out { display: none; }
.comment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.comment-author {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--text);
}
.comment-date {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
}
.comment-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.img-tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--blue-bg);
  border: 1px solid #bfdbfe;
  border-radius: 3px;
  font-size: 0.72rem;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--blue);
  text-decoration: none;
}
.img-tag:hover { background: #dbeafe; text-decoration: none; }
.comment-body { line-height: 1.6; color: var(--text); margin-bottom: 6px; }
.comment-actions { display: flex; gap: 10px; align-items: center; }

/* Tagging UI */
.tag-form.hidden { display: none; }
.tag-form-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.tag-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
}
.tag-checkbox input { cursor: pointer; accent-color: var(--amber); }

/* Bulk tag panel */
.bulk-tag-panel {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  background: var(--surface2);
}
.bulk-tag-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.bulk-count { font-size: 0.78rem; color: var(--text-muted); flex: 1; }
.bulk-images {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.bulk-images.hidden { display: none; }

/* Comment form */
.comment-form-section {
  border-top: 1px solid var(--border);
  padding: 12px;
  background: var(--surface);
}
.comment-form-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.comment-form-section textarea {
  margin-bottom: 8px;
  min-height: 70px;
}

/* ── Position edit form — two column layout ─────────────── */
.pos-edit-form { max-width: 1200px; }

.pos-edit-cols {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 2rem;
  align-items: start;
  margin-bottom: 2rem;
}

.pos-edit-right {
  position: sticky;
  top: 68px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
}

.pos-edit-actions {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Admin image list — horizontal thumbnail strip ──────── */
.existing-images {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  margin-top: 0.5rem;
}
.admin-image-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.admin-image-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: 200px;
  flex-shrink: 0;
}
.admin-img-wrap {
  position: relative;
  width: 100%;
}
.admin-img-wrap img { width: 100%; display: block; }
.admin-img-controls {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.caption-form { display: flex; flex-direction: column; gap: 4px; }
.caption-form input { width: 100%; font-size: 0.8rem; padding: 4px 8px; }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 2rem 0;
}
.empty-state.small { padding: 0.5rem 0; }
.empty-state a { color: var(--amber); }

/* ── Error page ─────────────────────────────────────────── */
.error-page { text-align: center; padding: 5rem 2rem; }
.error-code {
  font-family: 'Playfair Display', serif;
  font-size: 5rem;
  color: var(--text-faint);
  margin-bottom: 1rem;
}
.error-message { color: var(--text-muted); margin-bottom: 2rem; font-size: 1.1rem; }

/* ── Utilities ──────────────────────────────────────────── */
.hidden { display: none !important; }
