/* TGPulse — dark dashboard UI.
   Layout skeleton: full-width top bar (brand · search · period · bell · account) + 264px sidebar + content.
   Channel detail = 3 zones: KPIs → charts → tables/drill-down. State matrix: skeletons, loading buttons, breadcrumbs. */
:root { --accent: #2ea6ff; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: #0b0f14; color: #e8edf3; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 15px; line-height: 1.5; }

/* ---------- layout skeleton: top bar (full width) + sidebar + content ---------- */
.shell { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }

/* ---------- top bar (58px): brand · search · period picker · bell · account menu ---------- */
.topbar { grid-column: 1 / -1; position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 58px; padding: 8px 20px; background: #0e141c; border-bottom: 1px solid #1d2735; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand img { border-radius: 6px; background: #0b0f14; }

/* global search (Ctrl+K) */
.search-wrap { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; max-width: 380px; min-width: 150px; background: #131b26; border: 1px solid #243040; border-radius: 9px; padding: 7px 12px; color: #8fa0b3; }
.search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46,166,255,.15); }
.search-wrap input { flex: 1; background: none; border: 0; outline: 0; color: #e8edf3; font-size: 14px; min-width: 0; padding: 0; width: auto; }

/* period picker — one predictable filter place, shown only on data views */
.topbar-period { display: inline-flex; gap: 2px; background: #131b26; border: 1px solid #243040; border-radius: 9px; padding: 3px; }
.topbar-period button { border: 0; background: transparent; color: #8fa0b3; font-size: 13px; padding: 5px 11px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.topbar-period button.active { background: var(--accent); color: #fff; font-weight: 600; }
.topbar-dates { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-dates input[type=date] { background: #131b26; border: 1px solid #243040; color: #e8edf3; border-radius: 7px; padding: 5px 8px; font-size: 13px; width: auto; }
.topbar-dates .ghost { padding: 5px 10px; font-size: 13px; }

/* right cluster: bell + account menu */
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn { position: relative; width: 36px; height: 36px; border-radius: 9px; border: 1px solid #243040; background: #131b26; color: #8fa0b3; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { color: #e8edf3; border-color: var(--accent); }
.badge { position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; background: #ff5d6c; color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; }

/* account menu */
.acct-wrap { position: relative; }
.acct-btn { display: flex; align-items: center; gap: 8px; background: #131b26; border: 1px solid #243040; color: #e8edf3; font-size: 13.5px; padding: 7px 12px; border-radius: 9px; cursor: pointer; max-width: 220px; }
.acct-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-btn:hover, .acct-wrap.open .acct-btn { border-color: var(--accent); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: #141c27; border: 1px solid #243040; border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.5); padding: 6px; z-index: 40; }
.menu-head { font-size: 13px; color: #8fa0b3; padding: 7px 10px 9px; border-bottom: 1px solid #243040; margin-bottom: 5px; overflow-wrap: anywhere; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: #e8edf3; font-size: 14px; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.menu-item:hover { background: #1b2534; }
.menu-item.danger { color: #ff8a93; }

/* notifications panel (drops under the bell) */
.notif-panel { position: absolute; right: 20px; top: 62px; width: 340px; max-width: calc(100vw - 40px); background: #141c27; border: 1px solid #243040; border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.55); z-index: 45; padding: 8px; }
.notif-panel h4 { margin: 4px 8px 8px; font-size: 12.5px; color: #8fa0b3; text-transform: uppercase; letter-spacing: .6px; }
.notif-item { display: flex; gap: 9px; padding: 9px 10px; border-radius: 8px; font-size: 13.5px; align-items: baseline; }
.notif-item:hover { background: #1b2534; }
.notif-time { color: #6b7a8d; font-size: 12px; white-space: nowrap; margin-left: auto; padding-top: 2px; }
.notif-empty { padding: 14px 10px; color: #6b7a8d; font-size: 13.5px; text-align: center; }

/* ---------- sidebar (primary nav lives here, not in the top bar) ---------- */
.sidebar { position: sticky; top: 58px; height: calc(100vh - 58px); overflow-y: auto; background: #0e141c; border-right: 1px solid #1d2735; padding: 16px 14px 24px; }
.side-sec { margin-bottom: 22px; }
.side-sec h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: #6b7a8d; margin: 0 0 9px 4px; }
.side-add { width: 100%; margin-top: 8px; padding: 9px 12px; font-size: 13.5px; }
.side-accounts .account-card { margin-bottom: 7px; }
.side-nav a, .side-link { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: #c3cedb; text-decoration: none; font-size: 14px; margin-bottom: 2px; }
.side-link:hover, .side-nav a:hover { background: #16202d; color: #fff; }
.side-link.active { background: rgba(46,166,255,.14); color: #7cc8ff; font-weight: 600; }
.folder-link .fcount { margin-left: auto; font-size: 12px; color: #6b7a8d; background: #131b26; border-radius: 9px; padding: 1px 8px; }

/* ---------- content area ---------- */
main { padding: 24px 28px 80px; width: 100%; max-width: 1280px; margin: 0 auto; min-width: 0; }
.card { background: #131a24; border: 1px solid #1f2937; border-radius: 14px; padding: 20px 22px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.35); }
.card.center { max-width: 640px; margin-left: auto; margin-right: auto; text-align: center; padding-top: 0; overflow: hidden; }

/* breadcrumbs (state matrix: always know where you are) */
.crumbs { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.crumb-path { font-size: 13.5px; }
.detail .card:first-of-type h2, .detail > .card h2 { margin-top: 0; }

/* section head */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2, .section-head h3 { margin: 0; font-size: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* buttons */
button { font: inherit; cursor: pointer; border-radius: 9px; padding: 8px 14px; border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s; position: relative; }
.primary { background: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { background: #4fb3ff; }
.ghost { background: transparent; color: #9fb0c3; border-color: #2a3547; }
.ghost:hover { color: #e8edf3; border-color: var(--accent); }
.ghost.danger { color: #ff8a93; }
.link { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }

/* loading button state (spinner replaces the label) */
button.loading, button:disabled { pointer-events: none; opacity: .75; color: transparent !important; }
button.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); border-top-color: currentColor; animation: spin .7s linear infinite; }
button.ghost.loading::after { border-color: #2a3547; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* skeleton loaders — same shape as the real content, so nothing jumps */
.skel { position: relative; overflow: hidden; background: #18212e; border-radius: 9px; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.07), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.skel-line { height: 13px; border-radius: 6px; background: #18212e; position: relative; overflow: hidden; display: block; }
.skel-line::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.07), transparent); animation: shimmer 1.4s infinite; }
.kpi-skel { display: flex !important; flex-direction: column; justify-content: center; gap: 8px; padding: 10px 14px; }
.chart-skel { height: 158px; border-radius: 12px; }
.msg-skel { display: grid; gap: 0; }

/* ---------- auth view (hero art on top, centered card) ---------- */
.auth-hero { width: 100%; display: block; border-radius: 14px 14px 0 0; margin-bottom: 16px; }
.tabs { display: inline-flex; gap: 4px; background: #0e141c; border-radius: 10px; padding: 4px; margin: 6px auto 18px; position: relative; z-index: 1; }
.tab { border: 0; background: transparent; color: #9fb0c3; font-weight: 600; padding: 7px 22px; border-radius: 8px; }
.tab.active { background: var(--accent); color: #fff; }
.stack { display: grid; gap: 14px; text-align: left; }
label { display: grid; gap: 6px; font-size: 13.5px; color: #9fb0c3; }
input[type=email], input[type=password], input[type=tel], input[type=search], input:not([type]), select, textarea { background: #0e141c; border: 1px solid #2a3547; color: #e8edf3; border-radius: 9px; padding: 9px 12px; font-size: 15px; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46,166,255,.18); }
.error { color: #ff8a93; font-size: 13.5px; min-height: 1em; margin: 0; text-align: left; }
.note { color: #8fa0b3; font-size: 13.5px; margin: 4px 0 0; }

/* ---------- wizard ---------- */
.steps .wiz { display: grid; gap: 12px; max-width: 460px; margin: 0 auto; text-align: left; }
.qr-box { background: #fff; padding: 14px; border-radius: 12px; width: fit-content; margin: 8px auto; min-height: 190px; display: flex; align-items: center; justify-content: center; color: #6b7a8d; font-size: 13.5px; }
.qr-box img, .qr-box canvas { max-width: 220px; border-radius: 6px; }

/* ---------- accounts (sidebar cards) ---------- */
.account-card { display: grid; gap: 5px; background: #0e141c; border: 1px solid #1f2937; border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.account-card.active { border-color: var(--accent); background: rgba(46,166,255,.08); }
.acc-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-sub { color: #8fa0b3; font-size: 12.5px; }
.acc-meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: #8fa0b3; }
.acc-status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; display: inline-block; flex-shrink: 0; }
.acc-status.off .dot { background: #6b7a8d; }
.acc-actions { display: flex; gap: 6px; margin-top: 4px; }
.acc-actions button { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }

/* empty state (fresh illustration + CTA) */
.empty-card, .empty-state { text-align: center; display: grid; gap: 6px; justify-items: center; padding: 34px 22px; }
.empty-card img, .empty-state img { max-width: 100%; height: auto; margin-bottom: 8px; }
.empty-card h2 { margin: 0; font-size: 19px; }
.empty-card p, .empty-state p { color: #8fa0b3; margin: 0 0 10px; max-width: 460px; }

/* ---------- channel list (cards for scanning) ---------- */
.ch-list { display: grid; gap: 10px; }
.ch-block { background: #0e141c; border: 1px solid #1f2937; border-radius: 12px; padding: 13px 16px; cursor: pointer; transition: border-color .15s, transform .18s ease, background .15s; }
.ch-block:hover { border-color: var(--accent); }
.ch-main b { font-size: 15.5px; }
.ch-meta { color: #8fa0b3; font-size: 12.5px; margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kind { background: rgba(46,166,255,.14); color: #7cc8ff; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.ch-open { background: none; border: 0; padding: 2px 4px; cursor: pointer; margin-left: auto; align-self: center; }
.ch-block .ch-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ch-open svg text { fill: #9fb0c3; font-weight: 700; letter-spacing: .5px; filter: url(#txtInset); transition: fill .15s; }
.ch-block:hover .ch-open svg text, .folder-card:hover .ch-open svg text { fill: #7cc8ff; }

/* folder cards in the list (drop targets that "walk away" from the cursor) */
.folder-card { border-style: dashed; background: transparent; }
.folder-card.avoid-left { transform: translateX(10px); }
.folder-card.avoid-right { transform: translateX(-10px); }
.ch-folder-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: 13.5px; color: #8fa0b3; }

/* drag & drop states */
.dragging { opacity: .45; }
.drop-hint { border-color: var(--accent) !important; background: rgba(46,166,255,.07) !important; }
.drag-ghost { position: fixed; z-index: 99; pointer-events: none; opacity: .95; box-shadow: 0 18px 40px rgba(0,0,0,.6); transform: rotate(2deg) scale(1.03); }
.ch-empty { padding: 14px 4px; text-align: center; }

/* ---------- KPI bento (zone 1: is anything wrong?) ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 6px; }
.kpi { background: #0e141c; border: 1px solid #1f2937; border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.kpi:first-child { grid-column: span 2; grid-row: span 2; justify-content: center; }
.kpi .k { color: #8fa0b3; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-weight: 700; font-size: 21px; line-height: 1.15; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kpi:first-child .v { font-size: 30px; }

/* ---------- charts (zone 2: how wrong and since when?) ---------- */
.chart-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 4px; }
.chart-box h4 { margin: 0 0 8px; font-size: 13.5px; color: #9fb0c3; font-weight: 600; }
.chart { background: #0e141c; border: 1px solid #1f2937; border-radius: 12px; padding: 10px 8px 4px; min-height: 170px; display: flex; align-items: center; }
.chart svg { display: block; width: 100%; height: auto; }
.chart-empty { text-align: center; margin: 8px 12px; }
.chart img { max-width: 160px; height: auto; margin: 0 auto 6px; display: block; }
.chart-tip { position: fixed; z-index: 90; background: #1b2534; border: 1px solid #2a3547; padding: 8px 10px; border-radius: 8px; font-size: 12.5px; pointer-events: none; display: none; box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 260px; }

/* ---------- tables (zone 3: what do I do about it?) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid #1f2937; border-radius: 12px; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.table th { text-align: left; color: #8fa0b3; font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; border-bottom: 1px solid #1f2937; background: #0e141c; }
.table td { padding: 10px 14px; border-bottom: 1px solid #18212e; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(46,166,255,.05); }
#d-top td:nth-child(n+3), #f-stats td:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* messages */
.msgs { display: grid; gap: 8px; }
.msg { background: #0e141c; border: 1px solid #1f2937; border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.msg .meta { color: #8fa0b3; font-size: 12.5px; margin-bottom: 4px; }

/* top posts sort select */
.top-select { width: auto; padding: 6px 10px; font-size: 13.5px; background: #0e141c; border-color: #2a3547; color: #e8edf3; }

/* export format toggle (XLSX / CSV) */
.fmt-toggle { display: inline-flex; border: 1px solid #2a3547; border-radius: 9px; overflow: hidden; padding: 0 !important; gap: 0 !important; background: transparent !important; }
.fmt-toggle button { border: 0; background: transparent; color: #8fa0b3; font-size: 12.5px; padding: 6px 12px; border-radius: 0; }
.fmt-toggle button.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- misc ---------- */
.hidden { display: none !important; }
.muted { color: #8fa0b3; }
.chip { background: rgba(46,166,255,.15); color: #7cc8ff; border-radius: 999px; padding: 3px 11px; font-size: 12.5px; font-weight: 600; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1b2534; border: 1px solid var(--accent); color: #e8edf3; padding: 10px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 99; max-width: min(90vw, 560px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* auth mode: no sidebar, no search/bell/account — just brand + centered card */
body.auth .shell { grid-template-columns: 1fr; }
body.auth .sidebar, body.auth .search-wrap, body.auth .topbar-right { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi:first-child { grid-column: span 2; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 58px; bottom: 0; width: 284px; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; box-shadow: 8px 0 30px rgba(0,0,0,.45); }
  .sidebar.open { transform: none; }
  .sidebar-toggle { display: inline-flex !important; }
  main { padding: 18px 16px 70px; }
}
@media (min-width: 901px) { .sidebar-toggle { display: none; } }
@media (max-width: 640px) {
  .chart-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
