/* public/css/admin.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #f5f6fa;
  --surface: #ffffff;
  --fg:      #1a1a1a;
  --muted:   #666;
  --accent:  #0066cc;
  --danger:  #dc3545;
  --border:  #e0e0e0;
  --nav-bg:  #1e2128;
  --nav-fg:  #c9cdd6;
  --radius:  6px;
  --font:    -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:    'Fira Code', 'Courier New', monospace;
}

body { font-family: var(--font); background: var(--bg); color: var(--fg); }

/* Nav */
.admin-nav {
  background: var(--nav-bg);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  height: 52px;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.admin-logo { color: #fff; font-weight: 700; text-decoration: none; font-size: 1rem; white-space: nowrap; }
.admin-nav-site-link {
  display: inline-flex; align-items: center; gap: .3rem;
  color: rgba(255,255,255,.55); text-decoration: none; font-size: .75rem;
  border: 1px solid rgba(255,255,255,.2); border-radius: 5px;
  padding: .2rem .55rem; transition: all .15s; white-space: nowrap;
}
.admin-nav-site-link:hover { color: #fff; border-color: rgba(255,255,255,.5); background: rgba(255,255,255,.08); }
.admin-nav-links { display: flex; gap: 1.25rem; align-items: center; flex: 1; }
.admin-nav-links a { color: var(--nav-fg); text-decoration: none; font-size: .875rem; }
.admin-nav-links a:hover { color: #fff; }
.admin-nav-links .logout { margin-left: auto; color: #f87171; }

/* Main content */
.admin-main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.admin-main h1 { font-size: 1.5rem; margin-bottom: 1.5rem; }

/* Flash */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: #d4edda; color: #155724; }
.flash-error   { background: #f8d7da; color: #721c24; }

/* Buttons */
.btn { display: inline-block; padding: .45rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--fg); cursor: pointer; font-size: .875rem; text-decoration: none; transition: background .15s; }
.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #0052a3; }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b02a37; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* Table actions row */
.table-actions { margin-bottom: 1rem; }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.admin-table th { background: #f8f9fa; text-align: left; padding: .75rem 1rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--border); }
.admin-table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr.pending td { background: #fffbf0; }
.actions { display: flex; gap: .4rem; align-items: center; }

/* Badges */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge-published { background: #d4edda; color: #155724; }
.badge-draft     { background: #fff3cd; color: #856404; }

/* Dashboard stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1.25rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,.07); display: flex; flex-direction: column; gap: .4rem; }
.stat-number { font-size: 2.25rem; font-weight: 700; color: var(--accent); }
.stat-label  { color: var(--muted); font-size: .85rem; }
.stat-card a { font-size: .8rem; color: var(--accent); text-decoration: none; }

/* Quick actions */
.quick-actions { background: var(--surface); padding: 1.25rem; border-radius: var(--radius); box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.quick-actions h2 { font-size: 1rem; margin-bottom: .75rem; }
.quick-actions { display: flex; flex-direction: column; gap: .75rem; }
.quick-actions > div, .quick-actions > * { /* flex children */ }

/* Post form */
.post-form .form-row { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; align-items: start; }
.form-col-side { display: flex; flex-direction: column; gap: 1rem; }
.side-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.side-box h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .75rem; }
.form-label { display: flex; flex-direction: column; gap: .3rem; font-size: .875rem; margin-bottom: .75rem; }
.form-input { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; font-size: .9rem; font-family: var(--font); width: 100%; }
.form-input:focus { outline: none; border-color: var(--accent); }
.code-editor { font-family: var(--mono); font-size: .85rem; resize: vertical; min-height: 480px; }
.form-actions { display: flex; gap: .5rem; margin-top: .75rem; justify-content: flex-end; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: .875rem; margin-bottom: .4rem; cursor: pointer; }

/* Media grid */
.upload-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.5rem; display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.upload-box label { display: flex; flex-direction: column; gap: .3rem; font-size: .875rem; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.media-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.media-item img { width: 100%; height: 120px; object-fit: cover; display: block; }
.media-icon { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; background: #f8f9fa; }
.media-info { padding: .6rem; display: flex; flex-direction: column; gap: .4rem; }
.media-filename { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Inline form (categories/tags) */
.inline-form { display: flex; gap: .75rem; margin-bottom: 1.25rem; }
.inline-form input { border: 1px solid var(--border); border-radius: var(--radius); padding: .45rem .75rem; font-size: .9rem; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-form { background: var(--surface); padding: 2.5rem; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.1); width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; }
.login-form h1 { font-size: 1.4rem; text-align: center; margin-bottom: .5rem; }
.login-form label { display: flex; flex-direction: column; gap: .35rem; font-size: .875rem; }
.login-form input { border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .8rem; font-size: .95rem; }
.login-form button { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: .65rem; font-size: 1rem; cursor: pointer; }

/* Dashboard grid */
.dashboard-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 1.25rem; align-items: start; }
.recent-posts-box h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .75rem; }
.quick-actions h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .75rem; }
.quick-actions { display: flex; flex-direction: column; gap: .5rem; }
@media (max-width: 700px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* Users page */
.users-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; align-items: start; }
.current-user td { background: #f0f7ff; }
@media (max-width: 700px) { .users-grid { grid-template-columns: 1fr; } }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal-box { background: var(--surface); border-radius: 10px; padding: 1.75rem; width: 100%; max-width: 380px; box-shadow: 0 8px 40px rgba(0,0,0,.2); }
.modal-box h3 { font-size: 1rem; margin-bottom: 1rem; }

/* Bulk action bar */
.bulk-bar { display: flex; align-items: center; gap: 1rem; background: #fff3cd; border: 1px solid #ffc107; border-radius: var(--radius); padding: .6rem 1rem; margin-top: .75rem; }

/* Featured image picker */
.featured-preview { margin-bottom: .5rem; }
.featured-preview img { width: 100%; border-radius: var(--radius); display: block; }
.media-picker { margin-top: .75rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; max-height: 260px; overflow-y: auto; }
.media-picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.media-picker-item { cursor: pointer; border-radius: 4px; overflow: hidden; border: 2px solid transparent; }
.media-picker-item img { width: 100%; height: 60px; object-fit: cover; display: block; }
.media-picker-item:hover { border-color: var(--accent); }
.media-picker-item.selected { border-color: var(--accent); }
.mt-sm { margin-top: .5rem; }
.hidden { display: none !important; }

/* Muted text */
.muted { color: var(--muted); font-size: .85rem; }
code { font-family: var(--mono); background: #f4f4f4; padding: .1em .35em; border-radius: 3px; font-size: .85em; }

@media (max-width: 768px) {
  .post-form .form-row { grid-template-columns: 1fr; }
  .admin-nav-links { gap: .75rem; }
}

/* ═══════════════════════════════════════════════
   Settings page
   ═══════════════════════════════════════════════ */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* Sidebar */
.settings-sidebar {
  position: sticky;
  top: 68px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.settings-nav {
  display: flex;
  flex-direction: column;
  padding: .5rem;
  gap: 2px;
}
.snav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem .9rem;
  border-radius: 7px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: .875rem;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
  width: 100%;
}
.snav-item svg { flex-shrink: 0; opacity: .7; }
.snav-item:hover { background: var(--bg); color: var(--fg); }
.snav-item.active {
  background: #e8f0fe;
  color: var(--accent);
  font-weight: 600;
}
.snav-item.active svg { opacity: 1; }

.settings-save-sidebar {
  border-top: 1px solid var(--border);
  padding: .85rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.btn-save {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  padding: .6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: .875rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-save:hover { opacity: .88; }
.settings-preview-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--muted);
  text-decoration: none;
  padding: .3rem;
}
.settings-preview-link:hover { color: var(--accent); }

/* Panel */
.settings-content {
  min-width: 0;
}
.settings-panel { display: none; }
.settings-panel.active { display: block; }

.settings-panel-header {
  padding-bottom: 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.settings-panel-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 .3rem;
}
.settings-panel-header p {
  font-size: .875rem;
  color: var(--muted);
  margin: 0;
}

/* Fields */
.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.sfield {
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.sfield label {
  font-size: .825rem;
  font-weight: 600;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.sfield input[type="text"],
.sfield input[type="url"],
.sfield input[type="email"],
.sfield textarea {
  width: 100%;
  padding: .55rem .85rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .9rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--fg);
  transition: border-color .15s, box-shadow .15s;
}
.sfield input:focus,
.sfield textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,.1);
}
.sfield textarea { resize: vertical; }
.sfield-hint {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.4;
}
.sfield-hint code {
  background: #f0f0f0;
  padding: .1em .4em;
  border-radius: 4px;
  font-size: .85em;
}
.sfield-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .25rem 0 -.25rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.sfield-divider::before, .sfield-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Theme cards */
.theme-cards {
  display: flex;
  gap: 1rem;
}
.theme-card {
  cursor: pointer;
}
.theme-card input { display: none; }
.theme-card-preview {
  width: 130px;
  height: 88px;
  border-radius: 8px;
  border: 2px solid var(--border);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
}
.theme-card input:checked + .theme-card-preview {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,.12);
}
.theme-card:hover .theme-card-preview { border-color: #bbb; }
.dark-preview  { background: #0d0f14; }
.light-preview { background: #f5f5f0; }
.tp-bar {
  height: 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.dark-preview  .tp-bar  { background: #13161e; }
.light-preview .tp-bar  { background: #fff; border-color: rgba(0,0,0,.08); }
.tp-content { padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }
.tp-line { height: 7px; border-radius: 4px; }
.dark-preview  .tp-line { background: rgba(255,255,255,.12); }
.light-preview .tp-line { background: rgba(0,0,0,.12); }
.tp-line.long  { width: 75%; }
.tp-line.short { width: 45%; }
.theme-card-label {
  display: block;
  text-align: center;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: .5rem;
}
.theme-card input:checked ~ .theme-card-label { color: var(--accent); }

/* Accent color */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.color-swatch-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
}
.color-swatch-wrap input[type="color"] {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  opacity: 0;
  cursor: pointer;
  border: none;
}
.color-swatch-bg {
  position: absolute;
  inset: 0;
  border-radius: 7px;
  pointer-events: none;
}
.hex-input {
  width: 96px !important;
  font-family: 'Fira Code', monospace !important;
  font-size: .85rem !important;
  text-transform: uppercase;
  padding: .45rem .7rem !important;
  letter-spacing: .04em;
}
.color-presets {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}
.preset {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  padding: 0;
}
.preset:hover { transform: scale(1.25); border-color: rgba(0,0,0,.2); }

/* Profile photo */
.profile-photo-row {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}
.profile-photo-thumb {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.profile-photo-thumb.hidden { display: none; }

/* Social fields in 2-col grid on wider screens */
.social-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.social-sfield { margin: 0; }

/* Custom CSS textarea */
.css-editor {
  width: 100%;
  font-family: 'Fira Code', 'Courier New', monospace !important;
  font-size: .82rem !important;
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .85rem 1rem;
  resize: vertical;
  color: #1a1a1a;
  line-height: 1.65;
  min-height: 360px;
}
.css-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,.1);
}

/* Nav builder rows */
.nav-builder { display: flex; flex-direction: column; gap: .4rem; }
.nav-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr auto;
  gap: .5rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .65rem;
  transition: background .15s;
}
.nav-row.dragging { opacity: .45; }
.nav-row:hover { background: #fafafa; }
.drag-handle {
  color: var(--muted);
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 .15rem;
  opacity: .5;
}
.drag-handle:hover { opacity: 1; }
.nav-row input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .4rem .65rem;
  font-size: .875rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}
.nav-row input:focus { outline: none; border-color: var(--accent); }
.nav-row .nav-label { }
.nav-row .nav-url   { font-family: 'Fira Code', monospace; font-size: .8rem; }
.nav-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .12s, border-color .12s, background .12s;
}
.nav-del:hover { color: var(--danger); border-color: var(--danger); background: #fff5f5; }
.btn-add-row {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem .9rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: .85rem;
  font-family: var(--font);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  margin-top: .25rem;
}
.btn-add-row:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: #f0f5ff;
}
.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem .9rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: none;
  color: var(--fg);
  font-size: .875rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
}
.btn-outline:hover { background: var(--bg); }

@media (max-width: 860px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-sidebar { position: static; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; }
  .snav-item { flex: 0 0 auto; }
  .social-fields { grid-template-columns: 1fr; }
  .theme-cards { flex-wrap: wrap; }
}
