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

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 150ms ease;

  /* Dark theme (default) */
  --bg: #0f1117;
  --surface: #1a1d27;
  --text: #e4e5e9;
  --text-muted: #9ca3af;
  --text-light: #6b7280;
  --border: #2d3142;
  --border-light: #232636;
  --nav-bg: #0b0d14;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: rgba(129, 140, 248, 0.12);
  --danger: #f87171;
  --danger-hover: #ef4444;
  --success-bg: rgba(16, 185, 129, 0.12);
  --success-text: #6ee7b7;
  --error-bg: rgba(248, 113, 113, 0.12);
  --error-text: #fca5a5;
  --public-bg: rgba(16, 185, 129, 0.12);
  --public-text: #6ee7b7;
  --internal-bg: rgba(96, 165, 250, 0.12);
  --internal-text: #93c5fd;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --nav-bg: #1a1a2e;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --public-bg: #ecfdf5;
  --public-text: #065f46;
  --internal-bg: #eff6ff;
  --internal-text: #1e40af;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ──────────────────────────────── */
.nav {
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
}

/* ── Layout ──────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page {
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-title {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
  color: var(--text);
}

.section {
  margin-top: 2.5rem;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
}

/* ── Cards ───────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  transition: box-shadow var(--transition);
}

.card-header {
  margin-bottom: 1rem;
}

/* ── Post Cards ──────────────────────────────── */
.post-card {
  transition: box-shadow var(--transition), transform var(--transition);
}

.post-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.post-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.375rem;
}

.post-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.post-date {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.post-content {
  white-space: pre-wrap;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.post-actions {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-public {
  background: var(--public-bg);
  color: var(--public-text);
}

.badge-internal {
  background: var(--internal-bg);
  color: var(--internal-text);
}

/* ── Tags ────────────────────────────────────── */
.tag {
  display: inline-block;
  background: var(--border-light);
  color: var(--text-muted);
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ── Images Grid ─────────────────────────────── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.grid-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
}

.grid-image:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
}

/* ── Forms ────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.5625rem 0.75rem;
  margin-top: 0.375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-family: var(--font);
  font-weight: 400;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input::placeholder {
  color: var(--text-light);
}

.form-textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.6;
}

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
}

.btn-secondary {
  background: var(--border-light);
  color: var(--text-muted);
  text-decoration: none;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}

.btn-block {
  width: 100%;
  padding: 0.625rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ── Auth Page ───────────────────────────────── */
.auth-page {
  display: flex;
  justify-content: center;
  padding-top: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-tabs {
  display: flex;
  margin: -1.5rem -1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  padding: 0.875rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition), border-color var(--transition);
}

.auth-tab:first-child {
  border-top-left-radius: var(--radius);
}

.auth-tab:last-child {
  border-top-right-radius: var(--radius);
}

.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.auth-tab:hover:not(.active) {
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
}

/* ── Messages ────────────────────────────────── */
.error-msg {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.success-msg {
  background: var(--success-bg);
  color: var(--success-text);
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ── Loading & Empty ─────────────────────────── */
.loading {
  color: var(--text-light);
  padding: 3rem 0;
  text-align: center;
  font-size: 0.9375rem;
}

.empty {
  color: var(--text-light);
  text-align: center;
  padding: 2rem 0;
  font-size: 0.9375rem;
}

/* ── Tabs ────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition), border-color var(--transition);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab:hover:not(.active) {
  color: var(--text);
}

/* ── Tables ──────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin: 0 -1.5rem;
  padding: 0 1.5rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
}

.table-input {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding: 0.375rem 0.5rem;
  font-size: 0.875rem;
}

.actions {
  white-space: nowrap;
  width: 1%;
}

.actions .btn + .btn {
  margin-left: 0.375rem;
}

.mono {
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, monospace;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--border-light);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
}

/* ── Theme Toggle ────────────────────────────── */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.125rem;
  line-height: 1;
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  display: flex;
  align-items: center;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 640px) {
  .container {
    padding: 1.25rem 1rem 3rem;
  }

  .nav-inner {
    padding: 0 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .auth-tabs {
    margin: -1.25rem -1.25rem 1.25rem;
  }

  .table-wrap {
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
  }

  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .post-thumbnails {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }

  .image-uploader-preview {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .lightbox-image {
    max-width: 95vw;
    max-height: 75vh;
  }

  .lightbox-desktop-nav {
    display: none;
  }

  .lightbox-bottom-nav {
    display: flex;
  }

  .lightbox-bottom-nav .lightbox-nav {
    position: static;
    transform: none;
    width: 48px;
    height: 48px;
    font-size: 2rem;
  }

  .lightbox-bottom-nav .lightbox-counter {
    position: static;
    transform: none;
  }
}

/* Post primary image */
.post-primary-image {
  width: 100%;
  max-height: 500px;
  object-fit: cover;
  border-radius: 8px 8px 0 0;
  margin-bottom: 1rem;
  cursor: pointer;
}

/* Post thumbnails grid */
.post-thumbnails {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
  margin: 1rem 0;
}

.post-thumbnail {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
}

.post-thumbnail:hover {
  opacity: 0.85;
  transform: scale(1.03);
}

@media (hover: none) {
  .post-thumbnail:hover {
    opacity: 1;
    transform: none;
  }

  .post-thumbnail:active {
    opacity: 0.7;
  }
}

/* Lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  font-size: 1.25rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  font-size: 2.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  line-height: 1;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.25);
}

.lightbox-nav-left {
  left: 1rem;
}

.lightbox-nav-right {
  right: 1rem;
}

.lightbox-bottom-nav {
  display: none;
  gap: 2rem;
  align-items: center;
}

.lightbox-counter {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
}

/* Image uploader */
.image-uploader {
  margin: 0.5rem 0;
}

.upload-status {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.image-uploader-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.image-uploader-item {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
  transition: border-color 0.2s;
}

.image-uploader-primary {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.image-uploader-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.image-uploader-controls {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.image-uploader-radio {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-danger {
  background: #dc3545;
  color: #fff;
  border: none;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}

.btn-danger:hover {
  background: #c82333;
}
