/* ============================================================
   👑 KINGxSMS — Central Dark Theme (Task 3)
   Location: /public_html/assets/css/theme.css
   Load this BEFORE page-specific inline styles so var() resolves.
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
    /* Brand */
    --primary: #ff2a5f;
    --primary-dark: #b9002d;
    --primary-grad: linear-gradient(135deg, #ff2a5f 0%, #b9002d 100%);
    --primary-glow: rgba(255, 42, 95, 0.25);

    /* Surfaces */
    --bg: #0a0f1c;
    --bg-deep: #050b14;
    --surface: rgba(15, 23, 42, 0.8);
    --surface-solid: #0f172a;
    --surface-2: rgba(30, 41, 59, 0.55);
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);

    /* Text */
    --text: #e2e8f0;
    --text-strong: #ffffff;
    --muted: #94a3b8;

    /* Semantic */
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Shape & depth */
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55);
    --shadow-sm: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    --blur: 16px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --dur: 0.3s;
}

/* ---------- Base ---------- */
body {
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 15% 50%, rgba(255, 42, 95, 0.06), transparent 28%),
        radial-gradient(circle at 85% 30%, rgba(59, 130, 246, 0.06), transparent 28%);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
::selection { background: rgba(255, 42, 95, 0.35); color: #fff; }

/* ---------- Glass / Surfaces ---------- */
.glass {
    background: var(--surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
}
.glass-strong {
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
}
.card {
    background: var(--surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.card:hover { border-color: rgba(255, 42, 95, 0.25); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease);
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary-grad); color: #fff; box-shadow: 0 8px 20px -6px var(--primary-glow); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 28px -8px var(--primary-glow); }
.btn-ghost { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.4); color: #60a5fa; }
.btn-ghost:hover { background: rgba(59, 130, 246, 0.22); transform: translateY(-2px); }
.btn-danger { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); color: #f87171; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.22); transform: translateY(-2px); }
.btn-success { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.4); color: #4ade80; }
.btn-success:hover { background: rgba(34, 197, 94, 0.22); transform: translateY(-2px); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.75rem; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

/* ---------- Forms ---------- */
.input, .select, .textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-strong);
    color: var(--text-strong);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
    font-size: 0.875rem;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.input::placeholder { color: #475569; }
.select option { background: var(--surface-solid); color: var(--text); }
.label {
    display: block;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}

/* ---------- Tables ---------- */
.table-wrap {
    background: var(--surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; }
.table thead th {
    background: rgba(15, 23, 42, 0.75);
    color: var(--muted);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: left;
    padding: 0.85rem 1.25rem;
    white-space: nowrap;
}
.table tbody td { padding: 0.85rem 1.25rem; border-top: 1px solid var(--border); font-size: 0.85rem; vertical-align: middle; }
.table tbody tr { transition: background var(--dur) var(--ease); }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
.table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.015); }
.table tbody tr:nth-child(even):hover { background: rgba(255, 255, 255, 0.05); }

/* ---------- Badges & Pills ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.7rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-success { background: rgba(34, 197, 94, 0.14); color: #4ade80; border-color: rgba(34, 197, 94, 0.35); }
.badge-warning { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35); }
.badge-danger  { background: rgba(239, 68, 68, 0.14); color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
.badge-info    { background: rgba(59, 130, 246, 0.14); color: #60a5fa; border-color: rgba(59, 130, 246, 0.35); }
.badge-muted   { background: rgba(148, 163, 184, 0.12); color: var(--muted); border-color: rgba(148, 163, 184, 0.25); }

/* ---------- Stat cards ---------- */
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
    width: 2.75rem; height: 2.75rem;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; color: var(--text-strong); letter-spacing: -0.02em; }
.stat-card .stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- Empty states ---------- */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 3.5rem 1.5rem; text-align: center; color: var(--muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.6; }
.empty-state h4 { color: var(--text); font-size: 1rem; margin: 0 0 0.25rem; }
.empty-state p { font-size: 0.8rem; }

/* ---------- Modals ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(5, 11, 20, 0.8);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-card {
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid var(--border-strong);
    border-radius: 1.1rem;
    box-shadow: var(--shadow);
    width: 100%; max-width: 30rem;
    max-height: 88vh; overflow-y: auto;
    animation: modalIn 0.28s var(--ease);
}
.modal-in { animation: modalIn 0.28s var(--ease); }

/* ---------- Animations ---------- */
.fade-in { animation: fadeIn 0.45s var(--ease) both; }
.slide-in-up { animation: slideUp 0.45s var(--ease) both; }
.hover-lift { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.hover-lift:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.pulse-dot { animation: pulse 2s infinite; }
.toast-in { animation: toastIn 0.3s var(--ease); }
.pop-in { animation: popIn 0.45s var(--ease); }

/* Stagger helpers (use with .fade-in / .slide-in-up) */
.stagger-1 { animation-delay: 0.05s; } .stagger-2 { animation-delay: 0.12s; }
.stagger-3 { animation-delay: 0.19s; } .stagger-4 { animation-delay: 0.26s; }
.stagger-5 { animation-delay: 0.33s; } .stagger-6 { animation-delay: 0.40s; }

/* Skeleton loading */
.skeleton {
    position: relative;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.12);
    border-radius: 8px;
    min-height: 1rem;
}
.skeleton::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
    animation: shimmer 1.4s infinite;
}

/* Step indicator */
.steps { display: flex; align-items: center; gap: 0.35rem; }
.step {
    display: flex; align-items: center; justify-content: center;
    width: 1.9rem; height: 1.9rem; border-radius: 999px;
    font-size: 0.78rem; font-weight: 700;
    background: rgba(148, 163, 184, 0.15); color: var(--muted);
    border: 1px solid var(--border-strong);
    transition: all var(--dur) var(--ease);
    flex-shrink: 0;
}
.step.active { background: var(--primary-grad); color: #fff; border-color: transparent; box-shadow: 0 6px 16px -4px var(--primary-glow); }
.step.done { background: rgba(34, 197, 94, 0.2); color: #4ade80; border-color: rgba(34, 197, 94, 0.4); }
.step-line { height: 2px; flex: 1; max-width: 3rem; background: var(--border-strong); border-radius: 2px; }
.step-line.done { background: var(--success); }

/* Status pills */
.pill {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.25rem 0.8rem; border-radius: 999px;
    font-size: 0.72rem; font-weight: 600;
}
.pill-on { background: rgba(34, 197, 94, 0.14); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.35); }
.pill-off { background: rgba(148, 163, 184, 0.12); color: var(--muted); border: 1px solid rgba(148, 163, 184, 0.25); }
.pill-waiting { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.35); }
.pill-success { background: rgba(34, 197, 94, 0.14); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.35); }
.pill-danger { background: rgba(239, 68, 68, 0.14); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.35); }

