:root {
  --bg: #f3f6fb;
  --card: #fff;
  --primary: #1463c5;
  --primary-2: #0d2f53;
  --primary-soft: #edf5ff;
  --green: #2e9d4b;
  --red: #d64545;
  --text: #1e2d45;
  --muted: #6e7a90;
  --line: #e7ebf2;
  --sidebar-w: 264px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: inherit; }
h1, h2, h3, h4 { font-family: inherit; }

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

.admin-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 22px 22px 18px; }
.sidebar-brand img { height: 30px; width: auto; }
.sidebar-brand span { font-weight: 800; color: var(--primary-2); font-size: 1.02rem; letter-spacing: -.01em; }

.sidebar-nav { flex: 1; padding: 6px 14px; }
.sidebar-group { margin-bottom: 14px; }
.sidebar-group-label { margin: 12px 10px 6px; font-size: .7rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 12px; color: var(--text);
  font-weight: 600; font-size: .92rem; text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.sidebar-link svg { width: 19px; height: 19px; flex-shrink: 0; color: var(--muted); transition: color .15s ease; }
.sidebar-link:hover { background: var(--primary-soft); color: var(--primary-2); }
.sidebar-link:hover svg { color: var(--primary); }
.sidebar-link.active { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; box-shadow: 0 8px 18px rgba(20, 99, 197, .25); }
.sidebar-link.active svg { color: #fff; }

.sidebar-view-site {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 14px 18px; padding: 11px 14px;
  border-radius: 12px; border: 1px dashed var(--line);
  color: var(--muted); font-weight: 700; font-size: .85rem; text-decoration: none;
}
.sidebar-view-site svg { width: 16px; height: 16px; }
.sidebar-view-site:hover { border-color: var(--primary); color: var(--primary); }

.sidebar-backdrop { display: none; border: 0; padding: 0; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.admin-topbar {
  display: flex; align-items: center; gap: 14px;
  justify-content: space-between; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 16px 28px; position: sticky; top: 0; z-index: 20;
}
.admin-topbar h1 { margin: 0; font-size: 1.15rem; color: var(--primary-2); flex: 1; min-width: 0; }
.topbar-user { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.topbar-user .muted { color: var(--muted); font-size: .88rem; }
.topbar-user strong { color: var(--text); }
.logout-link {
  padding: 8px 16px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: .85rem; text-decoration: none;
  border: 1px solid transparent;
}
.logout-link:hover { background: #fff; border-color: var(--primary); }

.sidebar-toggle {
  display: none; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--primary-2);
  cursor: pointer; flex-shrink: 0;
}
.sidebar-toggle svg { width: 20px; height: 20px; }

.admin-content { padding: 24px 28px 60px; max-width: 1320px; width: 100%; }

.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.subtabs .subtab {
  padding: 9px 16px; font-size: .86rem; font-weight: 600; color: var(--primary-2);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtabs .subtab:hover { color: var(--primary); }
.subtabs .subtab.active { color: var(--primary); border-bottom-color: var(--primary); }

@media (max-width: 960px) {
  .admin-sidebar {
    position: fixed; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
  }
  .admin-sidebar.open { transform: translateX(0); box-shadow: 20px 0 40px rgba(15, 43, 85, .15); }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(13, 30, 53, .45); z-index: 30;
  }
  .sidebar-backdrop.visible { display: block; }
  .admin-content { padding: 18px 16px 48px; }
  .admin-topbar { padding: 14px 16px; }
}

/* ---- Cards & grids ---- */
.grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; align-items: start; }
.admin-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 8px 24px rgba(15, 43, 85, .04);
}
.admin-card h2 { margin: 0 0 14px; font-size: 1.08rem; color: var(--primary-2); }
.admin-card + .admin-card { margin-top: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-box {
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff;
  padding: 20px;
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(13, 47, 83, .16);
}
.stat-box h3 { margin: 0; font-size: 1.8rem; }
.stat-box p { margin: 6px 0 0; opacity: .9; font-size: .88rem; }

/* ---- Forms ---- */
.form label { display: block; font-weight: 700; font-size: .85rem; color: var(--muted); margin: 14px 0 4px; }
.form label:first-child { margin-top: 0; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 4px; }
.label-row:first-child { margin-top: 0; }
.label-row label { margin: 0; }
.label-row .ai-translate-btn { flex-shrink: 0; }
.form input,
.form textarea,
.form select {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
  background: #fbfcfe;
}
.form input:focus,
.form textarea:focus,
.form select:focus { outline: 2px solid rgba(20, 99, 197, .25); border-color: var(--primary); background: #fff; }
.form .field-hint { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 12px; }
.form .checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.form .checkbox-row input { width: auto; }
.form .field-note { display: block; font-size: .78rem; color: var(--primary); margin-top: 8px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 20px; border: none; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: .92rem; text-decoration: none; font-family: inherit; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: #fff; color: var(--primary); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--primary); }
.btn-danger { background: #fdecec; color: var(--red); }
.btn-danger:hover { background: #f9d9d9; }
.btn-sm { padding: 8px 14px; font-size: .82rem; }

.link-btn {
  background: none; border: none; padding: 0; margin: 0;
  color: var(--primary); font-weight: 700; font-size: .85rem;
  font-family: inherit; cursor: pointer; text-decoration: none;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }
.inline-form { display: inline; }

.notice { padding: 12px 14px; border-radius: 12px; background: #eefbf2; color: #206a38; margin-bottom: 14px; font-weight: 600; }
.notice.error { background: #fdecec; color: #a92a2a; }

.pill { display: inline-block; padding: 5px 12px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .78rem; font-weight: 700; }
.pill.status-published { background: #e7f8ec; color: #206a38; }
.pill.status-draft { background: #fff4e5; color: #a5650f; }
.pill.role-admin { background: #fdecec; color: var(--red); }
.pill.role-editor { background: var(--primary-soft); color: var(--primary); }
a.pill { text-decoration: none; }

/* ---- List toolbar (search + filters) ---- */
.list-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.list-toolbar input,
.list-toolbar select {
  padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line);
  font: inherit; font-size: .88rem; background: #fbfcfe;
}
.list-toolbar input:focus,
.list-toolbar select:focus { outline: 2px solid rgba(20, 99, 197, .25); border-color: var(--primary); background: #fff; }
.list-toolbar .toolbar-search { flex: 1 1 220px; min-width: 180px; }
.list-toolbar select { flex: 0 0 auto; min-width: 140px; }
.list-toolbar .btn { flex-shrink: 0; }
.list-toolbar .toolbar-reset { display: flex; align-items: center; font-size: .85rem; font-weight: 700; color: var(--muted); text-decoration: none; }
.list-toolbar .toolbar-reset:hover { color: var(--primary); }
.list-count { color: var(--muted); font-size: .85rem; margin: -8px 0 14px; }

/* ---- Data table ---- */
.table-scroll { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th {
  text-align: left; padding: 10px 14px; border-bottom: 2px solid var(--line);
  color: var(--muted); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .05em; font-weight: 800; white-space: nowrap;
}
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--primary-soft); }
.data-table .row-title { font-weight: 700; color: var(--text); }
.data-table .row-meta { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.data-table .col-actions { white-space: nowrap; text-align: right; }
.data-table .col-status, .data-table .col-order { white-space: nowrap; }

.btn-pill { display: inline-flex; align-items: center; padding: 6px 13px; border-radius: 8px; font-size: .78rem; font-weight: 700; text-decoration: none; border: none; cursor: pointer; font-family: inherit; margin-left: 6px; }
.btn-pill:first-child { margin-left: 0; }
.btn-pill-edit { background: var(--primary-soft); color: var(--primary); }
.btn-pill-edit:hover { background: var(--primary); color: #fff; }
.btn-pill-view { background: #eef0f4; color: var(--text); }
.btn-pill-view:hover { background: #dfe4ee; }
.btn-pill-delete { background: #fdecec; color: var(--red); }
.btn-pill-delete:hover { background: var(--red); color: #fff; }

.list { padding: 0; list-style: none; margin: 0; }
.list li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .item-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
.list .item-meta { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.list .item-actions { margin-top: 8px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.list .item-actions a, .list .item-actions .link-btn { font-weight: 700; font-size: .85rem; color: var(--primary); text-decoration: none; }
.list .item-actions a.danger, .list .item-actions .link-btn.danger { color: var(--red); }
.list .item-actions a:hover, .list .item-actions .link-btn:hover { text-decoration: underline; }
.empty-state { color: var(--muted); text-align: center; padding: 28px 0; }

.muted { color: var(--muted); }

/* ---- Login ---- */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #eef4ff 0%, #f9fbff 100%); }
.login-box { width: 100%; max-width: 400px; background: #fff; padding: 32px; border-radius: 22px; box-shadow: 0 20px 45px rgba(15, 43, 85, .14); }
.login-box .brand-mark { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-box .brand-mark img { width: 44px; height: 44px; }
.login-box .brand-mark span { font-weight: 800; color: var(--primary-2); line-height: 1.3; font-size: .95rem; }
.login-box h1 { font-size: 1.3rem; margin: 0 0 6px; color: var(--primary-2); }
.login-box .subtitle { color: var(--muted); margin: 0 0 20px; font-size: .92rem; }
.login-box form input { width: 100%; padding: 12px 14px; margin-bottom: 12px; border-radius: 12px; border: 1px solid var(--line); font: inherit; background: #fbfcfe; }
.login-box .btn { width: 100%; padding: 13px; margin-top: 4px; }
.login-box .hint { margin-top: 18px; font-size: .8rem; color: var(--muted); text-align: center; }
.login-box .hint a { color: var(--primary); font-weight: 700; }

/* ---- Media library ---- */
.image-field { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.image-field-input { flex: 1; margin-bottom: 0 !important; }
.image-upload-btn { flex-shrink: 0; white-space: nowrap; }
.image-upload-btn[disabled] { opacity: .6; cursor: default; }
.image-field-preview:empty { display: none; }
.image-field-preview { margin-bottom: 10px; }
.image-field-preview img { max-width: 180px; max-height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }

.upload-preview { margin-top: 14px; padding: 14px; border: 1px dashed var(--line); border-radius: 14px; background: #fbfcfe; }
.upload-preview img { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 10px; }
.upload-preview code { word-break: break-all; font-size: .82rem; }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.media-item { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fbfcfe; }
.media-item img { width: 100%; height: 92px; object-fit: cover; display: block; }
.media-item-body { padding: 8px 10px; }
.media-item-body p { font-size: .7rem; color: var(--muted); word-break: break-all; margin: 0 0 6px; }
.media-item-actions { display: flex; justify-content: space-between; align-items: center; }
@media (max-width: 640px) { .media-grid { grid-template-columns: repeat(2, 1fr); } }

@media (max-width: 900px) {
  .grid, .stat-grid { grid-template-columns: 1fr; }
}
