/* WaChat CRM — Premium UI */
:root {
  --bg: #f7f8fa;
  --bg2: #ffffff;
  --bg3: #f0f2f5;
  --border: #e4e6ea;
  --text: #1a1d23;
  --text2: #6b7280;
  --text3: #9ca3af;
  --primary: #25D366;
  --primary-dark: #1db954;
  --primary-light: #dcfce7;
  --blue: #3b82f6;
  --blue-light: #eff6ff;
  --purple: #8b5cf6;
  --purple-light: #f3f0ff;
  --teal: #14b8a6;
  --teal-light: #f0fdfa;
  --red: #ef4444;
  --red-light: #fef2f2;
  --amber: #f59e0b;
  --amber-light: #fffbeb;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #13151e;
  --border: #2a2d3a;
  --text: #e8eaf0;
  --text2: #8b8fa8;
  --text3: #555870;
  --primary-light: #0d2e1a;
  --blue-light: #0d1a2e;
  --purple-light: #1a1035;
  --teal-light: #0a2020;
  --red-light: #2e0d0d;
  --amber-light: #2e1d00;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
}
.sidebar-logo {
  padding: 18px 20px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 700; color: var(--text);
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text3);
  padding: 10px 20px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; color: var(--text2); cursor: pointer;
  border-radius: 0; transition: all .15s; font-size: 13.5px;
  text-decoration: none !important; border: none; background: none; width: 100%;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.nav-item svg { flex-shrink: 0; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h); background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.topbar-left { font-size: 15px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.theme-toggle {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg3);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text2); transition: all .15s;
}
.theme-toggle:hover { background: var(--bg); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px; border-radius: 20px;
  border: 1px solid var(--border); cursor: pointer;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-dark);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.user-name { font-size: 13px; font-weight: 500; }

/* ── LAYOUT ── */
.main-content { margin-left: var(--sidebar-w); min-height: 100vh; }
.page-content { padding: 24px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-sub { font-size: 13px; color: var(--text2); margin-top: 2px; }

/* ── STATS GRID ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg2); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 18px 20px;
  display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon.teal { background: var(--teal-light); color: var(--teal); }
.stat-icon.blue { background: var(--blue-light); color: var(--blue); }
.stat-icon.purple { background: var(--purple-light); color: var(--purple); }
.stat-icon.green { background: var(--primary-light); color: var(--primary-dark); }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* ── CONTENT GRID ── */
.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .content-grid { grid-template-columns: 1fr; } }

/* ── CARD ── */
.card {
  background: var(--bg2); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 20px; }

/* ── ACCOUNT ROW ── */
.account-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.account-row:last-child { border-bottom: none; }
.account-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-dark);
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.account-avatar.large { width: 46px; height: 46px; font-size: 16px; }
.account-info { flex: 1; }
.account-name { font-weight: 600; font-size: 14px; }
.account-phone { font-size: 12px; color: var(--text2); }

/* ── ACCOUNTS GRID ── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.account-card {
  background: var(--bg2); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 20px; box-shadow: var(--shadow);
}
.account-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.account-card-header .account-name { font-size: 15px; flex: 1; }
.account-card-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── QR ── */
.qr-container { text-align: center; padding: 16px 0; }
.qr-hint { font-size: 12px; color: var(--text2); margin-bottom: 10px; }
#qr-canvas > canvas { border-radius: 8px; }
.empty-card {
  background: var(--bg2); border-radius: var(--radius);
  border: 2px dashed var(--border); padding: 40px 20px;
  text-align: center; color: var(--text2);
  grid-column: 1 / -1;
}
.empty-card p { margin-bottom: 16px; }
.empty-state { text-align: center; padding: 20px; color: var(--text2); }

/* ── MESSAGES ── */
.msg-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.msg-row:last-child { border-bottom: none; }
.msg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.msg-avatar.incoming { background: var(--blue-light); color: var(--blue); }
.msg-avatar.outgoing { background: var(--primary-light); color: var(--primary-dark); }
.msg-info { flex: 1; min-width: 0; }
.msg-name { font-size: 13px; font-weight: 600; }
.msg-text { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-time { font-size: 11px; color: var(--text3); white-space: nowrap; }

/* ── BADGES ── */
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 20px; white-space: nowrap;
}
.badge-success { background: var(--primary-light); color: var(--primary-dark); }
.badge-warning { background: var(--amber-light); color: var(--amber); }
.badge-danger { background: var(--red-light); color: var(--red); }
.badge-info { background: var(--blue-light); color: var(--blue); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13.5px;
  font-weight: 500; cursor: pointer; transition: all .15s;
  border: 1px solid transparent; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg3); }
.btn-danger { background: var(--red-light); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-control {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg3); color: var(--text);
  font-size: 14px; transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); background: var(--bg2); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.modal {
  background: var(--bg2); border-radius: 14px; width: 100%; max-width: 440px;
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.modal-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: var(--text2); line-height: 1; padding: 0 4px;
}
.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── ALERT ── */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; }
.alert-danger { background: var(--red-light); color: var(--red); border: 1px solid #fca5a5; }
.alert-success { background: var(--primary-light); color: var(--primary-dark); }

/* ── TABLE ── */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.table th { font-weight: 600; color: var(--text2); background: var(--bg3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:hover td { background: var(--bg3); }

/* ── LOGIN ── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card { background: var(--bg2); border-radius: 16px; border: 1px solid var(--border); padding: 36px 32px; box-shadow: var(--shadow-md); }
.login-logo { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin-bottom: 28px; }
