:root {
  --admin-primary: #1e3a8a;
  --admin-accent: #2563eb;
  --admin-bg: #f1f5f9;
  --admin-surface: #ffffff;
  --admin-sidebar: #0f172a;
  --admin-border: #e2e8f0;
  --admin-text: #1e293b;
  --admin-muted: #64748b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Sarabun', system-ui, -apple-system, sans-serif;
  background: var(--admin-bg);
  color: var(--admin-text);
  font-size: 15px;
}

.admin-shell {
  display: grid;
  grid-template-columns: 245px 1fr;
  min-height: 100vh;
}

.admin-sidebar {
  background: var(--admin-sidebar);
  color: #cbd5e1;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.08rem;
  padding: 8px 10px 16px;
  border-bottom: 1px solid #1e293b;
  margin-bottom: 12px;
}
.sidebar-brand small {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: #94a3b8;
}
.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}
.sidebar-section {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  padding: 12px 10px 4px;
}
.sidebar-nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 7px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.92rem;
  margin-bottom: 2px;
}
.sidebar-nav a:hover { background: #1e293b; color: #fff; }
.sidebar-nav a.active { background: var(--admin-accent); color: #fff; font-weight: 600; }

.admin-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.admin-topbar {
  background: var(--admin-surface);
  border-bottom: 1px solid var(--admin-border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.admin-topbar h1 { margin: 0; font-size: 1.25rem; }
.admin-user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.admin-content {
  padding: 22px 24px;
  max-width: 1280px;
  width: 100%;
}

.card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}
.card h2, .card h3 { margin-top: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card .label { color: var(--admin-muted); font-size: 0.85rem; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; color: var(--admin-primary); margin-top: 4px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--admin-border);
  text-align: left;
  vertical-align: middle;
}
.table th { background: #f8fafc; font-weight: 700; font-size: 0.88rem; }

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--admin-accent);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.92; }
.btn-sm { padding: 4px 10px; font-size: 0.82rem; }
.btn-success { background: #059669; }
.btn-warning { background: #d97706; }
.btn-danger { background: #dc2626; }
.btn-secondary { background: #e2e8f0; color: #1e293b; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.badge-published { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-hidden { background: #fee2e2; color: #991b1b; }

.form-group { margin-bottom: 13px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 0.9rem; }
.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.94rem;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.flash-msg {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
  padding: 6px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px 6px 0 0;
}
.editor-toolbar button {
  padding: 4px 9px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.editor-table-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  background: #eff6ff;
  border-left: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #bfdbfe;
}
.editor-table-bar[hidden] {
  display: none;
}
.editor-table-bar button {
  padding: 3px 8px;
  border: 1px solid #93c5fd;
  background: #fff;
  color: #1e3a8a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}
.editor-table-bar button:hover {
  background: #dbeafe;
}
.editor-img-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  background: #ecfdf5;
  border-left: 1px solid #cbd5e1;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #a7f3d0;
}
.editor-img-bar[hidden] {
  display: none;
}
.editor-img-bar button {
  padding: 3px 8px;
  border: 1px solid #6ee7b7;
  background: #fff;
  color: #065f46;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}
.editor-img-bar button:hover {
  background: #d1fae5;
}
.editor-area img {
  max-width: 100%;
  height: auto;
  cursor: pointer;
}
.editor-area img.editor-img-selected {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.14);
}
.editor-area {
  min-height: 240px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-top: none;
  border-radius: 0 0 6px 6px;
  background: #fff;
  outline: none;
  overflow-x: auto;
}
.editor-area table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
}
.editor-area th,
.editor-area td {
  border: 1px solid #94a3b8;
  padding: 8px 10px;
  min-width: 48px;
  vertical-align: top;
  position: relative;
}
.editor-area th {
  background: #f1f5f9;
  font-weight: 700;
  text-align: left;
}
.editor-area .embed-wrap {
  position: relative;
  margin: 12px 0;
  padding: 8px;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  background: #f8fafc;
}
.editor-area iframe {
  max-width: 100%;
  display: block;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #0f172a);
  padding: 16px;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 28px 30px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

@media (max-width: 860px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar { display: block; }
}

.badge-rejected { background: #fee2e2; color: #b91c1c; }
.nav-badge {
  float: right;
  background: #f59e0b;
  color: #0f172a;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}
.alert-warning {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.tab-btn {
  padding: 6px 12px;
  border-radius: 6px;
  background: #e2e8f0;
  color: #1e293b;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}
.tab-btn.active {
  background: var(--admin-primary);
  color: #fff;
}

/* Clean Focus Styles (fixes thick Safari blue focus ring on inputs/selects/textareas) */
.form-control,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="password"],
textarea,
select {
  background-color: #ffffff;
  color: #1e293b;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus,
.editor-area:focus {
  outline: none;
  border-color: var(--admin-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.16);
  background-color: #ffffff;
}


/* Centered Alert & Confirm Modal Popup (System-wide) */
dialog.center-alert-dialog {
  border: none;
  border-radius: 16px;
  padding: 28px 26px 22px;
  width: min(430px, 92vw);
  max-width: 92vw;
  text-align: center;
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 25px 65px rgba(15, 23, 42, 0.32);
  margin: auto;
  animation: centerPopupIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
dialog.center-alert-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(3px);
}
@keyframes centerPopupIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.center-alert-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}
.center-alert-icon.is-success { background: #dcfce7; color: #059669; }
.center-alert-icon.is-error { background: #fee2e2; color: #dc2626; }
.center-alert-icon.is-confirm { background: #fef3c7; color: #d97706; }
.center-alert-title {
  margin: 0 0 8px;
  font-size: 1.22rem;
  font-weight: 700;
  color: #0f172a;
}
.center-alert-body {
  margin: 0 0 20px;
  font-size: 0.96rem;
  line-height: 1.55;
  color: #475569;
  word-break: break-word;
}
.center-alert-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.center-alert-actions .btn {
  min-width: 112px;
  padding: 9px 20px;
  font-size: 0.94rem;
  border-radius: 8px;
}
