@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root,
html[data-theme="dark"] {
  --bg:           #0d1321;
  --surface:      #131c2f;
  --surface2:     #1a2740;
  --surface3:     #23324e;
  --border:       rgba(255,255,255,0.08);
  --text:         #ecf2ff;
  --text-muted:   #9aa7c1;
  --accent:       #4f7cff;
  --accent-hover: #3d67de;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #38bdf8;
  --font:         'Inter', system-ui, sans-serif;
  --radius:       12px;
  --sidebar-w:    260px;
  --topbar-h:     60px;
  --shadow:       0 8px 32px rgba(0,0,0,0.28);
}
html[data-theme="light"] {
  --bg:           #f0f4fb;
  --surface:      #ffffff;
  --surface2:     #f4f7fc;
  --surface3:     #e8eef9;
  --border:       rgba(30,41,59,0.1);
  --text:         #142033;
  --text-muted:   #64748b;
  --accent:       #3157d5;
  --accent-hover: #2848b0;
  --success:      #15803d;
  --warning:      #b45309;
  --danger:       #dc2626;
  --info:         #0284c7;
  --shadow:       0 4px 20px rgba(15,23,42,0.08);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }

/* ── Sidebar ────────────────────────────────────────────── */
.admin-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}

/* Mobile: hidden off-screen by default */
@media (max-width: 900px) {
  .admin-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  .admin-sidebar.open { transform: translateX(0); }
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo-icon,
.user-avatar {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.user-avatar { border-radius: 50%; font-size: 14px; }
.sidebar-logo-text { font-size: 15px; font-weight: 700; line-height: 1.2; }
.sidebar-logo-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.5px; }
.admin-logo-image { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: var(--surface2); padding: 4px; }

/* Close X button — only on mobile */
.sidebar-close-btn {
  margin-left: auto;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  padding: 0;
}
@media (max-width: 900px) {
  .sidebar-close-btn { display: flex; }
}

/* Nav */
.sidebar-nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  padding: 0 10px;
  margin-bottom: 4px;
}
.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.nav-item:hover,
.nav-theme-toggle:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,0.12); color: var(--accent); }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
}

/* Sidebar user footer */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ── Overlay ─────────────────────────────────────────────── */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 199;
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

/* ── Main area ──────────────────────────────────────────── */
.admin-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
@media (max-width: 900px) {
  .admin-main { margin-left: 0; }
}

/* ── Topbar ─────────────────────────────────────────────── */
.admin-topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }
.topbar-title { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Hamburger — only on mobile */
.mobile-menu-btn {
  display: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  align-items: center; justify-content: center;
  font-size: 20px;
  padding: 0;
  flex-shrink: 0;
}
@media (max-width: 900px) {
  .mobile-menu-btn { display: flex; }
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn, .topbar-btn {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover, .topbar-btn:hover { background: var(--surface3); }
.btn-primary, .topbar-btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover, .topbar-btn.primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover);
}
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface2); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn-xs { min-height: 28px; padding: 0 8px; font-size: 11px; border-radius: 6px; }
.btn-icon { width: 38px; padding: 0; }
.btn-block { width: 100%; }

/* ── Content padding ─────────────────────────────────────── */
.admin-content {
  padding: 20px;
  flex: 1;
}
@media (max-width: 600px) {
  .admin-content { padding: 14px; }
  .admin-topbar { padding: 10px 14px; }
}

/* ── Stats grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-change { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}

/* ── Dashboard grid ──────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  gap: 18px;
}
@media (max-width: 1080px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Table card ──────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 18px;
}
.table-card:last-child { margin-bottom: 0; }
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table-title { font-size: 15px; font-weight: 700; }

.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: var(--surface2);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.td-title { font-weight: 600; line-height: 1.3; }
.td-excerpt { color: var(--text-muted); font-size: 11px; margin-top: 3px; }

/* Mobile card-style rows for article list */
@media (max-width: 680px) {
  .table-responsive table,
  .table-responsive thead,
  .table-responsive tbody,
  .table-responsive th,
  .table-responsive td,
  .table-responsive tr {
    display: block;
  }
  .table-responsive thead { display: none; }
  .table-responsive tr {
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .table-responsive tr:last-child { border-bottom: none; }
  .table-responsive td {
    border: none;
    padding: 2px 0;
    font-size: 13px;
  }
  .table-responsive td::before {
    content: attr(data-label) ": ";
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-right: 4px;
  }
  .table-responsive td.no-label::before { content: ""; }
  table { min-width: unset; }
}

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.14); color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,0.12);  color: var(--danger); }
.badge-info    { background: rgba(56,189,248,0.12);  color: var(--info); }

