/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #222535;
  --border:    #2e3347;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --dim:       #525d72;
  --accent:    #4f7ef7;
  --accent-bg: rgba(79,126,247,0.12);
  --green:     #22c55e;
  --green-bg:  rgba(34,197,94,0.12);
  --yellow:    #eab308;
  --yellow-bg: rgba(234,179,8,0.12);
  --red:       #ef4444;
  --red-bg:    rgba(239,68,68,0.12);
  --purple:    #a855f7;
  --purple-bg: rgba(168,85,247,0.12);
  --radius:    8px;
  --sidebar-w: 240px;
  --topbar-h:  56px;
  --transition: 0.15s ease;
}

/* ── Base ── */
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; overflow-wrap: break-word; word-break: break-word; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Utility ── */
.hidden { display: none !important; }
.w-full { width: 100%; }
.text-muted { color: var(--muted); }
.text-dim { color: var(--dim); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-danger { color: var(--red); }
.font-semibold { font-weight: 600; }
.font-mono { font-family: 'Courier New', monospace; font-size: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; align-items: center; gap: 8px; }
.opacity-50 { opacity: 0.5; }

/* ── Auth Layout ── */
.auth-layout { height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-bottom: 28px; color: var(--text); }
.auth-logo svg { color: var(--accent); }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.auth-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth-footer { margin-top: 20px; font-size: 13px; color: var(--muted); text-align: center; }

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

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-w); height: 100%; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: transform var(--transition); z-index: 200; }
.sidebar-logo { height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 20px; font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.sidebar-logo svg { color: var(--accent); flex-shrink: 0; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius); color: var(--muted); font-size: 13px; font-weight: 500; transition: var(--transition); cursor: pointer; }
.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item:hover svg { opacity: 1; }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }
.nav-item.active svg { opacity: 1; color: var(--accent); }
.nav-label { padding: 16px 12px 6px; font-size: 10px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 12px; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-width: 0; }
.user-avatar { width: 32px; height: 32px; border-radius: 6px; background: var(--accent-bg); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-details { flex: 1; min-width: 0; }
.user-name { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 11px; color: var(--muted); }
.footer-actions { display: flex; gap: 6px; }

/* ── Mobile Topbar ── */
.mobile-topbar { display: none; }
.hamburger { background: none; border: none; cursor: pointer; color: var(--text); display: flex; padding: 6px; border-radius: 6px; }
.hamburger:hover { background: var(--surface2); }
.mobile-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.mobile-logo svg { color: var(--accent); }
.mobile-user-avatar { width: 30px; height: 30px; border-radius: 6px; background: var(--accent-bg); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 190; opacity: 0; pointer-events: none; transition: opacity var(--transition); }
.sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

/* ── Main Content ── */
.main-content { flex: 1; height: 100vh; overflow-y: auto; overflow-x: hidden; min-width: 0; }
.page { max-width: 1080px; margin: 0 auto; padding: 32px 24px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; }
.page-subtitle { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card-title { font-size: 15px; font-weight: 600; }

/* ── Stat Grid ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; margin-bottom: 6px; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; transition: var(--transition); border: 1px solid var(--border); background: var(--surface2); color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--border); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3d6de0; border-color: #3d6de0; color: #fff; }
.btn-danger { background: var(--red-bg); border-color: rgba(239,68,68,0.3); color: var(--red); }
.btn-danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--radius); background: transparent; border: 1px solid var(--border); color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: var(--transition); position: relative; flex-shrink: 0; }
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.btn-danger { border-color: rgba(239,68,68,0.2); color: var(--red); }
.btn-icon.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge svg { width: 12px; height: 12px; }
.badge-blue   { background: var(--accent-bg); color: var(--accent); }
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray   { background: rgba(82,93,114,0.2); color: var(--muted); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.form-input { width: 100%; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 13px; transition: border-color var(--transition); }
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input::placeholder { color: var(--dim); }
select.form-input { cursor: pointer; }
.form-hint { font-size: 11px; color: var(--dim); margin-top: 4px; display: block; }
.form-error { background: var(--red-bg); border: 1px solid rgba(239,68,68,0.25); color: var(--red); padding: 8px 12px; border-radius: var(--radius); font-size: 13px; margin-top: 8px; }

/* ── Tables ── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; min-width: 0; }
th { background: var(--surface2); padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 700; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* ── Table Mobile ── */
@media (max-width: 640px) {
  .table-wrap { overflow-x: auto; }
  table { min-width: 500px; }
}

/* ── Dialog Grid ── */
.dialog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 12px; }
.dialog-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 12px; display: flex; flex-direction: column; align-items: center; text-align: center; transition: border-color var(--transition); cursor: pointer; position: relative; }
.dialog-card:hover { border-color: #3e4560; }
.dialog-card.selected { border-color: var(--accent); background: var(--accent-bg); }
.dialog-card.selected::after { content: '✓'; position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; background: var(--accent); border-radius: 50%; color: #fff; font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.dialog-avatar { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--border); margin-bottom: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: var(--surface2); flex-shrink: 0; }
.dialog-avatar img { width: 100%; height: 100%; object-fit: cover; }
.dialog-avatar-placeholder { font-size: 22px; font-weight: 700; color: var(--muted); }
.dialog-name { font-weight: 600; font-size: 13px; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.dialog-info { width: 100%; }

/* ── Account Grid ── */
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; transition: border-color var(--transition); cursor: pointer; }
.account-card:hover { border-color: #3e4560; }
.account-card.selected { border-color: var(--accent); background: var(--accent-bg); }
.account-card-top { display: flex; align-items: center; gap: 12px; }
.tg-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-bg); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; flex-shrink: 0; overflow: hidden; }
.tg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-info { flex: 1; min-width: 0; }
.account-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-phone { font-size: 12px; color: var(--muted); }

/* ── Toolbar / Tabs ── */
.chats-toolbar { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface2); padding: 3px; border-radius: var(--radius); border: 1px solid var(--border); }
.filter-tab { padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 500; color: var(--muted); cursor: pointer; transition: var(--transition); display: flex; align-items: center; gap: 5px; border: none; background: none; white-space: nowrap; }
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--surface); color: var(--text); font-weight: 600; }
.search-wrap { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); flex: 1; min-width: 160px; }
.search-wrap svg { color: var(--dim); flex-shrink: 0; }
.search-input { border: none !important; background: none !important; padding: 8px 0 !important; box-shadow: none !important; flex: 1; min-width: 0; }

/* ── Floating Action Bar ── */
.dump-action-bar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface2); border: 1px solid var(--border); padding: 10px 20px; border-radius: 50px; display: flex; align-items: center; gap: 16px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); z-index: 500; width: calc(100% - 32px); max-width: max-content; justify-content: space-between; }
#selected-count { font-weight: 600; color: var(--accent); font-size: 13px; }

/* ── Progress ── */
.progress-bar-wrap { width: 100%; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width 0.4s ease; border-radius: 2px; }

/* ── Modal ── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); z-index: 10; }
.modal-header h3 { font-size: 15px; font-weight: 600; }
#modal-body { padding: 20px; }

/* ── Step Indicators ── */
.step-indicator { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; }
.step { width: 28px; height: 28px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.step.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.step.done { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.step-line { flex: 1; height: 1px; background: var(--border); max-width: 32px; }

/* ── Notifications Panel ── */
.notif-panel { position: fixed; top: 0; right: 0; bottom: 0; width: 300px; background: var(--surface); border-left: 1px solid var(--border); z-index: 1100; display: flex; flex-direction: column; }
.notif-panel-header { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.notif-panel-title { font-weight: 600; font-size: 14px; }
.notif-list { flex: 1; overflow-y: auto; padding: 8px; }
.notif-item { display: flex; gap: 10px; padding: 10px; border-radius: var(--radius); }
.notif-item:hover { background: var(--surface2); }
.notif-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.notif-dot.success { background: var(--green); }
.notif-dot.error { background: var(--red); }
.notif-dot.info { background: var(--accent); }
.notif-content { flex: 1; min-width: 0; }
.notif-msg { font-size: 13px; line-height: 1.4; }
.notif-time { font-size: 11px; color: var(--dim); margin-top: 3px; }
.notif-empty { text-align: center; padding: 40px 16px; color: var(--dim); font-size: 13px; }
.notif-badge { position: absolute; top: 1px; right: 1px; min-width: 15px; height: 15px; padding: 0 3px; background: var(--red); color: #fff; border-radius: 8px; font-size: 9px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface); }

/* ── Toasts ── */
#toast-container { position: fixed; bottom: 24px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: calc(100vw - 40px); }
.toast { pointer-events: auto; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: flex-start; gap: 10px; font-size: 13px; min-width: 240px; max-width: 340px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

/* ── Spinner / Empty ── */
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; color: var(--muted); gap: 12px; }
.empty-state svg { opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ── Toggle Row (Admin Config) ── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-weight: 500; font-size: 14px; }
.toggle-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Misc inline helpers used in app.js ── */
.font-semibold { font-weight: 600; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; left: 0; height: 100%; transform: translateX(-100%); z-index: 200; }
  .sidebar.visible { transform: translateX(0); }
  .mobile-topbar { display: flex; position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border); z-index: 180; padding: 0 16px; align-items: center; justify-content: space-between; }
  .main-content { padding-top: var(--topbar-h); }
  .page { padding: 20px 16px; }
  .page-title { font-size: 18px; }
  .stat-grid { gap: 10px; }
  td { word-break: break-word; }
}

@media (max-width: 480px) {
  .auth-card { padding: 24px 20px; }
  .dump-action-bar { flex-wrap: wrap; gap: 10px; border-radius: 12px; bottom: 12px; padding: 12px 16px; }
  .chats-toolbar { flex-direction: column; align-items: stretch; }
  .filter-tabs { overflow-x: auto; flex-wrap: nowrap; }
}
