/*
 * Admin backend — styled after the Argon Dashboard (Creative Tim) look:
 * fixed white sidebar, gradient header band, stat cards overlapping the header,
 * soft-shadow cards. Self-contained (no Bootstrap/CDN), brand colors (navy + red).
 */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@400;500;600;700&family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
  --navy: #061A4A;
  --navy-2: #0A2A6E;
  --red: #F20D18;
  --red-dark: #c40a13;
  --bg: #f4f6fb;
  --text: #525f7f;
  --heading: #1a2b4a;
  --muted: #8898aa;
  --border: #e9ecf3;
  --card-shadow: 0 0 2rem 0 rgba(136,152,170,.15);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }
body.admin {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Noto Sans Thai', sans-serif; font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body.admin h1, body.admin h2, body.admin h3, body.admin h4 { font-family: 'Prompt', sans-serif; color: var(--heading); margin: 0; }
a { color: var(--red); text-decoration: none; }

/* ===== Sidebar ===== */
.sidenav {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: #fff; box-shadow: 0 0 2rem 0 rgba(136,152,170,.1);
  display: flex; flex-direction: column; z-index: 100; overflow-y: auto;
}
.sidenav-brand { display: flex; align-items: center; gap: 10px; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.sidenav-brand img { width: 38px; height: 38px; border-radius: 9px; object-fit: contain; background: var(--navy); }
.sidenav-brand span { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 17px; color: var(--navy); }
.sidenav-nav { list-style: none; margin: 0; padding: 16px 14px; flex: 1; }
.sidenav-nav .nav-section { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; }
.sidenav-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px;
  color: #4a5568; font-weight: 500; font-size: 14.5px; margin-bottom: 2px; transition: .15s;
}
.sidenav-nav a svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--muted); }
.sidenav-nav a:hover { background: #f6f7fb; color: var(--navy); }
.sidenav-nav a.active { background: #fdeaeb; color: var(--red); }
.sidenav-nav a.active svg { color: var(--red); }
.sidenav-foot { padding: 14px; border-top: 1px solid var(--border); }

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

/* top navbar (sits on the light background, above the gradient header) */
.topnav { display: flex; align-items: center; gap: 16px; padding: 16px 30px; }
.topnav .crumb { color: var(--muted); font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 14px; }
.topnav .spacer { flex: 1; }
.topnav .user { display: flex; align-items: center; gap: 10px; color: var(--heading); font-size: 14px; font-weight: 500; }
.topnav .user .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-family: 'Prompt'; font-weight: 700; }
.topnav .user form { margin: 0; }
.topnav .btn-logout { background: #eef1f6; color: #5a6a85; border: none; padding: 8px 16px; border-radius: 8px; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13.5px; cursor: pointer; transition: .15s; }
.topnav .btn-logout:hover { background: #fdeaeb; color: var(--red); }

/* gradient header band */
.header {
  background: linear-gradient(87deg, var(--navy) 0, var(--navy-2) 100%);
  padding: 0 30px 90px; position: relative;
}
.header::before { content: ''; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.04) 1px,transparent 1px); background-size: 40px 40px; pointer-events: none; }
.header .page-title { color: #fff; font-size: 26px; position: relative; }
.header .page-hint { color: rgba(255,255,255,.7); font-size: 14px; margin-top: 4px; position: relative; }

/* page body pulls up over the header (Argon mt--6) */
.page-body { flex: 1; padding: 0 30px 40px; margin-top: -74px; position: relative; z-index: 2; }
.page-foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 30px 30px; margin-left: var(--sidebar-w); }

/* ===== Cards ===== */
.card { background: #fff; border-radius: 12px; box-shadow: var(--card-shadow); margin-bottom: 26px; }
.card-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.card-header h2 { font-size: 18px; }
.card-header .spacer { flex: 1; }
.card-body { padding: 24px; }
.card-body.-flush { padding: 0; }

/* stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; margin-bottom: 8px; }
.stat-card { background: #fff; border-radius: 12px; box-shadow: var(--card-shadow); padding: 22px 24px; }
.stat-card .row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stat-label { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.stat-value { font-family: 'Prompt', sans-serif; font-size: 30px; font-weight: 700; color: var(--heading); line-height: 1; }
.stat-icon { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; flex: 0 0 auto; box-shadow: 0 4px 10px rgba(0,0,0,.12); }
.stat-icon svg { width: 24px; height: 24px; }
.bg-grad-red { background: linear-gradient(87deg, #f5365c 0, #f56036 100%); }
.bg-grad-navy { background: linear-gradient(87deg, var(--navy) 0, #2650b0 100%); }
.bg-grad-green { background: linear-gradient(87deg, #2dce89 0, #2dcecc 100%); }
.bg-grad-orange { background: linear-gradient(87deg, #fb6340 0, #fbb140 100%); }
.stat-foot { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  background: #f6f7fb; color: var(--muted); font-family: 'Prompt', sans-serif; font-weight: 600;
  font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; text-align: left;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
}
table.data td { padding: 15px 24px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbff; }
table.data .muted { color: var(--muted); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 7px; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 14px; padding: 10px 20px; border-radius: 9px; border: none; cursor: pointer; transition: .18s; text-decoration: none; line-height: 1; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 4px 12px rgba(242,13,24,.3); }
.btn-primary:hover { background: var(--red-dark); transform: translateY(-1px); color: #fff; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); color: #fff; }
.btn-light { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn-light:hover { border-color: var(--red); color: var(--red); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-danger { background: #fdeaeb; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
.btn-ghost:hover { color: var(--red); }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-row { display: flex; gap: 20px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 200px; }
.form-label { display: block; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13.5px; color: var(--heading); margin-bottom: 8px; }
.form-control {
  width: 100%; padding: 11px 15px; border: 1px solid #dfe3ec; border-radius: 9px;
  font-family: inherit; font-size: 14.5px; color: var(--heading); background: #fff; transition: .15s;
}
.form-control:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(10,42,110,.1); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
fieldset.box { border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin: 0 0 20px; }
fieldset.box legend { font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 14px; color: var(--heading); padding: 0 8px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px,1fr)); gap: 8px; max-height: 260px; overflow-y: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: normal; font-size: 13.5px; }
.check input { width: auto; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 11.5px; padding: 4px 11px; border-radius: 999px; }
.badge-green { background: #e6f7ef; color: #1aae6f; }
.badge-gray { background: #eef1f6; color: #8898aa; }
.badge-navy { background: #e7edfb; color: var(--navy-2); }
.badge-red { background: #fdeaeb; color: var(--red); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== Alerts (flash) ===== */
.alert { padding: 14px 20px; border-radius: 10px; margin-bottom: 22px; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.alert.ok { background: #e6f7ef; color: #178a58; }
.alert.error { background: #fdeaeb; color: var(--red-dark); }

/* ===== Media grid ===== */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 16px; }
.media-grid figure { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.media-grid img { width: 100%; height: 120px; object-fit: cover; display: block; }
.media-grid figcaption { padding: 8px 10px; font-size: 11px; color: var(--muted); word-break: break-all; }
.media-grid .file { display: flex; align-items: center; justify-content: center; height: 120px; background: #f6f7fb; color: var(--muted); font-size: 12px; padding: 8px; text-align: center; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.featured-preview { max-width: 220px; border-radius: 10px; display: block; margin-bottom: 10px; }
.empty-row { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ===== Login page ===== */
body.admin-auth {
  margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(87deg, var(--navy) 0, var(--navy-2) 100%); padding: 20px;
  font-family: 'Noto Sans Thai', sans-serif;
}
body.admin-auth::before { content: ''; position: fixed; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.04) 1px,transparent 1px); background-size: 42px 42px; }
.auth-card { position: relative; background: #fff; width: 100%; max-width: 400px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); padding: 40px 36px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand img { width: 60px; height: 60px; border-radius: 14px; object-fit: contain; background: var(--navy); }
.auth-brand h1 { font-size: 21px; color: var(--navy); }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13.5px; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 13px; margin-top: 6px; }

/* ===== Responsive ===== */
.sidenav-toggle { display: none; }
@media (max-width: 900px) {
  .sidenav { transform: translateX(-100%); transition: transform .25s; }
  .sidenav.open { transform: translateX(0); }
  .main-content, .page-foot { margin-left: 0; }
  .sidenav-toggle { display: inline-flex; background: var(--navy); border: none; color: #fff; width: 40px; height: 40px; border-radius: 9px; align-items: center; justify-content: center; cursor: pointer; }
}

/* ===== Analytics dashboard ===== */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 26px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 26px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }

/* card + stat-card polish */
.card { transition: box-shadow .2s ease; }
.stat-card { transition: transform .18s ease, box-shadow .18s ease; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(136,152,170,.26); }

/* realtime strip */
.realtime-card .card-body { display: flex; align-items: center; gap: 13px; }
.rt-pulse { width: 12px; height: 12px; border-radius: 50%; background: #2dce89; flex: 0 0 auto; animation: rtpulse 1.9s infinite; }
@keyframes rtpulse { 0% { box-shadow: 0 0 0 0 rgba(45,206,137,.45); } 70% { box-shadow: 0 0 0 12px rgba(45,206,137,0); } 100% { box-shadow: 0 0 0 0 rgba(45,206,137,0); } }
.rt-num { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 24px; color: var(--heading); }
.rt-txt { color: var(--muted); }
.rt-txt b { color: var(--heading); font-weight: 600; }
.rt-badge { margin-left: auto; background: #e6f7ef; color: #1aae6f; font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 11px; letter-spacing: .06em; padding: 5px 11px; border-radius: 999px; }

/* line chart */
.chip-muted { background: #f0f2f7; color: var(--muted); font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 11.5px; padding: 4px 10px; border-radius: 999px; }
.chart-kpi { color: var(--muted); font-size: 13px; margin-left: 18px; }
.chart-kpi b { font-family: 'Prompt', sans-serif; color: var(--heading); font-size: 15px; margin-right: 3px; }
.ga-chart { position: relative; }
.ga-chart #ga-line { display: block; }
.ga-tip { position: absolute; transform: translate(-50%, -128%); background: #1a2b4a; color: #fff; border-radius: 9px; padding: 7px 11px; font-size: 12.5px; line-height: 1.35; pointer-events: none; display: none; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.22); z-index: 5; text-align: center; }
.ga-tip::after { content: ''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 5px solid transparent; border-top-color: #1a2b4a; }
.ga-tip .d { color: #aeb9d4; font-size: 11px; }
.ga-tip .u { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 14px; }

/* donut */
.donut { position: relative; width: 132px; height: 132px; margin: 2px auto 18px; }
.donut-svg { width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center b { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 25px; color: var(--heading); line-height: 1; }
.donut-center span { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* legends */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.legend-ico { width: 26px; height: 26px; border-radius: 7px; display: flex; align-items: center; justify-content: center; background: #f4f6fb; flex: 0 0 auto; }
.legend-ico svg { width: 15px; height: 15px; }
.legend-lbl { flex: 1; color: var(--heading); font-weight: 500; }
.legend-val { color: var(--muted); font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 12.5px; }

/* horizontal bars (countries) */
.hbar { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 15px; }
.hbar li { display: grid; grid-template-columns: 22px minmax(64px, 1.1fr) 1.4fr 42px; align-items: center; gap: 12px; font-size: 14px; }
.hbar-flag { font-size: 18px; line-height: 1; }
.hbar-name { color: var(--heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 9px; background: #eef1f6; border-radius: 6px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--navy), #2650b0); border-radius: 6px; }
.hbar-val { text-align: right; color: var(--muted); font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13px; }

/* engagement insight tiles */
.insight-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.insight { background: #f6f7fb; border-radius: 12px; padding: 16px 12px; text-align: center; }
.insight-val { font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 25px; color: var(--heading); line-height: 1; }
.insight-val small { font-size: 15px; color: var(--muted); font-weight: 600; }
.insight-lbl { font-size: 12px; color: var(--muted); margin-top: 7px; }

@media (max-width: 600px) {
  .chart-kpi { display: none; }
  .insight-val { font-size: 21px; }
}

/* ===== Tag filter bar (posts list) ===== */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; padding: 16px 24px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, #fbfcfe, #fff); }
.filter-label { display: inline-flex; align-items: center; gap: 6px; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13px; color: var(--muted); margin-right: 4px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: 'Prompt', sans-serif; font-weight: 500; font-size: 13px;
  padding: 7px 14px; border-radius: 999px;
  background: #fff; border: 1.5px solid var(--border); color: #5a6a85;
  text-decoration: none; transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, color .16s ease, background .16s ease;
}
.filter-chip:hover { border-color: var(--red); color: var(--red); transform: translateY(-2px); box-shadow: 0 6px 15px rgba(242,13,24,.14); }
.filter-chip.active {
  background: linear-gradient(135deg, #F20D18 0%, #FF5436 100%);
  border-color: transparent; color: #fff;
  box-shadow: 0 7px 18px rgba(242,13,24,.32);
}
.filter-chip .count {
  font-family: 'Prompt', sans-serif; font-weight: 700; font-size: 11px; min-width: 18px; text-align: center;
  background: #eef1f7; color: #7d8aa3; padding: 1px 7px; border-radius: 999px; line-height: 1.5; transition: .16s;
}
.filter-chip:hover .count { background: #fdeaeb; color: var(--red); }
.filter-chip.active .count { background: rgba(255,255,255,.24); color: #fff; }

/* ===== Portfolio manager ===== */
/* sections as blocks in a grid (2 columns) instead of one long vertical stack */
.pf-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 22px; align-items: start; }
.pf-grid > .card { margin-bottom: 0; }
@media (max-width: 980px) { .pf-grid { grid-template-columns: 1fr; } }
.pf-secform { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.pf-secform > div { flex: 1; min-width: 180px; }
.pf-secform .form-label { margin-bottom: 6px; }
.pf-secform .btn { flex: 0 0 auto; }
.pf-items { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; }
.pf-item { width: 100px; }
.pf-thumb { width: 100px; height: 74px; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #f6f7fb; display: flex; align-items: center; justify-content: center; }
.pf-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pf-name { font-size: 12px; color: var(--heading); margin-top: 5px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-actions { display: flex; gap: 4px; justify-content: center; margin-top: 6px; }
.pf-actions form { margin: 0; }
.pf-mv, .pf-del { border: 1px solid var(--border); background: #fff; border-radius: 6px; width: 27px; height: 27px; cursor: pointer; font-size: 13px; color: #5a6a85; transition: .15s; line-height: 1; }
.pf-mv:hover { border-color: var(--navy); color: var(--navy); }
.pf-del { color: var(--red); }
.pf-del:hover { background: var(--red); color: #fff; border-color: var(--red); }
.pf-additem { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border); }
.pf-additem .form-control { padding: 8px 12px; font-size: 13.5px; }
.filter-note { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px 24px; background: #fff8f8; border-bottom: 1px solid var(--border); font-size: 13.5px; color: #5a6a85; }
.filter-note .clear { margin-left: auto; color: var(--red); text-decoration: none; font-family: 'Prompt', sans-serif; font-weight: 600; font-size: 13px; }
.filter-note .clear:hover { text-decoration: underline; }
