/* ==================================================================
   Facebook постын үзүүлэлт — PHP апп-ын стиль
   Цэвэрхэн, цайвар, мэдээлэлд төвлөрсөн
   ================================================================== */
:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e6eaf2;
  --text: #16223b;
  --muted: #6b7a99;
  --blue: #1877f2;
  --blue-dark: #0f5dc4;
  --reaction: #1877f2;
  --comment: #00b894;
  --share: #f5a623;
  --engagement: #7b61ff;
  --danger: #e5484d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 34, 59, .05), 0 6px 20px rgba(16, 34, 59, .06);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 8px; }
a { color: var(--blue); }

/* ---------------- Толгой ---------------- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 700; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 600; padding: 8px 14px; border-radius: 999px; white-space: nowrap; }
.nav a:hover { background: #eef3fd; color: var(--blue); }
.nav a.active { background: #e7f0fe; color: var(--blue); }
.spacer { flex: 1; }
.user-area { display: flex; align-items: center; gap: 10px; }
.user-chip { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.user-role { background: #eef3fd; color: var(--blue); font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------------- Бүтэц ---------------- */
.page { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.section-head p { color: var(--muted); font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head small { color: var(--muted); font-size: 13px; }

/* ---------------- Форм ---------------- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: #384764; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="url"], input[type="file"], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: #fff; color: var(--text); font: inherit; font-size: 14px;
}
input:focus, select:focus { outline: 2px solid #cfe0ff; border-color: var(--blue); }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: 14px; cursor: pointer;
  background: var(--blue); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--blue-dark); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f2f5fb; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f4c9cb; }
.btn-danger:hover { background: #fdf1f1; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------------- Нэвтрэх ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand .logo { width: 44px; height: 44px; border-radius: 12px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; }

/* ---------------- KPI ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .kpi-label { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .kpi-value { font-size: 30px; font-weight: 750; margin-top: 6px; letter-spacing: -.02em; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent-reaction { border-top: 3px solid var(--reaction); }
.kpi.accent-comment { border-top: 3px solid var(--comment); }
.kpi.accent-share { border-top: 3px solid var(--share); }
.kpi.accent-engagement { border-top: 3px solid var(--engagement); }
.kpi.accent-posts { border-top: 3px solid #16223b; }

/* ---------------- Сегмент ---------------- */
.segmented { display: inline-flex; background: #eef1f7; border-radius: 999px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; font: inherit; font-weight: 650; font-size: 13.5px;
  color: var(--muted); padding: 8px 16px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.segmented button.active { background: #fff; color: var(--blue); box-shadow: 0 1px 4px rgba(16,34,59,.12); }

/* ---------------- Шүүлтүүр ---------------- */
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.filters .field { margin: 0; }

/* ---------------- Хүснэгт ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfe; }
tbody tr:hover { background: #fafbfe; }
td.wrap { white-space: normal; min-width: 180px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: #eef3fd; color: var(--blue); }
.badge.gray { background: #f1f3f7; color: var(--muted); }

/* ---------------- Постын карт ---------------- */
.top-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.post-card { position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.post-card .thumb { height: 128px; background: #eef1f7; object-fit: cover; width: 100%; display: block; }
.post-card .thumb-ph { height: 128px; display: grid; place-items: center; color: var(--muted); font-size: 12px; background: #f2f5fb; }
.post-card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.post-card .title { font-weight: 700; font-size: 14px; }
.post-card .meta { font-size: 12.5px; color: var(--muted); }
.post-card .metrics { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; margin-top: 6px; }
.post-card .metrics b { font-size: 13.5px; }
.m-reaction { color: var(--reaction); }
.m-comment { color: var(--comment); }
.m-share { color: var(--share); }
.m-engagement { color: var(--engagement); }
.rank { position: absolute; top: 10px; left: 10px; background: var(--blue); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }

/* ---------------- График ---------------- */
.chart-box { position: relative; width: 100%; height: 340px; }
.chart-box.tall { height: 380px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------------- Туслах ---------------- */
.empty { padding: 30px 10px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: #16223b; color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all .2s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); }
.shot-preview { margin-top: 10px; max-width: 220px; border: 1px solid var(--border); border-radius: 9px; display: block; }

.alert-error {
  background: #fdf1f1; border: 1px solid #f4c9cb; color: #a8262a;
  border-radius: 9px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}

/* ---------------- Суулгах wizard ---------------- */
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 18px; flex-wrap: wrap; }
.step-item {
  flex: 1 1 180px; display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-weight: 600; color: var(--muted); font-size: 14px;
}
.step-item .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #eef1f7; color: var(--muted); font-size: 13px; font-weight: 700; flex: none; }
.step-item.active { border-color: var(--blue); color: var(--text); }
.step-item.active .num { background: var(--blue); color: #fff; }
.step-item.done .num { background: #00b894; color: #fff; }
.step-item.done { color: var(--text); }

.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: #fafbfe; font-size: 14px; }
.check-list .mark { font-weight: 700; width: 18px; flex: none; text-align: center; }
.check-list li.ok .mark { color: #00b894; }
.check-list li.fail .mark { color: var(--danger); }
.check-list li.fail { border-color: #f4c9cb; background: #fdf1f1; }

.done-info { background: #f4f7fd; border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; margin-top: 8px; font-size: 14px; }
code { background: #eef1f7; padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  body { font-size: 14.5px; }
  .page { padding: 16px 14px 60px; }
  .topbar-inner { padding: 10px 14px; gap: 10px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi .kpi-value { font-size: 24px; }
  .field-row { grid-template-columns: 1fr; }
  .nav { width: 100%; overflow-x: auto; }
  .chart-box { height: 280px; }
  .segmented button { padding: 7px 12px; font-size: 13px; }
  .card { padding: 14px; }
}
