/* ===== HD BLOG ADMIN PANEL — DESIGN SYSTEM ===== */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #0058CD;
  --primary-light: #3B82F6;
  --primary-dark: #003A8C;
  --accent: #00D4FF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --surface2: #F8FAFC;
  --border: #E2E8F0;
  --text: #1E293B;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --sidebar-w: 240px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Sarabun', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

/* ===== LAYOUT ===== */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar__logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar__logo img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  padding: 4px;
}

.sidebar__logo-text h1 {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar__logo-text span {
  font-size: 0.72rem;
  opacity: 0.7;
}

.sidebar__nav {
  flex: 1;
  padding: 16px 0;
  overflow-y: auto;
}

.sidebar__section {
  padding: 8px 12px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.5;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 0.88rem;
  font-weight: 500;
  color: rgba(255,255,255,0.8);
  transition: all 0.2s;
  border-radius: 0;
  cursor: pointer;
}

.sidebar__link:hover,
.sidebar__link.active {
  background: rgba(255,255,255,0.12);
  color: white;
}

.sidebar__link.active {
  border-left: 3px solid var(--accent);
  padding-left: 17px;
}

.sidebar__link .icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar__footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sidebar__avatar {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary-dark);
  flex-shrink: 0;
}

.sidebar__user-info p { font-size: 0.82rem; font-weight: 600; }
.sidebar__user-info span { font-size: 0.7rem; opacity: 0.6; }

.btn-logout {
  width: 100%;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  color: white;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
}

.btn-logout:hover { background: rgba(239,68,68,0.3); }

/* ===== MAIN CONTENT ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.topbar__actions { display: flex; align-items: center; gap: 12px; }

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--text);
  padding: 4px;
}

/* ===== PAGE CONTENT ===== */
.page-content {
  padding: 28px 24px;
  flex: 1;
}

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-sm { padding: 16px 20px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.blue { background: #EFF6FF; }
.stat-icon.green { background: #ECFDF5; }
.stat-icon.amber { background: #FFFBEB; }
.stat-icon.purple { background: #F5F3FF; }

.stat-info p { font-size: 0.78rem; color: var(--text-muted); }
.stat-info h3 { font-size: 1.6rem; font-weight: 700; line-height: 1; margin-top: 2px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,88,205,0.3); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #059669; }

.btn-danger { background: #FEE2E2; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,88,205,0.1);
}

.form-textarea { min-height: 100px; resize: vertical; }

/* ===== TABLE ===== */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead tr { background: var(--surface2); }

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

tbody tr:hover { background: var(--surface2); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-published { background: #DCFCE7; color: #16A34A; }
.badge-draft { background: #FEF9C3; color: #A16207; }
.badge-admin { background: #EFF6FF; color: var(--primary); }
.badge-editor { background: #F5F3FF; color: #7C3AED; }

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: #FEE2E2; color: #DC2626; border: 1px solid #FECACA; }
.alert-success { background: #DCFCE7; color: #16A34A; border: 1px solid #BBF7D0; }
.alert-info { background: #EFF6FF; color: var(--primary); border: 1px solid #BFDBFE; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, #0077CC 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  background: var(--primary-dark);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 12px;
}

.login-logo h1 { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.login-logo p { font-size: 0.85rem; color: var(--text-muted); }

/* ===== EDITOR ===== */
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.editor-toolbar button {
  padding: 6px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all 0.15s;
  font-family: inherit;
}

.editor-toolbar button:hover,
.editor-toolbar button.active {
  background: var(--border);
  color: var(--text);
}

.editor-toolbar .sep {
  width: 1px;
  background: var(--border);
  margin: 2px 4px;
}

#editor-content {
  min-height: 320px;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: 0 0 8px 8px;
  outline: none;
  font-size: 0.9rem;
  line-height: 1.7;
}

#editor-content:focus { border-color: var(--primary); }

#editor-content img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
#editor-content h2, #editor-content h3 { margin: 16px 0 8px; }
#editor-content p { margin-bottom: 12px; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: white;
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--bg); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.875rem; }

/* ===== LOADING ===== */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }

  .sidebar-overlay.show { display: block; }

  .main { margin-left: 0; }

  .hamburger { display: flex; }

  .page-content { padding: 16px; }

  .topbar { padding: 0 16px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  table { font-size: 0.8rem; }
  th, td { padding: 10px 12px; }

  .btn { padding: 8px 14px; font-size: 0.82rem; }

  .login-card { padding: 28px 20px; }

  .card { padding: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; }
  .stat-info h3 { font-size: 1.3rem; }
}
