/* Порталын дизайны систем — бүх хуудас энэ классуудыг ашиглана.
   Брэнд өнгө (--brand, --accent) base.html-д SiteSettings-ээс ирнэ. */

:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #F8F9FA;
  --border: #E3E6EA;
  --border-soft: #EEF0F3;
  --text: #1A2230;
  --text-2: #465264;
  --muted: #7B8595;
  --faint: #A6AEBA;
  --sidebar: #161E2B;

  --green: #1E7A4C;  --green-bg: #E6F4EC;
  --amber: #9A6200;  --amber-bg: #FDF3DC;
  --blue: #2256A0;   --blue-bg: #E8F0FB;
  --red: #B42318;    --red-bg: #FDECEA;
  --gray: #556070;   --gray-bg: #EEF0F3;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .18);
  --font: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Roboto Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #CDD2D9; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
.mono { font-family: var(--mono); font-feature-settings: 'tnum'; }
.num { font-variant-numeric: tabular-nums; }
.table .num { white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden, [hidden] { display: none !important; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: var(--sidebar); color: #fff;
  display: flex; flex-direction: column; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark {
  width: 40px; height: 40px; border-radius: 9px; flex: 0 0 40px; display: flex; align-items: center;
  justify-content: center; border: 1.5px solid var(--accent); color: var(--accent); font-weight: 700; font-size: 14px;
}
.brand-logo { width: 40px; height: 40px; border-radius: 9px; object-fit: contain; background: #fff; }
.brand-name { font-weight: 700; font-size: 14.5px; letter-spacing: .01em; line-height: 1.2; }
.brand-tag { font-size: 11.5px; color: rgba(255,255,255,.5); margin-top: 2px; }
.nav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.nav-label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.35); padding: 4px 12px 8px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; margin-bottom: 2px;
  color: rgba(255,255,255,.64); font-size: 14px; font-weight: 500; transition: background .15s, color .15s;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.09); box-shadow: inset 3px 0 0 var(--accent); }
.nav-item svg { flex: 0 0 18px; }
.sidebar-admin {
  margin: 0 12px 10px; padding: 9px 12px; border-radius: 8px; background: rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 9px; font-size: 13px; color: rgba(255,255,255,.75); font-weight: 500;
}
.sidebar-admin:hover { background: rgba(255,255,255,.1); color: #fff; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.07); display: flex; align-items: center; gap: 11px; }
.me-name { font-size: 13.5px; font-weight: 600; }
.me-role { font-size: 11.5px; color: rgba(255,255,255,.5); }
.icon-plain { background: none; border: none; color: rgba(255,255,255,.55); cursor: pointer; display: flex; padding: 6px; border-radius: 6px; }
.icon-plain:hover { color: #fff; background: rgba(255,255,255,.08); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; flex: 0 0 64px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 28px;
}
.page-title { font-size: 18px; font-weight: 700; line-height: 1.2; }
.page-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.content { flex: 1; overflow-y: auto; padding: 24px 28px 40px; }
.topbar .menu-btn { display: none; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 12px; width: 280px; height: 38px;
}
.search input { border: none; background: transparent; outline: none; width: 100%; font-size: 13.5px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.row-wrap { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; }
.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: .3; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Card ───────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12.5px; color: var(--muted); }
.card-body { padding: 16px 20px; }
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }

.meta-grid { display: flex; flex-wrap: wrap; gap: 14px 32px; padding: 16px 20px; border-top: 1px solid var(--border-soft); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.meta-label { font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.meta-value { font-size: 14px; font-weight: 600; margin-top: 4px; }

/* ── Stat ───────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; position: relative; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat-bar { position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; }
.help {
  display: inline-flex; width: 15px; height: 15px; border-radius: 50%; background: var(--gray-bg); color: var(--muted);
  font-size: 10px; font-weight: 700; align-items: center; justify-content: center; cursor: help;
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: 7px; }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand); filter: brightness(.9); }
.btn-dark { background: var(--text); border-color: var(--text); color: #fff; }
.btn-dark:hover { background: var(--text); filter: brightness(1.25); }
.btn-success { background: var(--green-bg); border-color: #C9E6D5; color: var(--green); }
.btn-success:hover { background: #D8EEE1; }
.btn-warn { background: var(--amber-bg); border-color: #F1DFB0; color: var(--amber); }
.btn-warn:hover { background: #FAEBC6; }
.btn-danger { background: var(--red-bg); border-color: #F6CFCA; color: var(--red); }
.btn-danger:hover { background: #FADCD8; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--gray-bg); }
.btn-link { background: none; border: none; color: var(--brand); font-weight: 600; cursor: pointer; padding: 0; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }

/* ── Badge ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.b-green { background: var(--green-bg); color: var(--green); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-gray { background: var(--gray-bg); color: var(--gray); }
.count { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 10px; background: rgba(0,0,0,.07); }

/* ── Tabs / pills ───────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer;
}
.pill.active { background: var(--text); border-color: var(--text); color: #fff; }

/* ── Forms ──────────────────────────────────────────────────────────── */
.input, .select, .textarea,
.form-grid input[type=text], .form-grid input[type=number], .form-grid input[type=email],
.form-grid input[type=password], .form-grid input[type=date], .form-grid select, .form-grid textarea {
  width: 100%; height: 38px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm);
  padding: 0 11px; font-size: 13.5px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea, .form-grid textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.form-grid select[multiple] { height: auto; min-height: 110px; padding: 6px; }
.input:focus, .select:focus, .textarea:focus,
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent);
}
.select, .form-grid select:not([multiple]) { appearance: none; padding-right: 30px; cursor: pointer;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237B8595' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center; }
.input-sm { height: 32px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.req { color: var(--red); }
.field-help { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--red); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.money-wrap { position: relative; }
.money-wrap::before { content: '₮'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; font-size: 13px; }
.money-wrap .input { padding-left: 26px; }

/* ── Filter bar ─────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 16px; }
.filters .field { min-width: 150px; flex: 1 1 150px; max-width: 240px; }
.filters .field-label { font-size: 11.5px; color: var(--muted); }
.filters .actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* ── Table ──────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 10px 14px; font-size: 11.5px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #FAFBFC; }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: none; }
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover { color: var(--text); }
.cell-main { font-weight: 500; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 13.5px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--gray-bg); color: var(--text-2); display: inline-flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: 0 0 28px;
}
.avatar-lg { width: 36px; height: 36px; flex: 0 0 36px; font-size: 13px; }
.avatar-accent { background: var(--accent); color: var(--sidebar); }
.avatar-dark { background: var(--text); color: #fff; }

/* Хэргийн мөрийн хүснэгт — дэлгэцэнд багтах баганыг л харуулна */
.rows-table td { max-width: 220px; }
.rows-table td .ellipsis { max-width: 220px; display: block; }
.rows-table .col-idx { width: 44px; color: var(--faint); font-size: 12.5px; }
.rows-table .col-more { width: 1%; white-space: nowrap; color: var(--muted); font-size: 12px; }
.rows-table th.col-hidden, .rows-table td.col-hidden { display: none; }
.rows-table tr.row-new td { background: #FFFCF2; }
.rows-table tr.row-dirty td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.progress { height: 6px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; border-radius: 4px; }

/* ── Drawer ─────────────────────────────────────────────────────────── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 80; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 90;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 16px; font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot { display: flex; gap: 10px; align-items: center; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.kv { display: flex; flex-direction: column; gap: 4px; }
.kv-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.kv-value { font-size: 14px; white-space: pre-line; word-break: break-word; }
.drawer .kv-value { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 8px 11px; min-height: 38px; color: var(--text-2); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

.save-bar {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 10px; align-items: center; padding: 12px 20px;
  background: #FFF9EC; border-top: 1px solid #F1DFB0; color: var(--amber); font-weight: 600; font-size: 13.5px;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Alerts / messages ─────────────────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 13.5px; border: 1px solid; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--green-bg); border-color: #C9E6D5; color: #145A37; }
.alert-error { background: var(--red-bg); border-color: #F6CFCA; color: #8F1C13; }
.alert-info { background: var(--blue-bg); border-color: #CFDDF3; color: #1B467F; }

/* ── Notifications dropdown ───────────────────────────────────────── */
.notif-wrap { position: relative; }
.notif-badge {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; align-items: center; justify-content: center; border: 2px solid #fff;
}
.notif-panel {
  position: absolute; right: 0; top: 48px; width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 60; overflow: hidden;
}
.notif-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: #FFF9EC; }

.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 40px)); }
.toast {
  display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); animation: slideIn .2s ease; transition: opacity .3s, transform .3s;
}
.toast.out { opacity: 0; transform: translateX(20px); }
.toast-icon { font-size: 18px; line-height: 1.2; }

/* ── Chat ───────────────────────────────────────────────────────────── */
.chat { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: calc(100vh - 64px - 64px); }
.chat-list { overflow-y: auto; flex: 1; }
.convo { display: flex; align-items: center; gap: 11px; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.convo:hover { background: var(--surface-2); }
.convo.active { background: var(--blue-bg); }
.thread { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
.msg { max-width: 70%; }
.msg.mine { align-self: flex-end; }
.bubble { padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-line; background: var(--surface); border: 1px solid var(--border); }
.msg.mine .bubble { background: var(--text); border-color: var(--text); color: #fff; }
.msg-time { font-size: 11px; color: var(--faint); margin-top: 3px; }
.msg.mine .msg-time { text-align: right; }

/* ── Login ──────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card { width: min(400px, 100%); padding: 32px; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1560px) {
  .hide-lg { display: none !important; }
}
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 30; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar .search { display: none; }
  .content { padding: 16px 16px 32px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat .chat-side { max-height: 260px; }
  .hide-sm { display: none !important; }
  .filters .field { max-width: none; }
}
