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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #0f172a;
    color: #f1f5f9;
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
}

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

/* ══════════════════════════════
   SIDEBAR
══════════════════════════════ */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: #1e293b;
    border-left: 1px solid #2d3f55;
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    gap: 14px;
    overflow-y: auto;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid #2d3f55;
}
.brand-icon { font-size: 30px; line-height: 1; }
.brand-name { font-size: 16px; font-weight: 700; color: #f1f5f9; }
.brand-sub  { font-size: 11px; color: #64748b; margin-top: 1px; }

/* Status badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.3s, color 0.3s;
}
.status-badge.connecting  { background: #1a2f24; color: #86efac; }
.status-badge.connected   { background: #14532d; color: #4ade80; }
.status-badge.disconnected{ background: #450a0a; color: #fca5a5; }

.status-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.status-badge.connecting .status-dot {
    animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.3; transform: scale(0.7); }
}

/* Side card */
.side-card {
    background: #0f172a;
    border: 1px solid #2d3f55;
    border-radius: 12px;
    padding: 16px;
}
.side-card-title {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 14px;
    text-align: center;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* QR */
.qr-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 190px;
}
.qr-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #475569;
    font-size: 12px;
}
.spinner {
    width: 30px; height: 30px;
    border: 3px solid #334155;
    border-top-color: #25D366;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-img {
    width: 190px; height: 190px;
    border-radius: 10px;
    display: block;
    margin: 0 auto;
    border: 3px solid #ffffff10;
}
.qr-hint {
    margin-top: 12px;
    font-size: 11px;
    color: #475569;
    text-align: center;
    line-height: 1.6;
}

/* Connected */
.conn-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.conn-avatar { font-size: 26px; }
.conn-title  { font-size: 15px; font-weight: 600; color: #4ade80; }
.conn-phone  { font-size: 12px; color: #94a3b8; direction: ltr; }

/* Sidebar footer */
.sidebar-footer { margin-top: auto; }

/* ══════════════════════════════
   MAIN
══════════════════════════════ */
.main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px 28px;
    min-width: 0;
}

/* Topbar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.page-title { font-size: 24px; font-weight: 700; }
.page-sub   { font-size: 13px; color: #64748b; margin-top: 3px; }

/* ── Stats ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}
.stat-card {
    background: #1e293b;
    border: 1px solid #2d3f55;
    border-radius: 12px;
    padding: 18px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.15s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card.green  { border-right: 3px solid #25D366; }
.stat-card.blue   { border-right: 3px solid #3b82f6; }
.stat-card.purple { border-right: 3px solid #a78bfa; }
.stat-card.red    { border-right: 3px solid #f87171; }

.stat-icon { font-size: 26px; line-height: 1; }
.stat-num  { font-size: 30px; font-weight: 700; line-height: 1; }
.stat-lbl  { font-size: 12px; color: #64748b; margin-top: 4px; }

/* ── Content grid ── */
.content-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 18px;
    flex: 1;
    min-height: 0;
}

/* ── Card ── */
.card {
    background: #1e293b;
    border: 1px solid #2d3f55;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #2d3f55;
    flex-shrink: 0;
}
.card-title { font-size: 14px; font-weight: 600; }

/* Pill badge */
.pill {
    background: #25D366;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 20px;
    min-width: 22px;
    text-align: center;
}

/* ── Feed ── */
.feed {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.feed-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #0f172a;
    border: 1px solid #2d3f55;
    border-radius: 10px;
    padding: 10px 12px;
    animation: fadeSlide 0.3s ease-out;
}
@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.feed-avatar {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, #25D366, #128C7E);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}
.feed-avatar.left {
    background: linear-gradient(135deg, #dc2626, #991b1b);
}
.feed-item.left-item {
    border-color: #450a0a;
    background: #1c0a0a;
}
.feed-item.left-item .feed-phone { color: #fca5a5; }
.feed-item.left-item .feed-coupon { color: #f87171; }
.feed-info { flex: 1; min-width: 0; }
.feed-phone  { font-size: 13px; font-weight: 600; direction: ltr; text-align: right; }
.feed-coupon { font-size: 12px; color: #25D366; font-family: monospace; font-weight: 600; margin-top: 2px; }
.feed-time   { font-size: 11px; color: #475569; margin-top: 2px; }
.feed-status { font-size: 18px; flex-shrink: 0; }

/* ── Table ── */
.search {
    background: #0f172a;
    border: 1px solid #2d3f55;
    border-radius: 8px;
    padding: 6px 12px;
    color: #f1f5f9;
    font-size: 13px;
    width: 220px;
    outline: none;
    transition: border-color 0.2s;
}
.search:focus { border-color: #25D366; }

.tbl-wrap {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.tbl thead {
    position: sticky;
    top: 0;
    background: #1e293b;
    z-index: 1;
}
.tbl th {
    padding: 11px 16px;
    text-align: right;
    color: #64748b;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid #2d3f55;
}
.tbl td {
    padding: 10px 16px;
    border-bottom: 1px solid #1a2535;
    color: #e2e8f0;
}
.tbl tbody tr:hover { background: #0f172a; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tr.new-row td { animation: rowPop 0.4s ease-out; }
@keyframes rowPop {
    from { background: #14532d55; }
    to   { background: transparent; }
}

/* Coupon chip */
.chip {
    background: #0f172a;
    border: 1px solid #2d3f55;
    color: #4ade80;
    font-family: monospace;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 5px;
    letter-spacing: 0.05em;
}

/* ── Buttons ── */
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
}
.btn-ghost {
    background: #1e293b;
    color: #94a3b8;
    border: 1px solid #2d3f55;
}
.btn-ghost:hover { background: #2d3f55; color: #f1f5f9; }

/* Empty state */
.empty {
    text-align: center;
    color: #334155;
    font-size: 13px;
    padding: 40px 16px;
}

/* ── Warning banner ── */
.warn-banner {
    background: #451a03;
    border: 1px solid #92400e;
    color: #fcd34d;
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
}

/* ── Active group badge (header) ── */
.active-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #14532d;
    border: 1px solid #166534;
    color: #86efac;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    transition: transform 0.2s;
}
.active-badge.pop { transform: scale(1.08); }
.active-dot {
    width: 8px; height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

/* ── Group section in sidebar ── */
.group-section {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.group-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.group-section-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.icon-btn {
    background: #1e293b;
    border: 1px solid #2d3f55;
    color: #94a3b8;
    border-radius: 6px;
    width: 26px; height: 26px;
    cursor: pointer;
    font-size: 15px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}
.icon-btn:hover { background: #2d3f55; color: #f1f5f9; transform: rotate(20deg); }

.group-search {
    background: #0f172a;
    border: 1px solid #2d3f55;
    border-radius: 8px;
    padding: 7px 10px;
    color: #f1f5f9;
    font-size: 12px;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}
.group-search:focus { border-color: #25D366; }

.groups-list {
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.groups-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #475569;
    font-size: 12px;
    padding: 12px 4px;
    justify-content: center;
}

.group-item {
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.group-item:hover { background: #1e293b; border-color: #2d3f55; }
.group-item.selected { background: #14532d; border-color: #166534; }

.group-item-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
}
.group-icon { font-size: 18px; flex-shrink: 0; }
.group-info { flex: 1; min-width: 0; }
.group-name {
    font-size: 12px;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.group-meta { font-size: 11px; color: #64748b; margin-top: 1px; }
.group-check {
    color: #4ade80;
    font-size: 14px;
    font-weight: 700;
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.group-item.selected .group-check { opacity: 1; }

/* Small spinner */
.spinner-sm {
    width: 14px; height: 14px;
    border: 2px solid #334155;
    border-top-color: #25D366;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    display: inline-block;
}

/* ── Debug bar ── */
.debug-bar {
    background: #0a0f1a;
    border: 1px solid #1e2d3d;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}
.debug-bar-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 14px;
    border-bottom: 1px solid #1e2d3d;
    font-size: 11px;
    color: #475569;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.debug-clear {
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.15s;
}
.debug-clear:hover { background: #1e293b; color: #94a3b8; }
.debug-log {
    height: 80px;
    overflow-y: auto;
    padding: 6px 14px;
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
}
.debug-line {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 11px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: ltr;
    text-align: left;
}
.debug-line.join   { color: #4ade80; }
.debug-line.error  { color: #f87171; }
.debug-line.send   { color: #60a5fa; }
.debug-waiting { font-size: 11px; color: #334155; font-style: italic; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2d3f55; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }
