/* ── Variables ─────────────────────────────────────────────────── */
:root {
    --color-primary:      #2563EB;
    --color-primary-dark: #1D4ED8;
    --color-success:      #16A34A;
    --color-warning:      #D97706;
    --color-danger:       #DC2626;
    --color-text:         #111827;
    --color-muted:        #6B7280;
    --color-placeholder:  #9CA3AF;
    --color-page:         #F9FAFB;
    --color-card:         #FFFFFF;
    --color-border:       #E5E7EB;
    --color-border-hover: #D1D5DB;
    --shadow-card:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-elevated:    0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
    --sidebar-w:          240px;
    --header-h:           56px;
    --bottom-nav-h:       60px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    margin: 0;
    background: var(--color-page);
    color: var(--color-text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}
button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

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

/* Sidebar */
.sidebar {
    display: none;
    width: var(--sidebar-w);
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    background: var(--color-card);
    border-right: 1px solid var(--color-border);
    flex-direction: column;
    z-index: 100;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
}
.sidebar-brand {
    font-size: 16px;
    font-weight: 600;
}
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 12px;
    overflow-y: auto;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--color-muted);
    transition: background 150ms, color 150ms;
}
.sidebar-link:hover { background: var(--color-page); color: var(--color-text); }
.sidebar-link--active {
    background: #EFF6FF;
    color: var(--color-primary);
    font-weight: 500;
    border-left: 3px solid var(--color-primary);
    padding-left: 9px;
}
.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-user-email {
    font-size: 13px;
    color: var(--color-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-logout {
    font-size: 13px;
    color: var(--color-danger);
    padding: 6px 0;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.sidebar-logout:hover { text-decoration: underline; }

/* Mobile header */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-h);
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 90;
}
.mobile-header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

/* Main */
.app-main {
    flex: 1;
    min-width: 0;
    padding: calc(var(--header-h) + 16px) 16px calc(var(--bottom-nav-h) + 16px);
}

/* Bottom nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--color-card);
    border-top: 1px solid var(--color-border);
    display: flex;
    z-index: 90;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    color: var(--color-muted);
    position: relative;
    transition: color 150ms;
}
.bottom-nav-item--active { color: var(--color-primary); }
.bottom-nav-dot {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--color-primary);
}

/* Desktop layout */
@media (min-width: 1025px) {
    .sidebar { display: flex; }
    .mobile-header { display: none; }
    .bottom-nav { display: none; }
    .app-main {
        margin-left: var(--sidebar-w);
        padding: 32px;
        width: calc(100% - var(--sidebar-w));
        max-width: none;
    }
}

/* ── Auth Layout ───────────────────────────────────────────────── */
.auth-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px 16px;
}
.auth-panel {
    width: min(100%, 400px);
    padding: 24px;
    text-align: center;
}
.auth-panel h1 { margin: 0; font-size: 22px; font-weight: 600; }
.auth-panel p  { margin: 6px 0 24px; color: var(--color-muted); }
.auth-form {
    display: grid;
    gap: 16px;
    padding-top: 24px;
    border-top: 1px solid var(--color-border);
    text-align: left;
}
@media (max-width: 767px) {
    .auth-form .button-primary { width: 100%; }
}

/* ── Brand mark ────────────────────────────────────────────────── */
.brand-mark {
    display: inline-grid;
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    place-items: center;
    border-radius: 12px;
    background: var(--color-primary);
    color: #FFF;
    font-weight: 600;
    font-size: 16px;
}
.brand-mark-sm {
    width: 32px;
    height: 32px;
    margin-bottom: 0;
    border-radius: 8px;
    font-size: 13px;
    flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0 16px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    background: var(--color-card);
    color: #374151;
    transition: background 150ms, border-color 150ms, color 150ms;
    white-space: nowrap;
}
.button:hover { background: var(--color-page); border-color: var(--color-border-hover); }
.button:disabled, .button[aria-busy="true"] { opacity: 0.6; cursor: not-allowed; }

.button-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #FFF;
}
.button-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }

