:root {
  --accent: #3a7bfd;
  --purple: #9b6bff;
  --blue: #3a9bfd;
  --green: #2ec06e;
  --amber: #f5a623;
  --red: #ff5b5b;
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e6e9ef;
  --text: #1f2430;
  --text-mut: #8991a3;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

/* Đảm bảo [hidden] LUÔN thắng mọi rule display:flex/grid phía dưới (kể cả .login-screen,
   .app-shell...) — nếu không, 2 màn hình login/dashboard sẽ hiển thị chồng lên nhau vì
   CSS của mình có cùng độ ưu tiên với rule [hidden] mặc định của trình duyệt và đứng sau. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

/* ── Login screen — split layout (light form / gradient hero) ─ */
.login-screen {
  min-height: 100vh;
  display: flex;
  background: #fff;
}

/* Left: white panel with the form */
.login-left {
  flex: 0 0 440px;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  background: #fff;
  position: relative;
}
.login-left-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 0 0;
}
.lang-toggle {
  margin-top: 20px;
  padding: 7px 12px;
  border: 1px solid #e6e6ef;
  border-radius: 20px;
  background: #f6f7fb;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.lang-toggle:hover { background: #eef1f6; }
.brand-mark {
  padding: 32px 0 0 40px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--accent);
}
.login-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 48px 60px;
}
.avatar-circle {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 1.5px solid #dcdfe8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  flex: 0 0 auto;
}
.login-form { width: 100%; max-width: 300px; }

.field-label { display: block; font-size: 12px; color: var(--text-mut); margin: 0 0 8px; text-align: center; }

.input-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f6f7fb;
  border: 1px solid #e6e6ef;
  border-radius: 24px;
  padding: 12px 18px;
  margin-bottom: 14px;
}
.input-pill:focus-within { border-color: var(--accent); background: #fff; }
.input-pill-center { justify-content: center; }
.input-icon { display: flex; color: #9a9aa8; flex: 0 0 auto; }
.input-pill input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--text);
}
.input-pill-center input { flex: none; width: 140px; text-align: center; letter-spacing: .3em; font-size: 16px; }

.login-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin: 2px 0 22px;
  font-size: 13px;
  color: var(--text-mut);
}
.remember-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.remember-label input { cursor: pointer; }

.btn-gradient {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), var(--purple) 65%, #5cd6c8);
  background-size: 160% 160%;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(58,123,253,0.30);
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn-gradient:hover { transform: translateY(-1px); box-shadow: 0 14px 28px rgba(58,123,253,0.36); }
.btn-gradient:active { transform: translateY(0); }

.login-error {
  margin-top: 14px;
  color: var(--red);
  font-size: 13px;
  text-align: center;
}

/* Right: colorful gradient hero panel */
.login-right {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  background: linear-gradient(160deg, #1b1f2e 0%, #2b2560 45%, #163a5c 100%);
}
.login-right .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .65;
}
.blob-1 { width: 420px; height: 420px; top: -80px; left: -60px; background: var(--purple); }
.blob-2 { width: 380px; height: 380px; bottom: -100px; left: 120px; background: #5cd6c8; opacity: .5; }
.blob-3 { width: 340px; height: 340px; top: 30%; right: -100px; background: var(--accent); }
.login-right-content {
  position: relative;
  z-index: 2;
  padding: 0 56px;
  max-width: 460px;
  color: #fff;
}
.login-right-content h1 { font-size: 38px; font-weight: 700; margin: 0 0 14px; }
.login-right-content p { font-size: 15px; line-height: 1.6; color: rgba(255,255,255,0.78); margin: 0; }

@media (max-width: 900px) {
  .login-right { display: none; }
  .login-left { flex: 1 1 auto; max-width: none; }
}

/* ── App shell ─────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}
.sidebar-logo {
  font-size: 18px; font-weight: 700; color: var(--accent); padding: 0 20px 20px;
  display: block; text-decoration: none; cursor: pointer;
}
.sidebar-logo:hover { opacity: .85; }
.sidebar-nav { flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: default;
}
.nav-item.active { color: var(--accent); background: #eef3ff; border-right: 3px solid var(--accent); font-weight: 600; }
.nav-item.disabled { color: #c3c8d4; cursor: not-allowed; }
.nav-item[data-view]:not(.active) { cursor: pointer; }
.nav-item[data-view]:not(.active):hover { background: #f2f4f8; }
.nav-icon { width: 18px; text-align: center; }

.main { flex: 1; padding: 24px 28px 40px; min-width: 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px 0; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-user { font-size: 12.5px; color: var(--text-mut); padding: 0 4px; white-space: nowrap; }

/* ── Nút mở menu (chỉ hiện trên mobile/tablet, ẩn mặc định trên desktop) ── */
.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
  flex: 0 0 auto;
}
.sidebar-toggle-btn:hover { background: #f2f4f8; }

/* ── Lớp phủ tối phía sau menu trượt trên mobile ─────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 30, 0.45);
  z-index: 999;
}
.sidebar-overlay.open { display: block; }

.btn-ghost {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: #f2f4f8; }
.btn-block { width: 100%; }

.banner-error {
  background: #fdeeee;
  border: 1px solid #f3c8c8;
  color: #c0392b;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}
.banner-success {
  background: #eaf9f0;
  border: 1px solid #bfe8cf;
  color: #1f7a44;
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 14px;
  font-size: 13px;
}

/* ── Views (Dashboard / Licenses / Customers) — ẩn/hiện đã xử lý bởi
   rule [hidden] chung ở đầu file. ── */

/* ── Forms (tạo license / thêm khách hàng) ─────────────────── */
.data-form { margin-top: 4px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px 16px;
  margin-bottom: 16px;
}
.form-field { display: flex; flex-direction: column; }
.form-field-wide { grid-column: 1 / -1; }
.form-field label { font-size: 12px; color: var(--text-mut); margin-bottom: 6px; }
.form-field input, .form-field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  background: #f8f9fb;
  color: var(--text);
  font-family: inherit;
}
.form-field input:focus, .form-field select:focus { outline: none; border-color: var(--accent); background: #fff; }
.form-field input:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: #2e63d6; }
.btn-primary:disabled { background: #b7c3d6; cursor: not-allowed; }
.btn-inline { width: auto; }

/* ── Data tables (licenses / customers) ────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-mut);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8f9fc; }
.data-table .key-cell { font-family: Consolas, monospace; font-size: 12px; white-space: nowrap; }
.data-table .muted-cell { color: var(--text-mut); }

.badge-status {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-active   { background: #e6f7ec; color: #1f9d55; }
.badge-unused   { background: #eef1f6; color: #6b7280; }
.badge-expired  { background: #fdeeee; color: #c0392b; }
.badge-revoked  { background: #fdeeee; color: #c0392b; }
.badge-trial    { background: #fff4e0; color: #b8860b; }
.badge-locked   { background: #ffe9d6; color: #b34700; margin-left: 6px; }

.hwid-cell { font-family: monospace; font-size: 12px; color: #4b5563; }

.btn-copy {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 11.5px;
  cursor: pointer;
  color: var(--text);
}
.btn-copy:hover { background: #f2f4f8; }
.btn-copy:disabled { opacity: .5; cursor: not-allowed; }
.btn-copy + .btn-copy { margin-left: 6px; }

/* ── Stat cards ────────────────────────────────────────────── */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 2px 10px rgba(20,20,40,0.05);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.stat-purple { background: linear-gradient(135deg, #a879ff, #8b5cf6); }
.stat-blue   { background: linear-gradient(135deg, #57a8ff, #3a7bfd); }
.stat-green  { background: linear-gradient(135deg, #4ad080, #2ec06e); }
.stat-amber  { background: linear-gradient(135deg, #ffbf5c, #f5a623); }
.stat-icon { font-size: 18px; opacity: 0.85; margin-bottom: 8px; }
.stat-num { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; opacity: 0.9; margin-top: 6px; }

/* ── Panels / charts ───────────────────────────────────────── */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.panel {
  background: var(--card);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 2px 10px rgba(20,20,40,0.05);
}
.panel-title { font-size: 12px; color: var(--text-mut); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 14px; }
.panel-chart { min-height: 200px; }

.chart-svg { width: 100%; height: 160px; display: block; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 2.5; }
.chart-area { fill: rgba(58,155,253,0.14); stroke: none; }
.chart-dot { fill: var(--blue); }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; overflow-x: auto; padding-top: 6px; }
.bar-col { display: flex; flex-direction: column; align-items: center; min-width: 30px; }
.bar-rect { width: 20px; border-radius: 4px 4px 0 0; background: var(--blue); }
.bar-label { font-size: 10px; color: var(--text-mut); margin-top: 6px; white-space: nowrap; }

.tier-row { display: flex; gap: 14px; flex-wrap: wrap; }
.tier-badge {
  flex: 1;
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tier-badge .n { font-size: 22px; font-weight: 700; }
.tier-badge .label { font-size: 12px; color: var(--text-mut); margin-top: 4px; }
.tier-basic .n { color: #6b7280; }
.tier-pro .n { color: var(--accent); }
.tier-enterprise .n { color: var(--purple); }

.activity-list, .expiring-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}
.activity-list li, .expiring-list li {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.activity-list li:last-child, .expiring-list li:last-child { border-bottom: none; }
.activity-action {
  display: inline-block;
  min-width: 96px;
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}
.activity-line, .expiring-line { color: #4b5163; }
.expiring-line { color: #b8860b; }

.empty-note { color: var(--text-mut); font-size: 12.5px; }

/* ── Security view (2FA + tài khoản quản trị) ──────────────── */
.muted-note { color: var(--text-mut); font-size: 12.5px; line-height: 1.5; margin: 0 0 14px; }
.secret-box {
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  word-break: break-all;
}
.secret-box code { font-family: Consolas, monospace; font-size: 13px; color: var(--accent); }

.btn-danger {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--red);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: #e64545; }
.btn-copy-danger { color: var(--red); border-color: #f3c8c8; }
.btn-copy-danger:hover { background: #fdeeee; }

.admin-users-table { margin-top: 16px; }

/* ── Tệp Post (upload, giống card "POST FILE" ở app Desktop) ─ */
.inline-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted-inline { font-size: 12.5px; color: var(--text-mut); }

/* ── Chat view (chat trực tuyến với khách hàng) ────────────── */
.nav-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  margin-left: auto;
}

.chat-panel { padding: 0; overflow: hidden; }
.chat-layout { display: flex; height: 62vh; min-height: 460px; }

.chat-thread-list-col {
  width: 260px;
  flex: 0 0 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-thread-list-header {
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-mut);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.chat-thread-list { flex: 1; overflow-y: auto; }
.chat-thread-list-empty { padding: 14px 16px; }

.chat-thread-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.chat-thread-item:hover { background: #f8f9fc; }
.chat-thread-item.active { background: #eef3ff; }
.chat-thread-item.closed { opacity: .6; }
.chat-thread-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-thread-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread-unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: 0 0 auto; }
.chat-thread-preview {
  font-size: 12px;
  color: var(--text-mut);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-thread-time { font-size: 10.5px; color: var(--text-mut); margin-top: 4px; }

.chat-conversation-col { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-mut);
  font-size: 13.5px;
  padding: 20px;
}
.chat-conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-conversation-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.chat-customer-meta { margin: 2px 0 0; }
.chat-conversation-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg-bubble {
  max-width: 75%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg-customer { align-self: flex-start; background: #eef1f6; color: var(--text); border-bottom-left-radius: 3px; }
.chat-msg-admin { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg-meta { font-size: 10.5px; color: var(--text-mut); margin-top: 3px; }

.chat-reply-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.chat-reply-input {
  flex: 1;
  resize: vertical;
  min-height: 40px;
  max-height: 140px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: #f8f9fb;
  color: var(--text);
}
.chat-reply-input:focus { outline: none; border-color: var(--accent); background: #fff; }

@media (max-width: 900px) {
  .chat-layout { flex-direction: column; height: auto; }
  .chat-thread-list-col { width: auto; flex: 0 0 auto; max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-messages { max-height: 320px; }
}

@media (max-width: 900px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .chart-row { grid-template-columns: 1fr; }

  /* Sidebar biến thành menu trượt (drawer) thay vì ẩn hẳn — vẫn giữ đủ
     chức năng chuyển view (Dashboard/Licenses/Customers/Bảo mật/Chat)
     trên điện thoại, không mất tính năng nào so với bản web. */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 24px rgba(0, 0, 0, 0.18);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle-btn { display: inline-flex; }

  .main { padding: 16px 16px 32px; }
  .topbar h1 { font-size: 17px; }
  .topbar-actions { gap: 6px; }
  .btn-ghost { padding: 8px 10px; font-size: 12px; }

  .form-grid { grid-template-columns: 1fr; }
  .data-table { font-size: 12px; }
}

@media (max-width: 480px) {
  .stat-row { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 21px; }
  .main { padding: 12px 12px 28px; }
}