/* ── Forms ───────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.form-card:last-child { margin-bottom: 0; }
.form-card-title {
  font-size: 14px; font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  font-weight: 700;
}
.form-control {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color 0.15s, background 0.15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface3);
}
textarea.form-control { min-height: 80px; resize: vertical; line-height: 1.5; }
.form-hint { color: var(--text-muted); font-size: 11px; margin-top: 4px; }
.select-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239aa7c1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Layout for article-edit: main + sidebar */
.edit-layout {
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .edit-layout { grid-template-columns: 1fr; }
}

/* Settings layout */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
}

/* ── Toggle switch ───────────────────────────────────────── */
.form-check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.form-check input[type="checkbox"] { display: none; }
.toggle {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--surface3);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.toggle::after {
  content: '';
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px; left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.form-check input:checked + .toggle,
.form-check input:checked ~ .toggle { background: var(--accent); }
.form-check input:checked + .toggle::after,
.form-check input:checked ~ .toggle::after { transform: translateX(18px); }
.form-check-label { font-size: 13px; font-weight: 500; }

/* ── Image upload ────────────────────────────────────────── */
.img-upload-area {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.img-upload-area:hover { border-color: var(--accent); background: rgba(79,124,255,0.05); }
.img-upload-area input[type="file"] { display: none; }
.img-upload-icon { font-size: 28px; margin-bottom: 6px; }
.img-upload-text { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.img-upload-hint { color: var(--text-muted); font-size: 11px; }

/* Settings media preview */
.settings-media-preview {
  min-height: 120px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
  overflow: hidden;
}
.settings-media-preview img { width: 100%; height: 100%; object-fit: contain; padding: 14px; }
.settings-favicon-preview { min-height: 100px; max-width: 120px; }

/* ── Alert ───────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}
.alert-success { background: rgba(16,185,129,0.12); color: var(--success); border-color: rgba(16,185,129,0.2); }
.alert-danger  { background: rgba(239,68,68,0.12);  color: var(--danger);  border-color: rgba(239,68,68,0.2); }

/* ── Login page ──────────────────────────────────────────── */
.admin-login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.admin-login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
@media (max-width: 460px) {
  .admin-login-card { padding: 24px 18px; border-radius: 14px; }
}
.admin-login-logo { width: 64px; height: 64px; object-fit: contain; margin: 0 auto 14px; }
.admin-login-mark {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
  margin: 0 auto 14px;
}

/* ── Quick links / sidebar widget ───────────────────────── */
.quick-links { display: flex; flex-direction: column; gap: 7px; padding: 16px; }

/* ── Trending / top list ─────────────────────────────────── */
.top-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.top-item:last-child { border-bottom: none; }
.top-num { font-size: 20px; font-weight: 900; color: var(--surface3); min-width: 28px; }
.top-title { font-size: 12px; font-weight: 600; line-height: 1.4; }
.top-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Pagination ──────────────────────────────────────────── */
.admin-pagination {
  display: flex; gap: 5px; flex-wrap: wrap;
  justify-content: center;
  padding: 16px;
  border-top: 1px solid var(--border);
}
.page-btn {
  min-width: 34px; height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  cursor: pointer;
}
.page-btn.active, .page-btn:hover {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* ── Rich text editor area ───────────────────────────────── */
.editor-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
}
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface3);
}
.editor-toolbar button {
  min-height: 30px; padding: 0 8px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text);
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.editor-toolbar button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Search / filter row ─────────────────────────────────── */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filter-bar .form-control { min-height: 38px; }
@media (max-width: 560px) {
  .filter-bar { flex-direction: column; }
  .filter-bar .form-control, .filter-bar .btn { width: 100%; }
}

/* ── Mobile action row below topbar ──────────────────────── */
.mobile-actions {
  display: none;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  background: var(--surface);
}
@media (max-width: 540px) {
  .mobile-actions { display: flex; flex-wrap: wrap; }
  .topbar-actions { display: none; }
}

/* ── Utility ─────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-col { flex-direction: column; }