/* Collapsible (providers credentials etc.) */
.collapsible { overflow: hidden; transition: max-height 0.35s var(--ease); max-height: 0; }
.collapsible.open { max-height: 40rem; }

/* ---------- Keyframes ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }

/* ---------- Responsive helpers ---------- */
.show-mobile { display: none !important; }
@media (max-width: 767px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    /* Table → card view on mobile */
    .table-card-mobile thead { display: none; }
    .table-card-mobile, .table-card-mobile tbody, .table-card-mobile tr, .table-card-mobile td { display: block; width: 100%; }
    .table-card-mobile tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 0.75rem; padding: 0.5rem 0; background: var(--surface); }
    .table-card-mobile td { border-top: none !important; border-bottom: 1px dashed var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 1rem; }
    .table-card-mobile td:last-child { border-bottom: none; }
    .table-card-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; margin-right: 1rem; }
    .modal-card { max-width: 100%; margin: 0 0.5rem; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   v2.0 — Cross-browser + Telegram Mini App layer
   ============================================================ */

/* ---- Global overflow guard: NO horizontal scroll anywhere ---- */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
img, video, table, pre, code, iframe { max-width: 100%; }
* { -webkit-tap-highlight-color: transparent; }

/* ---- Telegram WebApp: viewport & safe areas ---- */
html.tg, body.tg {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}
body.tg {
    padding-top: var(--tg-safe-top, 0px);
    padding-bottom: var(--tg-safe-bottom, 0px);
}
/* Native safe-area fallback for phones WITHOUT Telegram JS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
    .safe-top    { padding-top: env(safe-area-inset-top); }
}
/* Dynamic viewport height (modern mobile browsers — fixes address-bar jump) */
.vh-full { height: 100vh; height: 100dvh; }
.min-vh-full { min-height: 100vh; min-height: 100dvh; }

/* ---- Fixed bottom navigation (mobile / Telegram) ---- */
.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    background: rgba(11, 17, 32, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--border-strong);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    transition: color 0.2s;
    min-width: 56px;
}
.bottom-nav .nav-item i { font-size: 19px; }
.bottom-nav .nav-item.active, .bottom-nav .nav-item:active { color: var(--primary); }
/* Content spacer so fixed nav never covers the last card */
.nav-spacer { height: calc(76px + env(safe-area-inset-bottom, 0px)); }

