:root {
  --hgo-blue: #1769ff;
  --hgo-navy: #101c32;
  --hgo-border: #e5eaf3;
  --hgo-muted: #718096;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  color: #17233a;
  background: #f5f7fb;
}

* { box-sizing: border-box; }
body { margin: 0; background: #f3f6fc; color: #17243b; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #f8fbff, #eef4ff); }
.login-card { width: min(430px, 100%); background: #fff; border: 1px solid #e5eaf2; border-radius: 24px; padding: 34px; box-shadow: 0 18px 50px rgba(20, 35, 60, .09); }
.login-logo { width: 100px; display: block; margin: 0 auto 18px; }
.login-card h1 { text-align: center; margin: 0 0 6px; }
.login-card > p { text-align: center; color: #7b879b; margin: 0 0 26px; }
.login-card label { display: block; margin: 14px 0 7px; font-weight: 700; }
.login-card input, .search { width: 100%; border: 1px solid #dfe5ee; border-radius: 12px; padding: 12px 14px; background: #fff; outline: none; }
.login-card input:focus, .search:focus { border-color: #1769ff; box-shadow: 0 0 0 3px rgba(23, 105, 255, .1); }
button { border: 0; cursor: pointer; }
.primary, .secondary { border-radius: 12px; padding: 11px 16px; font-weight: 800; }
.primary { width: 100%; margin-top: 20px; background: #1769ff; color: #fff; }
.secondary { background: #edf3ff; color: #1769ff; }
.message { margin-top: 14px; color: #c62828; text-align: center; }

/* Layout */
.admin-app { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.main { min-width: 0; padding: 0 30px 40px; }

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #111e36 0%, #172b4d 100%);
  color: #fff;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: -5px 0 24px rgba(15, 30, 55, .08);
}
.sidebar .brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 22px 12px 26px;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
  margin-bottom: 20px;
  flex-shrink: 0;
}
.sidebar .brand img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 15px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, .12);
  background: #fff;
  padding: 5px;
}
.sidebar .brand > span {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}
.sidebar nav {
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
}
.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: transparent;
  color: #b8c3d6;
  text-align: right;
  padding: 12px 14px;
  border-radius: 13px;
  font-weight: 700;
  transition: background .2s ease, color .2s ease;
}
.sidebar .nav-item:hover { background: rgba(255, 255, 255, .09); }
.sidebar .nav-item.active {
  background: #075bd8;
  color: #fff;
  box-shadow: 0 5px 15px rgba(23, 105, 255, .25);
}
.sidebar .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 23px;
  font-weight: 700;
  stroke-width: 2;
  flex-shrink: 0;
}
.logout {
  margin-top: 12px;
  background: #2a1c2b;
  color: #ffb8b8;
  border-radius: 11px;
  padding: 12px;
  font-weight: 800;
  flex-shrink: 0;
}

/* Topbar & Stats */
.topbar { min-height: 105px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e6eaf1; margin-bottom: 28px; }
.topbar h1 { font-size: 28px; margin: 0; font-weight: 800; }
.topbar p { margin: 5px 0 0; color: #8490a4; }
.admin-badge { text-align: left; background: #fff; border: 1px solid #e6eaf1; border-radius: 14px; padding: 10px 14px; }
.admin-badge span, .admin-badge strong { display: block; }
.admin-badge span { font-size: 11px; color: #8792a5; }
.admin-badge strong { font-size: 13px; margin-top: 2px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat, .panel { background: #fff; border: 1px solid var(--hgo-border); border-radius: 20px; box-shadow: 0 6px 25px rgba(24, 44, 78, .045); }
.stat { padding: 22px; position: relative; overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
.stat::before { content: ""; position: absolute; top: 0; right: 0; width: 5px; height: 100%; background: var(--hgo-blue); }
.stat:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(24, 44, 78, .09); }
.stat span { display: block; color: #7f8a9e; font-size: 13px; }
.stat strong { display: block; font-size: 32px; margin-top: 8px; color: #142b50; }
.ops-stat { text-align: right; color: inherit; font: inherit; cursor: pointer; min-width: 0; }
.ops-stat:hover { border-color: #1769ff; }

/* Panels & Tables */
.panel { padding: 22px; margin-bottom: 20px; }
.panel h3 { margin: 0 0 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; }
.panel-head p { margin: 5px 0 0; color: #8490a4; }
.search { max-width: 340px; }
.table-wrap { overflow: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { text-align: right; padding: 15px 16px; border-bottom: 1px solid #edf0f5; font-size: 13px; }
th { color: #52627c; background: #f5f8fe; font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
table tbody tr { transition: background .15s ease; }
table tbody tr:hover, .order-row:hover, .user-row:hover { background: #f5f9ff; }
.order-row, .user-row { cursor: pointer; }
.user-order-card { cursor: pointer; }

/* Badges & Details */
.badge { display: inline-flex; padding: 6px 10px; border-radius: 999px; background: #eef2f7; color: #526077; font-size: 11px; font-weight: 800; }
.badge.good { background: #e8f8ee; color: #167d3c; }
.badge.warn { background: #fff3d7; color: #966500; }
.badge.bad { background: #ffe9e9; color: #c62828; }
.badge.info { background: #e7f1ff; color: #1267d6; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.wide { grid-column: 1 / -1; }
.detail-row { display: flex; justify-content: space-between; gap: 24px; padding: 11px 0; border-bottom: 1px solid #f0f2f6; }
.detail-row:last-child { border-bottom: 0; }
.detail-row span { color: #7c8799; }
.detail-row strong { text-align: left; overflow-wrap: anywhere; }
.event { display: grid; grid-template-columns: 150px 1fr 180px; gap: 16px; padding: 12px 0; border-bottom: 1px solid #eef1f5; }
.event:last-child { border-bottom: 0; }
.event small { color: #8994a6; }

/* Cards & Actions */
.cards-list { display: grid; gap: 12px; }
.list-card { border: 1px solid #e8ecf2; border-radius: 14px; padding: 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; background: #fff; transition: border-color .2s ease, box-shadow .2s ease; }
.list-card:hover { border-color: #cbdcff; box-shadow: 0 5px 18px rgba(23, 105, 255, .06); }
.list-card h4 { margin: 0 0 6px; }
.list-card p { margin: 3px 0; color: #667287; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.approve { background: #e8f8ee; color: #167d3c; padding: 8px 11px; border-radius: 10px; font-weight: 800; }
.reject { background: #ffe9e9; color: #c62828; padding: 8px 11px; border-radius: 10px; font-weight: 800; }
.empty { padding: 30px; text-align: center; color: #8792a5; }
.toast { position: fixed; left: 24px; bottom: 24px; background: #17233a; color: #fff; padding: 13px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); z-index: 50; }
.back { margin-bottom: 18px; }
.unread { border-right: 4px solid #1769ff; background: #f8fbff; }
.mono, bdi[dir="ltr"] { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: #8a95a7; }
.danger-text { color: #c62828; }
.good-text { color: #167d3c; }

/* Buttons */
.danger-button { border: 1px solid #dc2626; background: #fff; color: #dc2626; border-radius: 10px; padding: 8px 13px; font-weight: 700; cursor: pointer; }
.danger-button:hover { background: #fef2f2; }
.danger-button:disabled { opacity: .55; cursor: not-allowed; }
.primary-button { border: 1px solid #2563eb; background: #2563eb; color: #fff; border-radius: 10px; padding: 8px 13px; font-weight: 700; cursor: pointer; }
.primary-button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, input:focus-visible, .ops-stat:focus-visible { outline: 3px solid rgba(23, 105, 255, .3); outline-offset: 2px; }
button:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }

/* Chat & Users */
.user-search-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.user-search-form .search { flex: 1; min-width: 180px; max-width: 460px; }
.national-id-row { display: flex; align-items: center; gap: 18px; padding: 12px 0; border-bottom: 1px solid #edf0f5; }
.national-id-row strong { font-variant-numeric: tabular-nums; letter-spacing: .1em; }
.profile-order { width: 100%; font: inherit; text-align: right; background: #fff; color: inherit; }
.profile-order small { display: block; margin-top: 8px; line-height: 1.8; }
.chat-messages { height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 14px; background: #f6f8fc; border: 1px solid #e5eaf3; border-radius: 14px; overscroll-behavior: contain; }
.chat-message { max-width: 85%; padding: 12px 15px; border-radius: 14px; overflow-wrap: anywhere; background: #fff; border: 1px solid #e3e8f1; flex-shrink: 0; }
.chat-message.from-admin { align-self: flex-start; background: #edf4ff; border-color: #d5e4ff; }
.chat-message.from-user { align-self: flex-end; }
.chat-message p { white-space: pre-wrap; line-height: 1.8; margin: 7px 0; }
.chat-message time { color: #718096; font-size: 11px; }
.chat-composer { display: grid; gap: 10px; margin-top: 16px; }
.chat-composer textarea { width: 100%; resize: vertical; line-height: 1.8; }
.chat-composer button { justify-self: start; min-width: 110px; }
#userChatOlder, #userOrdersMore, #userFinanceMore, #usersLoadMore { margin: 12px 0; }
.unread-chat { background: #fff1db; color: #805500; font-size: 11px; border-radius: 20px; padding: 5px 9px; display: inline-block; margin: 5px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

/* Ops & Misc */
.ops-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.ops-filters label { display: grid; gap: 7px; }
.ops-filters input, .ops-filters select { width: 100%; padding: 10px; border: 1px solid #ccd6e5; border-radius: 8px; }
td small { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.application-review-dialog { width: min(560px, calc(100vw - 32px)); max-height: 85vh; overflow: auto; border: 0; border-radius: 20px; padding: 24px; color: #172b4d; background: #fff; box-shadow: 0 24px 80px #0004; }
.application-review-dialog::backdrop { background: #0f172a80; }
.application-review-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.application-review-head h2 { margin: 0 0 16px; font-size: 22px; }
.application-review-actions { display: flex; gap: 12px; margin-top: 20px; }
.application-review-actions button { flex: 1; min-height: 48px; font-size: 18px; }
.application-review-actions .danger { background: #b42318; color: #fff; border: 0; border-radius: 12px; }
.review-result { white-space: pre-wrap; overflow-wrap: anywhere; }
.application-review-dialog .detail-row { overflow-wrap: anywhere; }
.account-uid { display: block; max-width: 320px; overflow-wrap: anywhere; font-size: 12px; color: #64748b; margin-top: 6px; }
#customerSearchForm { flex-wrap: wrap; margin-bottom: 12px; }

/* Courier Map */
.courier-live-map { width: 100%; height: 390px; min-height: 280px; border-radius: 16px; border: 1px solid #e5eaf3; overflow: hidden; background: #eef3fa; margin-top: 14px; z-index: 0; }
#courierLocationStatus { font-size: 13px; margin: 8px 0; }

/* Responsive */
@media (max-width: 980px) {
  .admin-app { grid-template-columns: 200px 1fr; }
  .main { padding: 0 18px 30px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .admin-app { display: block; }
  .sidebar { position: relative; height: auto; overflow: visible; padding: 18px 12px; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .nav-item { font-size: 13px; padding: 11px 9px; }
  .main { padding: 0 12px 24px; }
  .topbar { align-items: flex-start; padding: 18px 0; }
  .topbar h1 { font-size: 22px; }
  .stats-grid, .details-grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .search { max-width: none; }
  .event { grid-template-columns: 1fr; }
  .detail-row { flex-direction: column; gap: 5px; }
  .detail-row strong { text-align: right; }
  .admin-badge { max-width: 48%; overflow-wrap: anywhere; }
  .stat { padding: 18px; }
  .list-card { flex-wrap: wrap; }
  .chat-message { max-width: 95%; }
  .user-search-form > * { width: 100%; }
  .national-id-row { flex-wrap: wrap; }
  .chat-messages { height: 320px; }
  .courier-live-map { height: 300px; }
  .ops-filters { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .stat, .nav-item, .list-card, table tbody tr { transition: none; }
}

/* ==========================================================
   HGO Admin — Premium Dark Theme
   Visual-only override; no JavaScript or API changes.
   ========================================================== */
:root {
  color-scheme: dark;
  --hgo-blue: #5b9cff;
  --hgo-navy: #0b1424;
  --hgo-border: #293a52;
  --hgo-muted: #a3b2c8;
  --hgo-bg: #09111f;
  --hgo-surface: #111e31;
  --hgo-surface-raised: #17263b;
  --hgo-text: #eaf2ff;
  --hgo-subtle: #a3b2c8;
  color: var(--hgo-text);
  background: var(--hgo-bg);
}
body { background: var(--hgo-bg); color: var(--hgo-text); }
button, input, select, textarea { color: inherit; }
button { transition: background-color .18s ease, border-color .18s ease; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible { outline: 3px solid #78adff; outline-offset: 2px; }
.sidebar {
  background: linear-gradient(180deg, #101d32 0%, #0b1424 100%);
  border-inline-end: 1px solid #293a52;
  box-shadow: none;
}
.sidebar .brand { border-bottom-color: #293a52; }
.sidebar .brand > span { color: #edf4ff; }
.sidebar .nav-item { color: #c1cee1; }
.sidebar .nav-item:hover { background: #20324c; color: #fff; }
.sidebar .nav-item.active { background: #2259b8; color: #fff; box-shadow: inset 3px 0 #8cbdff; }
.logout { background: #3a2230; color: #ffbfc8; }
.logout:hover { background: #56303d; }
.topbar { border-bottom-color: #293a52; }
.topbar h1, .panel h2, .panel h3, .list-card h4 { color: #f1f6ff; }
.topbar p, .panel-head p { color: var(--hgo-subtle); }
.admin-badge, .stat, .panel, .list-card {
  background: var(--hgo-surface);
  color: var(--hgo-text);
  border-color: var(--hgo-border);
  box-shadow: 0 8px 26px rgba(0,0,0,.12);
}
.stat::before { background: #5b9cff; }
.stat:hover, .list-card:hover { border-color: #5485c4; box-shadow: 0 10px 26px rgba(0,0,0,.22); }
.stat span, .admin-badge span, .list-card p, .detail-row span,
.event small, .muted { color: var(--hgo-subtle); }
.stat strong, .admin-badge strong { color: #f1f6ff; }
.search, .login-card input, .ops-filters input, .ops-filters select,
textarea, select, input {
  background: #0d192a;
  border-color: #34465f;
  color: #eef5ff;
}
input::placeholder, textarea::placeholder { color: #9cacc2; opacity: 1; }
.search:focus, .login-card input:focus { border-color: #78adff; box-shadow: 0 0 0 3px #3974c433; }
.login-page { background: radial-gradient(circle at 75% 5%, #19365b 0, #09111f 55%); }
.login-card { background: #142238; border-color: #34465f; box-shadow: 0 22px 65px #0007; }
.login-card h1 { color: #f1f6ff; }
.login-card > p { color: #b4c3d7; }
.login-card label { color: #dfeaff; }
.primary, .primary-button { background: #286cdb; color: #fff; border-color: #4e92ff; }
.primary:hover, .primary-button:hover { background: #377df0; }
.secondary { background: #233b5d; color: #d6e7ff; }
.secondary:hover { background: #2e4d76; }
th { background: #1a2a40; color: #d6e4f8; }
td, th { border-bottom-color: #293a52; }
table tbody tr:hover, .order-row:hover, .user-row:hover { background: #1d304a; }
.detail-row, .event, .national-id-row { border-bottom-color: #293a52; }
.detail-row strong { color: #edf4ff; }
.badge { background: #293a52; color: #e0eaff; }
.badge.good, .approve { background: #173e32; color: #91edc0; }
.badge.warn, .unread-chat { background: #4b361a; color: #ffda92; }
.badge.bad, .reject { background: #4c2630; color: #ffb3c0; }
.badge.info { background: #173b67; color: #b5d7ff; }
.good-text { color: #91edc0; }
.danger-text, .message { color: #ff9fac; }
.empty { color: #b0bfd2; }
.toast { background: #243c5c; color: #f4f8ff; border: 1px solid #4c6b91; }
.danger-button { background: #241b28; color: #ffb2be; border-color: #a84c62; }
.danger-button:hover { background: #432532; }
.chat-messages { background: #0c1829; border-color: #293a52; }
.chat-message { background: #1a2a40; border-color: #34465f; color: #edf4ff; }
.chat-message.from-admin { background: #193b68; border-color: #3566a2; }
.chat-message.from-user { background: #223148; }
.chat-message time, .account-uid { color: #b3c3d7; }
.unread { background: #172e4c; border-right-color: #6aa6ff; }
.profile-order { background: #111e31; color: #edf4ff; }
.courier-live-map { background: #14243a; border-color: #34465f; }
.application-review-dialog { background: #142238; color: #edf4ff; border: 1px solid #34465f; }
.application-review-dialog::backdrop { background: #030912cc; }
.application-review-head h2 { color: #f1f6ff; }
.application-review-actions .danger { background: #b43242; color: #fff; }
.ops-stat:hover { border-color: #78adff; }
button:disabled, textarea:disabled { opacity: .5; }
@media (max-width: 720px) {
  .sidebar { border-inline-end: 0; border-bottom: 1px solid #293a52; }
  .admin-badge { background: #17263b; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
