/* ══════════════════════════════════════════════════════════════
   Admin Dashboard — Sidebar Layout
   ══════════════════════════════════════════════════════════════ */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-light: #eff6ff;
  --brand-dark: #1d4ed8;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.05), 0 2px 4px rgba(0,0,0,.03);
  --transition: .2s ease;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
  font-size: 1rem;
  color: var(--brand);
  letter-spacing: -.02em;
}

.sidebar-brand svg {
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
}

.nav-section-label {
  padding: .5rem 1.5rem .25rem;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem 1.5rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--brand-light);
  color: var(--brand);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .7;
}

.nav-item.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--muted);
  padding: .35rem 0;
  transition: color var(--transition);
}

.sidebar-footer a:hover {
  color: var(--brand);
  text-decoration: none;
}

.sidebar-footer a svg {
  width: 16px;
  height: 16px;
}

/* ── Main content area ─────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

.topbar h1 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem;
  cursor: pointer;
  color: var(--text);
}

.content-wrap {
  padding: 2rem;
  max-width: 100%;
}

/* ── Section panels ────────────────────────────────────────── */

.cms-section {
  display: none;
  animation: fadeIn .25s ease;
}

.cms-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-header {
  margin-bottom: 1.5rem;
}

.section-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 .25rem;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  font-size: .875rem;
}

/* ── Cards ─────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: .95rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}

.card-title svg {
  width: 18px;
  height: 18px;
  color: var(--brand);
}

/* ── Forms ──────────────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
}

.form-group input,
.form-group textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .75rem;
  font: inherit;
  font-size: .875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--surface);
  margin: 0;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group input[type="file"] {
  padding: .5rem;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.form-group input[type="file"]:hover {
  border-color: var(--brand);
  background: var(--brand-light);
}

.form-group input[type="file"]::file-selector-button {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: .4rem .8rem;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  margin-right: .75rem;
  transition: background var(--transition);
}

.form-group input[type="file"]::file-selector-button:hover {
  background: var(--brand-dark);
}

.form-actions {
  margin-top: 1.25rem;
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
}

.form-actions-centered {
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.form-actions-centered .btn {
  flex: 0 0 auto;
  width: auto;
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: none;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  font-weight: 600;
  font-size: .8rem;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.btn:active {
  transform: scale(.97);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #fee2e2;
}

.btn-sm {
  padding: .35rem .7rem;
  font-size: .75rem;
}

/* ── Table ──────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .85rem;
}

.data-table thead th {
  background: var(--bg);
  padding: .65rem .75rem;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.data-table thead th:first-child {
  border-radius: 8px 0 0 0;
}

.data-table thead th:last-child {
  border-radius: 0 8px 0 0;
}

.data-table tbody td {
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table .col-action {
  width: 80px;
  text-align: center;
}

.drag-handle-cell {
  width: 32px;
  text-align: center;
  padding: 0 !important;
}

.row-drag-handle {
  display: inline-block;
  padding: .35rem .5rem;
  color: var(--muted);
  cursor: grab;
  font-size: 1rem;
  opacity: 0;
  transition: opacity .15s;
  user-select: none;
}

.data-table tbody tr:hover .row-drag-handle {
  opacity: 1;
}

.sortable-row-ghost {
  opacity: .35;
  background: var(--brand-soft) !important;
}

.sortable-row-chosen {
  background: #f0f6ff !important;
  cursor: grabbing;
}

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: .875rem;
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: .5rem;
  opacity: .4;
}

/* ── Notice / Toast ────────────────────────────────────────── */

.notice {
  padding: .75rem 1rem;
  border: 1px solid var(--success-border);
  background: var(--success-bg);
  border-radius: var(--radius);
  color: var(--success);
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.notice svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Stats row ─────────────────────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 0 0 .25rem;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  margin: 0;
  color: var(--text);
}

/* ── Auth / Login ──────────────────────────────────────────── */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: linear-gradient(135deg, #eff6ff 0%, #f1f5f9 50%, #faf5ff 100%);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.auth-card h1 {
  margin: 0 0 .3rem;
  font-size: 1.5rem;
}

.hint {
  margin: .2rem 0 1rem;
  color: var(--muted);
  font-size: .85rem;
}

.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: .65rem .85rem;
  font-size: .85rem;
  font-weight: 500;
  margin-bottom: .75rem;
}

label {
  display: block;
  margin: 0 0 .8rem;
  font-weight: 600;
  font-size: .85rem;
  color: var(--text-secondary);
}

input,
textarea {
  width: 100%;
  margin-top: .3rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: .6rem .75rem;
  font: inherit;
  font-size: .875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

button {
  background: var(--brand);
  border: 0;
  color: white;
  border-radius: 8px;
  padding: .65rem 1.25rem;
  font-weight: 700;
  font-size: .875rem;
  cursor: pointer;
  transition: background var(--transition);
  width: 100%;
}

button:hover {
  background: var(--brand-dark);
}

/* ── Gallery preview grid ──────────────────────────────────── */

.gallery-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}

.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 1;
  cursor: grab;
}

.gallery-item.sortable-ghost {
  opacity: .35;
  border: 2px dashed var(--accent);
}

.gallery-item.sortable-chosen {
  box-shadow: 0 8px 20px rgba(0,0,0,.2);
  cursor: grabbing;
}

.drag-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 10;
  background: rgba(0,0,0,.5);
  color: #fff;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  cursor: grab;
  opacity: 0;
  transition: opacity .15s;
  line-height: 1;
}

.gallery-item:hover .drag-handle {
  opacity: 1;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item .overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.gallery-item:hover .overlay {
  opacity: 1;
}

.gallery-item .caption-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .4rem .5rem;
  font-size: .7rem;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}

/* ── Mobile Overlay ────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 90;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-content {
    margin-left: 0;
  }

  .hamburger {
    display: flex;
  }

  .content-wrap {
    padding: 1.25rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }
}

/* Full width card for artikel CMS page on desktop */
@media (min-width: 1024px) {
  .card {
    width: 100%;
    max-width: none;
    box-sizing: border-box;
  }
}

/* ── Analytics Dashboard ──────────────────────────────────── */

.analytics-trend-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .35rem .7rem;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
}

.analytics-trend-badge.trend-up {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

.analytics-trend-badge.trend-down {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

#sec-analytics .stat-card {
  transition: transform .15s ease, box-shadow .15s ease;
}

#sec-analytics .stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

#sec-analytics canvas {
  max-width: 100%;
}

#sec-analytics .btn {
  width: auto;
}

@media (max-width: 768px) {
  #sec-analytics .stats-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 480px) {
  #sec-analytics .stats-row {
    grid-template-columns: 1fr !important;
  }
}
