/* OMB - trang quản lý trên điện thoại. Thiết kế ưu tiên điện thoại (mobile-first), giao diện tối giống phần mềm. */
:root {
  --bg: #0d1420; --side: #111a28; --card: #162030; --card2: #1b2638; --border: #26334a;
  --text: #e6ebf2; --muted: #8b99b0; --blue: #2f6fed; --blue-h: #2559c7; --green: #1fa45a; --orange: #f08c1a;
  --red: #e5484d; --purple: #7c5cf0; --teal: #14a3a8; --gray: #26334a;
  --tap: 48px; --radius: 14px; --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden; -webkit-tap-highlight-color: rgba(47, 111, 237, .25);
}
.noscript { padding: 24px; }
h1 { font-size: 1.35rem; margin: 0; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
h3 { font-size: 1rem; margin: 0 0 4px; overflow-wrap: anywhere; }
p { margin: 6px 0; }
a { color: #7fa7ff; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.hidden { display: none !important; }

/* ---------- Khung ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top, 0px));
  background: rgba(17, 26, 40, .97); border-bottom: 1px solid var(--border);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 12px; background: transparent;
  color: var(--text); font-size: 1.4rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; position: relative;
}
.icon-btn:active, .icon-btn:focus-visible { background: var(--gray); }
.badge-dot {
  position: absolute; top: 4px; right: 2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: .75rem; line-height: 20px; font-weight: 700;
}
main { padding: 14px 14px calc(var(--nav-h) + 24px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }

/* Thanh điều hướng dưới (điện thoại) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  min-height: var(--nav-h); padding-bottom: var(--safe-b); background: var(--side); border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tap);
  color: var(--muted); text-decoration: none; font-size: .78rem; background: none; border: 0; font-family: inherit; cursor: pointer;
}
.bottom-nav .ico { font-size: 1.35rem; line-height: 1; }
.bottom-nav .active { color: #fff; }
.bottom-nav .active .ico { filter: drop-shadow(0 0 6px rgba(47, 111, 237, .9)); }

/* Menu trượt (hamburger) */
.drawer-bg { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55); }
.drawer {
  position: fixed; z-index: 41; top: 0; bottom: 0; left: 0; width: min(84vw, 320px); overflow-y: auto;
  background: var(--side); border-right: 1px solid var(--border); padding: 12px 10px calc(16px + var(--safe-b));
  transform: translateX(-102%); transition: transform .2s ease;
}
.drawer.open { transform: none; }
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 8px 14px; font-weight: 800; font-size: 1.2rem; }
.brand img { width: 36px; height: 36px; }
.brand small { display: block; font-weight: 400; font-size: .8rem; color: var(--muted); }
.menu a {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 8px 12px; margin: 2px 0; border-radius: 12px;
  color: var(--text); text-decoration: none; font-size: 1rem;
}
.menu a .ico { width: 28px; text-align: center; font-size: 1.2rem; }
.menu a.active { background: var(--blue); }
.menu a:active { background: var(--gray); }
.me { margin: 14px 4px 0; padding: 12px; border-radius: var(--radius); background: var(--card); }

/* ---------- Thành phần ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card.link { cursor: pointer; display: block; color: inherit; text-decoration: none; }
.card.link:active { background: var(--card2); }
.cards { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; flex-wrap: nowrap; }
.row.between > :first-child { min-width: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 8px 0 0; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { border-radius: var(--radius); padding: 12px; color: #fff; min-height: 76px; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.2; }
.stat span { font-size: .9rem; opacity: .95; }
.c-blue { background: var(--blue); } .c-green { background: var(--green); } .c-orange { background: var(--orange); }
.c-red { background: var(--red); } .c-purple { background: var(--purple); } .c-teal { background: var(--teal); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; background: var(--gray); color: var(--text); white-space: nowrap; }
.pill.green { background: rgba(31, 164, 90, .25); color: #5be39a; }
.pill.orange { background: rgba(240, 140, 26, .22); color: #ffb35c; }
.pill.red { background: rgba(229, 72, 77, .22); color: #ff8a8d; }
.pill.blue { background: rgba(47, 111, 237, .25); color: #9dbbff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); min-width: var(--tap);
  padding: 10px 16px; border: 0; border-radius: 12px; background: var(--gray); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn.primary { background: var(--blue); color: #fff; } .btn.green { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; } .btn.orange { background: var(--orange); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btns .btn { flex: 1 1 140px; }

label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .95rem; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: #0f1826; color: var(--text); font: inherit; font-size: 16px; /* >= 16px: iOS không tự phóng to */
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.search { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 12px; }

/* Công tắc bật/tắt cỡ ngón tay */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .sw { flex: 0 0 auto; width: 64px; height: 36px; border-radius: 18px; background: #3a4760; position: relative; transition: background .15s; }
.toggle .sw::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .sw { background: var(--green); }
.toggle input:checked + .sw::after { transform: translateX(28px); }
.toggle input:focus-visible + .sw { outline: 2px solid var(--blue); outline-offset: 2px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--side); margin-bottom: 12px; }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--blue); color: #fff; }

.progress { height: 12px; border-radius: 6px; background: #0f1826; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--green); border-radius: 6px; }
.progress > i.mid { background: var(--orange); } .progress > i.low { background: var(--red); }

/* Tin nhắn hội thoại */
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 16px; background: var(--card2); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: #1f3d78; }
.msg .meta { display: block; margin-top: 4px; font-size: .78rem; color: var(--muted); white-space: normal; }

.toast {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + var(--safe-b)); z-index: 60;
  padding: 14px 16px; border-radius: 14px; background: #24324a; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); font-weight: 600;
}
.toast.err { background: #8f2629; } .toast.ok { background: #176a3d; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.loading { text-align: center; color: var(--muted); padding: 24px; }

/* Đăng nhập */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 420px; padding: 22px; }
.login .brand { justify-content: center; padding-bottom: 6px; }
.lan-note { margin-top: 14px; font-size: .9rem; color: var(--muted); }
.lan-note.warn { color: var(--orange); }

/* Bảng có thể kéo ngang (chỉ dùng khi thật cần) */
.hscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Máy tính bảng / máy tính: menu cố định bên trái, nhiều cột ---------- */
@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .search { grid-template-columns: 2fr 1fr; }
}
@media (min-width: 960px) {
  .bottom-nav, .menu-btn, .drawer-bg { display: none !important; }
  .drawer { transform: none; width: 260px; }
  .shell { padding-left: 260px; }
  main { padding-bottom: 32px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .toast { left: auto; right: 24px; bottom: 24px; max-width: 420px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