.button-danger {
    color: var(--color-danger);
    border-color: #FCA5A5;
}
.button-danger:hover { background: #FEF2F2; }

.button-secondary {
    background: var(--color-card);
    border-color: var(--color-border);
    color: #374151;
}
.button-secondary:hover { background: var(--color-page); }

.button-ghost {
    border-color: transparent;
    background: transparent;
}
.button-ghost:hover { background: var(--color-page); border-color: transparent; }

.button-sm {
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
}

/* ── Form fields ───────────────────────────────────────────────── */
.field { display: grid; gap: 6px; }
.field label { color: #374151; font-size: 13px; font-weight: 500; }
.field input,
.field textarea,
.field select {
    min-height: 44px;
    width: 100%;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-card);
    color: var(--color-text);
    padding: 0 12px;
    outline: none;
    transition: border-color 150ms, box-shadow 150ms;
}
.field textarea { min-height: 120px; padding: 12px; resize: vertical; }
.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.field-error { font-size: 13px; color: var(--color-danger); }
.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
    border-color: var(--color-danger);
}

/* Password toggle */
.input-password-wrap { position: relative; }
.input-password-wrap input { padding-right: 44px; }
.toggle-password {
    position: absolute; right: 0; top: 0;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: var(--color-muted);
}
.toggle-password:hover { color: var(--color-text); }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-card);
}
@media (min-width: 1025px) { .card { padding: 20px; } }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-active    { background: #DCFCE7; color: #16A34A; }
.badge-inactive  { background: #F3F4F6; color: #6B7280; }
.badge-pending   { background: #FEF9C3; color: #A16207; }
.badge-error     { background: #FEE2E2; color: #DC2626; }
.badge-warning   { background: #FEF3C7; color: #92400E; }

/* ── Toggle ────────────────────────────────────────────────────── */
.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    position: absolute; inset: 0;
    background: #D1D5DB;
    border-radius: 999px;
    cursor: pointer;
    transition: background 150ms;
}
.toggle input:checked + .toggle-track { background: var(--color-primary); }
.toggle-track::after {
    content: '';
    position: absolute;
    left: 3px; top: 3px;
    width: 18px; height: 18px;
    background: #FFF;
    border-radius: 50%;
    transition: transform 150ms;
}
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track {
    box-shadow: 0 0 0 3px rgba(37,99,235,0.3);
}
.toggle-label { font-size: 14px; color: var(--color-text); }

/* ── Avatar ────────────────────────────────────────────────────── */
.avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-ae { background: #DBEAFE; color: #1D4ED8; }
.avatar-fj { background: #D1FAE5; color: #065F46; }
.avatar-ko { background: #EDE9FE; color: #5B21B6; }
.avatar-pt { background: #FCE7F3; color: #9D174D; }
.avatar-uz { background: #FEF3C7; color: #92400E; }

/* ── Alert ─────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FCA5A5; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #86EFAC; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #93C5FD; }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 999;
    pointer-events: none;
}
@media (min-width: 1025px) {
    .toast-container { left: auto; right: 24px; transform: none; }
}
.toast {
    max-width: 320px;
    width: max-content;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: var(--shadow-elevated);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 250ms, transform 250ms;
}
.toast--visible { opacity: 1; transform: none; }
.toast-success { background: #DCFCE7; color: #166534; }
.toast-error   { background: #FEE2E2; color: #991B1B; }
.toast-info    { background: #DBEAFE; color: #1E40AF; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 200;
    padding: 0 0 0 0;
}
@media (min-width: 768px) {
    .modal-backdrop { align-items: center; }
}
.modal {
    background: var(--color-card);
    border-radius: 16px 16px 0 0;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-elevated);
}
@media (min-width: 768px) {
    .modal { border-radius: 16px; }
}
.modal-title { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.modal-text  { margin: 0 0 20px; color: var(--color-muted); font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 16px;
    gap: 8px;
}
.empty-state svg   { color: var(--color-placeholder); margin-bottom: 8px; }
.empty-state-title { font-size: 16px; font-weight: 500; color: #374151; margin: 0; }
.empty-state-text  { font-size: 14px; color: var(--color-muted); margin: 0; }

/* ── Page header ───────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 600; }

/* ── Table ─────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--color-border);
    background: var(--color-card);
    box-shadow: var(--shadow-card);
}
table { width: 100%; border-collapse: collapse; }
thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-page);
    white-space: nowrap;
}
tbody td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #F8FAFF; }
.table-actions { display: flex; gap: 8px; align-items: center; }

/* ── Conversation list ─────────────────────────────────────────── */
.conv-list { display: flex; flex-direction: column; gap: 0; }
.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 150ms;
    text-decoration: none;
    color: inherit;
}
.conv-item:first-child { border-radius: 12px 12px 0 0; }
.conv-item:last-child  { border-radius: 0 0 12px 12px; border-bottom: none; }
.conv-item:only-child  { border-radius: 12px; border-bottom: none; }
.conv-item:hover       { background: #F8FAFF; }
.conv-wrap { border: 1px solid var(--color-border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-card); }
.conv-body { flex: 1; min-width: 0; }
.conv-row  { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--color-muted); flex-shrink: 0; }
.conv-preview { font-size: 13px; color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }

/* ── Chat bubbles ──────────────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; gap: 12px; }
.bubble-row { display: flex; flex-direction: column; max-width: 75%; }
.bubble-row--in  { align-self: flex-start; }
.bubble-row--out { align-self: flex-end; align-items: flex-end; }
.bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}
.bubble--in  { background: #F3F4F6; border-bottom-left-radius: 4px; }
.bubble--out { background: #DBEAFE; color: #1E3A8A; border-bottom-right-radius: 4px; }
.bubble-time { font-size: 11px; color: var(--color-muted); margin-top: 4px; padding: 0 4px; }
.chat-date-sep {
    text-align: center;
    font-size: 12px;
    color: var(--color-muted);
    margin: 8px 0;
}

/* ── Filter tabs ───────────────────────────────────────────────── */
.filter-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 16px;
    overflow-x: auto;
}
.filter-tab {
    padding: 8px 14px;
    font-size: 14px;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    cursor: pointer;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    transition: color 150ms, border-color 150ms;
}
.filter-tab:hover { color: var(--color-text); }
.filter-tab--active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 500; }

/* ── Account card ──────────────────────────────────────────────── */
.account-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-card);
}
.account-info { flex: 1; min-width: 0; }
.account-name { font-size: 15px; font-weight: 500; }
.account-meta { font-size: 13px; color: var(--color-muted); }

/* ── Section label ─────────────────────────────────────────────── */
.section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 20px 0 8px;
}

/* ── Skeleton loader ───────────────────────────────────────────── */
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.skeleton {
    background: var(--color-border);
    border-radius: 6px;
    animation: pulse 1.5s ease infinite;
}

/* ── Spinner ───────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #FFF;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.button-primary .spinner { border-color: rgba(255,255,255,0.4); border-top-color: #FFF; }

/* ── QR Code modal ─────────────────────────────────────────────── */
.qr-wrap { text-align: center; padding: 8px 0; }
.qr-wrap img { margin: 0 auto 16px; max-width: 200px; border-radius: 8px; }
.qr-steps { text-align: left; font-size: 14px; color: var(--color-muted); }
.qr-steps li { margin-bottom: 6px; }

/* ── Utilities ─────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.flex     { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.gap-4    { gap: 16px; }
.mt-1     { margin-top: 4px; }
.mt-2     { margin-top: 8px; }
.mt-4     { margin-top: 16px; }
.mb-2     { margin-bottom: 8px; }
.mb-4     { margin-bottom: 16px; }
.gap-1    { gap: 4px; }
.flex-wrap { flex-wrap: wrap; }
.text-sm  { font-size: 13px; }
.text-muted { color: var(--color-muted); }
.font-medium { font-weight: 500; }
.w-full   { width: 100%; }
.grid-form { display: grid; gap: 16px; }
