:root {
    --bg: #eef3f8;
    --card: #ffffff;
    --ink: #243246;
    --muted: #8b9aaf;
    --line: #e7eef6;
    --sidebar: #0c2340;
    --green: #25d366;
    --green-deep: #128c7e;
    --blue: #1877f2;
    --red: #ef5b5b;
    --amber: #f5a524;
    --yellow: #e6b325;
    --shadow: 0 10px 28px rgba(16, 42, 74, 0.05);
    --radius: 22px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

button, input, select, textarea { font-family: inherit; }

a { color: inherit; text-decoration: none; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex: none;
    background: linear-gradient(180deg, #0d2748 0%, #0a1c33 100%);
    color: #fff;
    padding: 26px 16px 18px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand-title { font-size: 20px; font-weight: 800; line-height: 1.3; }
.brand-sub { margin-top: 2px; color: rgba(255, 255, 255, 0.62); font-size: 13px; font-weight: 600; }

.mode-pill {
    display: inline-flex;
    margin-top: 12px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(245, 165, 36, 0.16);
    color: #ffd27a;
}

.mode-pill.live { background: rgba(37, 211, 102, 0.16); color: #8ef0b2; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 26px; overflow: auto; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 14px;
    color: rgba(255, 255, 255, 0.78);
    font-weight: 700;
    font-size: 14.5px;
}

.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.is-active { background: #173a63; color: #fff; }

.side-foot { margin-top: auto; padding-top: 18px; }
.side-user-name { font-weight: 800; font-size: 14px; }
.side-user-role { color: rgba(255, 255, 255, 0.55); font-size: 12px; font-weight: 600; margin-top: 2px; }

.logout {
    width: 100%;
    margin-top: 14px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: transparent;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.logout:hover { background: rgba(255, 255, 255, 0.06); }

.main { flex: 1; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 22px 8px;
}

.content { padding: 8px 22px 32px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    font-weight: 800;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.btn-green { background: var(--green); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-ghost { background: #f4f7fb; color: var(--ink); }
.btn-line { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.search-form { flex: 1; }

.search {
    width: 100%;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 0 18px;
    font-size: 14px;
    color: var(--ink);
    outline: none;
}

.search::placeholder { color: #a0aec0; }
.search:focus { box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.15); }

.stats, .status-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.status-grid { margin-top: 16px; }

.stat-card, .status-card, .card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(231, 238, 246, 0.9);
}

.stat-card { text-align: center; padding: 28px 12px 22px; }
.stat-value { font-size: 34px; font-weight: 800; line-height: 1; letter-spacing: -0.4px; }
.stat-label { margin-top: 10px; color: var(--muted); font-size: 14px; font-weight: 700; }
.is-green { color: #22c55e; }
.is-amber { color: var(--amber); }

.status-card {
    min-height: 96px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.status-title { font-weight: 800; font-size: 15px; }
.status-hint { margin-top: 4px; color: var(--muted); font-size: 12.5px; font-weight: 700; }
.status-value { font-size: 34px; font-weight: 800; line-height: 1; }

.split, .thirds, .grid-2 { display: grid; gap: 16px; margin-top: 16px; }
.split { grid-template-columns: 1.35fr 0.9fr; }
.thirds { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 1.15fr 0.85fr; }

.card { padding: 18px 18px 10px; }
.card h2 { margin: 0 0 6px; font-size: 16px; font-weight: 800; }
.card.pad { padding-bottom: 18px; }

.chart-card { display: flex; flex-direction: column; }
.chart-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }

.donut {
    width: 220px;
    height: 220px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 18px auto 8px;
}

.donut span {
    width: 132px;
    height: 132px;
    border-radius: 50%;
    background: #fff;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    color: #7d8b9e;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 0 12px;
}

.legend b { font-weight: 800; }

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-inline-end: 6px;
}

.activity-row, .mini-row, .list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 2px;
}

.activity-row + .activity-row,
.mini-row + .mini-row,
.list-row + .list-row { border-top: 1px solid #f0f4f8; }

.who, .mini-copy { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who .name, .mini-name, .list-title { font-weight: 800; font-size: 14px; }
.when, .mini-sub, .muted { color: var(--muted); font-size: 12.5px; font-weight: 700; }
.when { white-space: nowrap; }
.mini-copy { display: block; }
.mini-phone { font-weight: 800; font-size: 14px; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

.tag, .pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.tag-green, .pill-green { background: #e5f8ec; color: #178a49; }
.tag-blue, .pill-blue { background: #e7f1ff; color: #1877f2; }
.tag-purple, .pill-purple { background: #f3eefe; color: #7c4dcc; }
.tag-amber, .pill-amber { background: #fff4df; color: #b4790d; }
.pill-red { background: #fdecec; color: #d64545; }

.empty { color: var(--muted); text-align: center; padding: 28px 8px 22px; font-weight: 700; }

.flash { border-radius: 16px; padding: 12px 16px; font-weight: 800; margin-bottom: 14px; }
.flash-ok { background: #e8f8ee; color: #0f7a45; }
.flash-err { background: #fdecec; color: #c43838; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-weight: 700; font-size: 13px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.chip {
    height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    box-shadow: var(--shadow);
}

.chip.is-on { background: var(--blue); color: #fff; }

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 800; font-size: 13px; margin-bottom: 6px; }

.input, .select, .textarea {
    width: 100%;
    border: 1px solid #e1e9f2;
    background: #f8fafc;
    border-radius: 14px;
    padding: 12px 14px;
    color: var(--ink);
    font-size: 14px;
    outline: none;
}

.textarea { min-height: 110px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: #b9d4fb; background: #fff; }

.help { color: var(--muted); font-size: 12.5px; font-weight: 700; margin-top: 6px; }
.field-error { color: #d64545; font-size: 12.5px; font-weight: 800; margin-top: 6px; }

.notice { border-radius: 16px; padding: 12px 14px; font-weight: 700; font-size: 14px; line-height: 1.7; margin-bottom: 12px; }
.notice-ok { background: #e8f8ee; color: #0f7a45; }
.notice-warn { background: #fff6e8; color: #9a6410; }
.notice-info { background: #eef5ff; color: #185aa8; }

.thread { max-height: 520px; overflow: auto; padding: 8px 4px 12px; display: flex; flex-direction: column; gap: 10px; }

.msg { display: flex; }
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }

.bubble { max-width: 74%; padding: 10px 14px; border-radius: 16px; }
.bubble.customer { background: #f2f5f9; }
.bubble.api { background: #e7f1ff; }
.bubble.mobile { background: #e7f8ee; }
.bubble.history { background: #f6f7f9; }
.bubble p { margin: 0; white-space: pre-wrap; font-weight: 600; }
.bubble small { display: block; margin-top: 6px; color: var(--muted); font-weight: 700; font-size: 11.5px; }

.steps { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.step { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; }
.step + .step { border-top: 1px solid #f0f4f8; }
.num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e7f1ff;
    color: var(--blue);
    display: grid;
    place-items: center;
    font-weight: 800;
    flex: none;
}
.step p { margin: 4px 0 0; color: #526277; font-weight: 600; font-size: 13.5px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid #f0f4f8; font-weight: 700; }
.kv span { color: var(--muted); }

.rules { margin: 0; padding: 0 18px 8px 0; }
.rules li { margin: 8px 0; font-weight: 700; color: #3c4d62; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 12px 8px; border-top: 1px solid #f0f4f8; font-size: 14px; }
th { color: var(--muted); font-size: 12.5px; font-weight: 800; }

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at top, #16467a, #0c2340 55%);
    padding: 24px;
}

.auth-card {
    width: min(440px, 100%);
    background: #fff;
    border-radius: 28px;
    padding: 32px 28px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.auth-card h1 { margin: 0; font-size: 28px; font-weight: 800; }
.auth-card .lead { margin: 6px 0 22px; color: var(--muted); font-weight: 700; }
.auth-submit { width: 100%; margin-top: 6px; }
.auth-hint { margin: 16px 0 0; color: var(--muted); font-size: 13px; font-weight: 700; text-align: center; }

.connect-wrap { max-width: 560px; margin: 12px auto 0; text-align: center; }
.connect-mark {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 24px rgba(37, 211, 102, 0.28);
}
.connect-mark svg { width: 34px; height: 34px; }
.connect-wrap h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.3px; }
.connect-lead { margin: 8px 0 22px; color: #7d8da3; font-weight: 700; }
.connect-card {
    background: #fff;
    border: 1px solid #e6edf5;
    border-radius: 18px;
    box-shadow: 0 16px 40px rgba(16, 42, 74, 0.06);
    padding: 22px 22px 18px;
    text-align: right;
}
.connect-card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 800; }
.connect-benefits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.connect-benefits li { display: flex; align-items: flex-start; gap: 10px; font-weight: 700; color: #31445c; line-height: 1.6; }
.connect-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e8f8ee;
    color: #16a34a;
    display: grid;
    place-items: center;
    flex: none;
    margin-top: 1px;
}
.connect-check svg { width: 14px; height: 14px; }
.connect-split { height: 1px; background: #eef2f6; margin: 18px 0; }
.connect-launch {
    width: 100%;
    height: 48px;
    border: 0;
    border-radius: 10px;
    background: var(--green);
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.connect-launch:hover { filter: brightness(0.97); }
.connect-launch:disabled { opacity: 0.55; cursor: not-allowed; }
.connect-launch svg { width: 18px; height: 18px; }
.connect-hint { margin: 12px 0 0; text-align: center; color: #8b9aaf; font-size: 13px; font-weight: 700; }
.connect-reqs {
    margin-top: 16px;
    background: #f7f9fc;
    border-radius: 12px;
    padding: 14px 16px;
    text-align: right;
}
.connect-reqs strong { display: block; margin-bottom: 6px; }
.connect-reqs ul { margin: 0; padding: 0 18px 0 0; color: #5c6d82; font-weight: 700; font-size: 13.5px; }
.connect-reqs li { margin: 4px 0; }
.connect-terms { margin: 22px 0 0; color: #8b9aaf; font-size: 13px; font-weight: 700; }
.connect-terms a { color: #3d6f9a; text-decoration: underline; }
.connect-admin { margin-top: 18px; text-align: right; display: flex; flex-direction: column; gap: 8px; }
.connect-admin form { margin: 0; }
.connect-status { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid #f0f4f8; font-weight: 800; }
.connect-status span { color: var(--muted); font-weight: 700; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }

@media (max-width: 1180px) {
    .stats, .status-grid, .thirds { grid-template-columns: 1fr 1fr; }
    .split, .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; height: auto; position: relative; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .side-foot { margin-top: 16px; }
    .topbar { flex-wrap: wrap; }
    .search-form { min-width: 100%; order: 5; }
    .stats, .status-grid, .thirds { grid-template-columns: 1fr; }
}