/* ---- Terminal (worker console) ---- */
.terminal {
    background: #060b14;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}
.terminal-head {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px 12px 0 0;
}
.terminal-dot { width: 10px; height: 10px; border-radius: 50%; }
.terminal-body { padding: 14px; min-height: 120px; font-size: 12.5px; line-height: 1.65; overflow-x: auto; }
.term-line { display: flex; gap: 10px; }
.term-prompt { color: var(--primary); font-weight: 700; flex-shrink: 0; }
.term-cmd { color: #e2e8f0; }
.term-ok { color: #4ade80; }
.term-info { color: #60a5fa; }
.term-warn { color: #fbbf24; }
.term-err { color: #f87171; }
.term-dim { color: #64748b; }

/* Blinking cursor */
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
.term-cursor { display: inline-block; width: 8px; height: 14px; background: var(--primary); vertical-align: middle; animation: blink 1s infinite; }

/* ---- Auto-Pilot toggle ---- */
.autopilot-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.autopilot-switch input { opacity: 0; width: 0; height: 0; }
.autopilot-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: rgba(148, 163, 184, 0.25);
    border: 1px solid var(--border-strong);
    border-radius: 26px;
    transition: background 0.25s, border-color 0.25s;
}
.autopilot-slider::before {
    content: '';
    position: absolute; height: 20px; width: 20px;
    left: 2px; bottom: 2px;
    background: #e2e8f0;
    border-radius: 50%;
    transition: transform 0.25s;
}
.autopilot-switch input:checked + .autopilot-slider { background: var(--primary); border-color: var(--primary); }
.autopilot-switch input:checked + .autopilot-slider::before { transform: translateX(20px); background: #fff; }
.autopilot-on { color: var(--primary); }

/* ---- TTL countdown chip ---- */
.ttl-chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; font-weight: 700;
    padding: 3px 9px; border-radius: 999px;
    background: rgba(245, 158, 11, 0.12); color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.ttl-chip.expired { background: rgba(239, 68, 68, 0.14); color: #f87171; border-color: rgba(239, 68, 68, 0.4); animation: pulse 1s infinite; }

/* ---- Sidebar desktop guarantee (w-64 fixed) ---- */
#sidebar, .app-sidebar { width: 16rem; } /* 256px = w-64 */
@media (max-width: 1023px) {
    #sidebar, .app-sidebar { width: 16rem; }
}

/* ---- Tablet / mobile padding tuning ---- */
@media (max-width: 639px) {
    .p-responsive { padding: 0.9rem; }
}

/* ═══════════════════════════════════════════════════════════════
   v5 — GLOBAL BRANDING & RESPONSIVE POLISH (Task 5)
   ═══════════════════════════════════════════════════════════════ */

/* ---- Animated green pulsing balance badge ---- */
.kx-pulse-balance {
    display: inline-flex; align-items: center;
    font-variant-numeric: tabular-nums;
    padding: 4px 12px; border-radius: 999px;
    color: #34d399 !important;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.35);
    animation: kxBalancePulse 2.2s ease-in-out infinite;
    white-space: nowrap;
}
@keyframes kxBalancePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45); }
    50%      { box-shadow: 0 0 14px 3px rgba(16, 185, 129, 0.55); }
}

/* ---- KINGxSMS logo treatment (KING white · x red · SMS white) ---- */
/* v6 FIX: full "KINGxSMS" must NEVER truncate to "KINGx" — inline-flex +
   nowrap + flex-shrink:0 + min-width:max-content keeps the brand intact
   inside narrow flex headers (desktop sidebar, mobile topbar, admin/agent). */
.kx-logo {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: max-content;
    font-weight: 900;
    letter-spacing: 0.02em;
    color: #ffffff;
    line-height: 1;
}
.kx-logo .kx-x { color: #ff2a5f; }
/* Header containers: let the logo breathe, siblings shrink instead */
.kx-topbar { flex-wrap: wrap; }
.kx-topbar > * { min-width: 0; }

/* ---- Telegram Mini App viewport (~396px) & small phones ---- */
@media (max-width: 420px) {
    .worker-steps .step { width: 2rem; height: 2rem; font-size: 0.75rem; }
    #stage1 .grid, #stage2 .grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 0.6rem; }
    #stage3 .glass { padding: 1rem; }
    .ttl-chip { font-size: 10px; padding: 2px 7px; }
    .terminal-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    body, main { overflow-x: hidden; }
    #terminalBody td { padding-left: 0.9rem; padding-right: 0.9rem; }
}

/* ---- Small landscape phones ---- */
@media (max-height: 480px) and (orientation: landscape) {
    #stage3 .glass { max-height: 78vh; overflow-y: auto; }
    .stat-card { padding: 0.9rem; }
}

/* ---- Compact admin tables on narrow screens ---- */
@media (max-width: 639px) {
    .table-responsive { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-responsive table { min-width: 560px; }
}

/* ═══════════════════════════════════════════════════════════
   👑 KINGxSMS v6 DIAMOND — viewport polyfills & theme tokens
   Cross-browser (Chrome/Safari iOS+macOS/Firefox/Edge) and
   in-app WebViews (Telegram Mini App / TikTok / Instagram).
   ═══════════════════════════════════════════════════════════ */
:root {
    --kx-bg: #0a0f1c;          /* Diamond bg */
    --kx-card: #111827;        /* Diamond card */
    --kx-accent: #ff2a5f;      /* Diamond accent */
    --kx-success: #10b981;     /* Diamond success */
    --kx-radius: 1rem;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    height: auto !important;
    max-width: 100%;
    overflow-x: clip;
}
html { overflow-x: hidden; }
body { overflow-x: hidden; }
main, section, article { max-width: 100%; }
body {
    background: var(--kx-bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* 100dvh app shells (mobile URL-bar safe) */
.h-screen { height: 100vh; height: 100dvh; }
.min-h-screen { min-height: 100vh; min-height: 100dvh; }

/* Safe-area insets for notch devices */
.pb-safe { padding-bottom: env(safe-area-inset-bottom, 0px); }
.pt-safe { padding-top: env(safe-area-inset-top, 0px); }
.pl-safe { padding-left: env(safe-area-inset-left, 0px); }
.pr-safe { padding-right: env(safe-area-inset-right, 0px); }

/* Tap highlight + input reset */
* { -webkit-tap-highlight-color: transparent; }
input, select, textarea, button { font-family: inherit; }
select, input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
    -webkit-appearance: none; appearance: none;
    border-radius: var(--kx-radius);
}

/* Flex/grid hardening — no shrinking/overflow surprises */
img, svg, video { max-width: 100%; height: auto; }
.flex { min-width: 0; }
.truncate { min-width: 0; }

/* Diamond card consistency */
.glass-card, .stat-card {
    background: rgba(17, 24, 39, 0.86) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Smooth 60fps micro-interactions (Diamond 2B) */
.btn-hover { transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease; }
.btn-hover:hover { transform: scale(1.03); box-shadow: 0 8px 20px -6px rgba(255, 42, 95, 0.35); }
.btn-hover:active { transform: scale(0.95); }

/* ── Role badges (PRODUCTION branding) ── */
.kx-role-badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 9.5px; font-weight: 800; text-transform: uppercase;
    letter-spacing: .05em; padding: 3px 8px; border-radius: 999px;
    border: 1px solid; white-space: nowrap; flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   PRODUCTION 7C: LIGHT THEME (html.light)
   Toggled by the 🌙/☀️ topbar button (kx-v6.js).
   ═══════════════════════════════════════════════════════════ */
html.light body,
html.light {
    --bg-deep: #f1f5f9 !important;
    --surface: rgba(255, 255, 255, 0.92) !important;
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
}
html.light body { background-color: #f1f5f9 !important; }
html.light .glass,
html.light .glass-card,
html.light .glass-panel,
html.light .stat-card,
html.light .folder-card {
    background: rgba(255, 255, 255, 0.92) !important;
    border-color: rgba(15, 23, 42, 0.08) !important;
    color: #0f172a;
}
html.light .text-white, html.light h1, html.light h2, html.light h3, html.light h4,
html.light .kx-logo, html.light .text-slate-200, html.light .text-slate-300 {
    color: #0f172a !important;
}
html.light .text-slate-400, html.light .text-slate-500, html.light .text-slate-600 { color: #475569 !important; }
html.light .bg-slate-900, html.light .bg-slate-800,
html.light .bg-\[#0a0f1c\] {
    background-color: #ffffff !important;
}
html.light input, html.light select, html.light textarea {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: rgba(15, 23, 42, 0.15) !important;
}
html.light .glass-strong { background: rgba(255,255,255,.95) !important; }
html.light nav a { color: #334155 !important; }
html.light nav a:hover { background: rgba(15,23,42,.05) !important; }
html.light .kx-topbar, html.light header { background: rgba(255,255,255,.9) !important; }

/* ═══════════════════════════════════════════════════════════
   KINGxSMS v7.2 — Responsive & mobile hardening
   ═══════════════════════════════════════════════════════════ */
html, body { overflow-x: hidden; }
body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

/* Mobile bottom nav: safe-area + no horizontal scroll */
.bottom-nav, [data-kx-bottomnav] {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    overflow-x: auto;
    scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar, [data-kx-bottomnav]::-webkit-scrollbar { display: none; }

/* Any fixed FAB must clear the mobile bottom nav */
body.fixed .fixed[class*="bottom-"], .fixed[class*="bottom-20"], .fixed[class*="bottom-24"] {
    margin-bottom: 0;
}
@media (max-width: 767px) {
    .fixed[class*="bottom-20"] { bottom: 84px !important; }
    .fixed[class*="bottom-24"] { bottom: 96px !important; }
}

/* Wide tables: guarantee the wrapper scrolls instead of breaking layout */
.overflow-x-auto { -webkit-overflow-scrolling: touch; }
table.table-card-mobile { min-width: 0; }

/* Sticky sidebar topbar stays on top of modals */
.glass-panel .glass-panel { box-shadow: none; }

/* Prevent modal content overflow on small screens */
.modal-animate, [id$="Modal"] .glass-panel { max-height: 92vh; overflow-y: auto; }

/* Buttons: never shrink labels on narrow screens */
button, .btn { white-space: normal; }

/* Harden the unified header on phones */
@media (max-width: 640px) {
    .kx-topbar, header { padding-left: 12px; padding-right: 12px; }
    h1, h2, h3 { word-break: break-word; }
}

/* v7.4: page-level support FABs are ALWAYS hidden — the kx-v6 floating chat
   is the single support entry point (prevents the double-icon bug for good,
   even when an old kx-v6.js is cached by the browser). */
.kx-page-fab { display: none !important; }

/* ═══════════════════════════════════════════════════════════
   v7.6 — MOBILE SCROLL FIX (bulletproof)
   The app-shell layout (body{overflow:hidden;height:100vh} + inner
   overflow-y-auto) is unreliable on Android Chrome/iOS where 100vh
   changes as the address bar collapses. On phones we let the BODY
   scroll naturally — the page can NEVER get stuck again.
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    body, html {
        overflow: visible !important;
        height: auto !important;
        min-height: 100vh;
        position: static !important;
    }
    body > .flex.flex-1, body .flex-1.overflow-hidden,
    main, main.flex-1, .app-shell {
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
    }
    /* keep fixed elements (bottom nav, FABs, modals) working */
    .fixed { position: fixed !important; }
}

/* v7.6.1: mobile header logo shows when sidebar is CLOSED, hides while it is open (no double logo) */
.kx-header-logo { display: inline-flex; }
@media (max-width: 1023px) {
    body.kx-nav-open .kx-header-logo { display: none !important; }
}
