/* TelegramCRM - main.css */
/* Light / dark via [data-theme] on <html> */

:root {
  --bg0: #ffffff;
  --bg1: #f6f5f3;
  --bg2: #efede9;
  --border: rgba(0,0,0,.1);
  --border2: rgba(0,0,0,.18);
  --text1: #1a1a1a;
  --text2: #555450;
  --text3: #888680;
  --purple: #7F77DD;
  --purple-l: #AFA9EC;
  --purple-bg: #EEEDFE;
  --purple-dk: #534AB7;
  --teal: #1D9E75;
  --teal-bg: #E1F5EE;
  --amber: #BA7517;
  --amber-bg: #FAEEDA;
  --red: #E24B4A;
  --red-bg: #FCEBEB;
  --green: #3B6D11;
  --green-bg: #EAF3DE;
  --blue: #185FA5;
  --blue-bg: #E6F1FB;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --sidebar-w: 220px;
  --topbar-h: 52px;
  --transition: .15s ease;
}

[data-theme="dark"] {
  --bg0: #1e1e1e;
  --bg1: #252525;
  --bg2: #2d2d2d;
  --border: rgba(255,255,255,.08);
  --border2: rgba(255,255,255,.14);
  --text1: #e8e6e0;
  --text2: #a8a69e;
  --text3: #6e6c66;
  --purple-bg: #26215C;
  --teal-bg: #04342C;
  --amber-bg: #412402;
  --red-bg: #501313;
  --green-bg: #173404;
  --blue-bg: #042C53;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg1); color: var(--text1); line-height: 1.6; }
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg0); border-right: .5px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 100;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; border-bottom: .5px solid var(--border);
}
.brand-text { font-size: 14px; font-weight: 500; }

.sidebar-nav { padding: 8px 0; flex: 1; }
.nav-section {
  padding: 12px 16px 4px; font-size: 10px; font-weight: 500;
  color: var(--text3); text-transform: uppercase; letter-spacing: .7px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; font-size: 13px; color: var(--text2);
  cursor: pointer; transition: all var(--transition);
  position: relative; border-radius: 0;
}
.nav-item:hover { background: var(--bg1); color: var(--text1); text-decoration: none; }
.nav-item.active { background: var(--bg1); color: var(--text1); font-weight: 500; }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 5px; bottom: 5px;
  width: 2.5px; background: var(--purple); border-radius: 0 2px 2px 0;
}
.nav-item svg { flex-shrink: 0; opacity: .65; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }
.nav-badge {
  margin-left: auto; background: var(--red-bg); color: var(--red);
  font-size: 10px; font-weight: 500; padding: 1px 6px; border-radius: 10px;
}

.sidebar-footer {
  padding: 12px 16px; border-top: .5px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.sf-plan { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; }
.sf-user { display: flex; align-items: center; gap: 8px; color: inherit; }
.sf-user:hover { text-decoration: none; }
.sf-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--purple-bg); color: var(--purple-dk);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500; flex-shrink: 0;
}
.sf-name { font-size: 13px; font-weight: 500; }
.sf-role { font-size: 11px; color: var(--text3); }
.sf-logout { color: var(--text3); display: flex; align-items: center; }
.sf-logout:hover { color: var(--red); }

/* ── Main wrap ── */
.main-wrap {
  margin-left: var(--sidebar-w); flex: 1;
  display: flex; flex-direction: column; min-height: 100vh; min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h); background: var(--bg0);
  border-bottom: .5px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 24px; position: sticky; top: 0; z-index: 90;
}
.topbar-hamburger { display: none; background: none; border: none; color: var(--text2); cursor: pointer; padding: 4px; }
.topbar-title { font-size: 14px; font-weight: 500; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius);
  border: .5px solid var(--border); background: var(--bg1);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text2); transition: all var(--transition);
}
.topbar-icon-btn:hover { background: var(--bg2); color: var(--text1); }
.notif-wrap { position: relative; }
.notif-badge {
  position: absolute; top: 5px; right: 5px; width: 7px; height: 7px;
  background: var(--red); border-radius: 50%; border: 1.5px solid var(--bg0);
}
.notif-dropdown {
  position: absolute; right: 0; top: 40px; width: 300px;
  background: var(--bg0); border: .5px solid var(--border2);
  border-radius: var(--radius-lg); box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 200; display: none; overflow: hidden;
}
.notif-dropdown.open { display: block; }

.plan-chip {
  font-size: 11px; font-weight: 500; padding: 3px 10px;
  border-radius: 10px; background: var(--green-bg); color: var(--green);
}

/* ── Alert banner ── */
.alert-banner {
  padding: 10px 24px; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.alert-danger { background: var(--red-bg); color: var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); }
.alert-warning { background: var(--amber-bg); color: var(--amber); }
.alert-info { background: var(--blue-bg); color: var(--blue); }

/* ── Main content ── */
.main-content { padding: 24px; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--bg0); border: .5px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 13px; font-weight: 500; }

/* ── Ring stat card ── */
.stat-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.stat-card {
  background: var(--bg0); border: .5px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.ring-wrap { position: relative; width: 88px; height: 88px; }
.ring-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--border2); stroke-width: 6; }
.ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-val { font-size: 18px; font-weight: 500; line-height: 1; }
.ring-pct { font-size: 10px; color: var(--text3); margin-top: 2px; }
.stat-label { font-size: 12px; color: var(--text2); text-align: center; }
.stat-sub { font-size: 11px; color: var(--text3); }

/* ── Quick stat row ── */
.qs-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
.qs { background: var(--bg1); border-radius: var(--radius); padding: 12px 14px; }
.qs-val { font-size: 22px; font-weight: 500; }
.qs-lbl { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 500; color: var(--text3); border-bottom: .5px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: .5px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg1); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 10px; }
.badge-purple { background: var(--purple-bg); color: var(--purple-dk); }
.badge-teal   { background: var(--teal-bg); color: var(--teal); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-blue   { background: var(--blue-bg); color: var(--blue); }
.badge-gray   { background: var(--bg2); color: var(--text2); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-red { background: var(--red); }
.dot-amber { background: var(--amber); }
.dot-green { background: var(--green); }
.dot-gray { background: var(--text3); }

/* ── Priority dots ── */
.priority-high   { color: var(--red); }
.priority-medium { color: var(--amber); }
.priority-low    { color: var(--green); }
.priority-urgent { color: var(--red); font-weight: 500; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: .5px solid var(--border2); background: var(--bg0);
  font-size: 13px; font-weight: 500; cursor: pointer;
  color: var(--text1); transition: all var(--transition); white-space: nowrap;
}
.btn:hover { background: var(--bg1); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--purple); border-color: var(--purple-dk); color: #fff; }
.btn-primary:hover { background: var(--purple-dk); color: #fff; }
.btn-danger { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.btn-success { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius); border: .5px solid var(--border); background: var(--bg1); color: var(--text2); cursor: pointer; display: inline-flex; align-items: center; }
.btn-icon:hover { background: var(--bg2); color: var(--text1); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="search"], input[type="date"],
input[type="datetime-local"], select, textarea {
  width: 100%; padding: 8px 12px; border-radius: var(--radius);
  border: .5px solid var(--border2); background: var(--bg0); color: var(--text1);
  font-size: 13px; font-family: inherit; transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--purple); box-shadow: 0 0 0 2px rgba(127,119,221,.15);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }
.input-group { display: flex; }
.input-group input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .btn { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }

/* Toggle switch */
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; background: var(--border2);
  border-radius: 10px; cursor: pointer; transition: .2s;
}
.toggle input:checked + .toggle-track { background: var(--purple); }
.toggle-thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: .2s; pointer-events: none;
}
.toggle input:checked ~ .toggle-thumb { transform: translateX(16px); }

/* ── Progress bar ── */
.prog-track { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.prog-fill { height: 100%; border-radius: 2px; transition: width .4s ease; }

/* ── Page header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 16px; font-weight: 500; }
.page-actions { display: flex; gap: 8px; }

/* ── Two-col grid ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Inbox layout ── */
.inbox-layout { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - var(--topbar-h) - 48px); overflow: hidden; }
.inbox-list { border-right: .5px solid var(--border); overflow-y: auto; }
.inbox-conv { flex: 1; display: flex; flex-direction: column; }
.inbox-item { padding: 12px 16px; border-bottom: .5px solid var(--border); cursor: pointer; transition: background var(--transition); }
.inbox-item:hover, .inbox-item.active { background: var(--purple-bg); }
.inbox-item-name { font-size: 13px; font-weight: 500; }
.inbox-item-preview { font-size: 12px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item-time { font-size: 11px; color: var(--text3); }

/* ── Messages ── */
.msg-area { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; }
.msg-out { align-self: flex-end; }
.msg-in { align-self: flex-start; }
.msg-bubble { padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.msg-out .msg-bubble { background: var(--purple); color: #fff; border-radius: 12px 12px 2px 12px; }
.msg-in .msg-bubble { background: var(--bg2); border-radius: 12px 12px 12px 2px; }
.msg-meta { font-size: 11px; color: var(--text3); margin-top: 3px; }
.msg-in .msg-meta { text-align: left; }
.msg-out .msg-meta { text-align: right; }
.msg-compose { padding: 12px 16px; border-top: .5px solid var(--border); display: flex; gap: 8px; }
.msg-compose textarea { flex: 1; min-height: 40px; max-height: 120px; resize: none; }

/* ── Live chat bubble ── */
#lc-bubble {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--purple); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 4px 12px rgba(127,119,221,.4);
  transition: transform .2s;
}
#lc-bubble:hover { transform: scale(1.08); }
.lc-dot {
  position: absolute; top: 8px; right: 8px; width: 8px; height: 8px;
  background: var(--green); border-radius: 50%; border: 2px solid var(--purple);
}
.lc-panel {
  position: fixed; bottom: 84px; right: 24px; z-index: 998;
  width: 320px; height: 440px;
  background: var(--bg0); border: .5px solid var(--border2);
  border-radius: var(--radius-lg); box-shadow: 0 8px 24px rgba(0,0,0,.14);
  display: flex; flex-direction: column; overflow: hidden;
}

/* ── Flow builder canvas ── */
.flow-canvas { background: var(--bg1); border: .5px solid var(--border); border-radius: var(--radius-lg); min-height: 480px; position: relative; overflow: hidden; }
.flow-node {
  position: absolute; background: var(--bg0); border: .5px solid var(--border2);
  border-radius: var(--radius); padding: 10px 14px; min-width: 140px;
  cursor: grab; user-select: none; box-shadow: var(--shadow);
}
.flow-node:active { cursor: grabbing; }
.flow-node-trigger { border-left: 3px solid var(--green); }
.flow-node-action  { border-left: 3px solid var(--purple); }
.flow-node-condition { border-left: 3px solid var(--amber); }
.flow-node-title { font-size: 12px; font-weight: 500; }
.flow-node-type  { font-size: 10px; color: var(--text3); margin-bottom: 4px; }
.flow-toolbar { display: flex; gap: 8px; padding: 12px; border-bottom: .5px solid var(--border); flex-wrap: wrap; }

/* ── Scraper ── */
.scraper-result { background: var(--bg1); border-radius: var(--radius); padding: 14px; margin-top: 12px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 16px; }
.pagination a, .pagination span {
  padding: 5px 10px; border-radius: var(--radius); border: .5px solid var(--border);
  font-size: 12px; color: var(--text2); background: var(--bg0);
}
.pagination a:hover { background: var(--bg1); text-decoration: none; }
.pagination .active { background: var(--purple); color: #fff; border-color: var(--purple); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  display: none;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg0); border-radius: var(--radius-lg);
  padding: 24px; width: 480px; max-width: 95vw; max-height: 90vh;
  overflow-y: auto; position: relative;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 15px; font-weight: 500; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text3); padding: 2px; }
.modal-close:hover { color: var(--text1); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Admin layout ── */
.admin-stat-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; margin-bottom: 20px; }
.admin-stat { background: var(--bg0); border: .5px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; }
.admin-stat-val { font-size: 28px; font-weight: 500; }
.admin-stat-lbl { font-size: 12px; color: var(--text3); margin-top: 2px; }
.admin-stat-delta { font-size: 11px; color: var(--green); }

/* ── Auth pages ── */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg1); }
.auth-box { background: var(--bg0); border: .5px solid var(--border); border-radius: var(--radius-lg); padding: 36px; width: 380px; max-width: 95vw; }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-title { font-size: 20px; font-weight: 500; margin-bottom: 4px; }
.auth-sub { font-size: 13px; color: var(--text3); margin-bottom: 24px; }
.auth-footer { margin-top: 20px; text-align: center; font-size: 13px; color: var(--text3); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .topbar-hamburger { display: flex; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .inbox-layout { grid-template-columns: 1fr; }
  .admin-stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .admin-stat-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}
