/* ========================================================================
   LiteBroadcast — Global Production CSS
   ========================================================================
   This file provides:
   1. Design tokens (CSS custom properties) aligned with Tailwind config
   2. Consolidated utility classes used across multiple pages
   3. Bootstrap overrides scoped to avoid Tailwind conflicts
   4. Reusable animation/interaction helpers
   ======================================================================== */

/* ── 1. Design Tokens ── */
:root {
    /* Brand Colors — matches Tailwind config in base.html */
    --lb-primary: #0d33f2;
    --lb-primary-dark: #0a28c2;
    --lb-primary-rgb: 13, 51, 242;
    --lb-gradient: linear-gradient(135deg, #0d33f2 0%, #4f46e5 100%);

    /* Surfaces */
    --lb-bg-light: #f8fafc;
    --lb-bg-card: #ffffff;
    --lb-border: #e2e8f0;
    --lb-border-light: #f1f5f9;

    /* Text */
    --lb-text-primary: #0f172a;
    --lb-text-secondary: #64748b;
    --lb-text-muted: #94a3b8;

    /* Semantic */
    --lb-success: #10b981;
    --lb-warning: #f59e0b;
    --lb-danger: #ef4444;
    --lb-info: #0ea5e9;

    /* Typography */
    --lb-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --lb-font-display: 'Plus Jakarta Sans', 'Inter', sans-serif;

    /* Shadows */
    --lb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --lb-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --lb-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
    --lb-shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.1);

    /* Layout */
    --lb-sidebar-width: 280px;
    --lb-header-height: 80px;
    --lb-header-height-md: 90px;
}

/* ========================================================================
   CRITICAL FIX: Context-Aware Border System & Bootstrap Override
   ========================================================================
   Bootstrap 5's .border rule uses !important and hardcoded #dee2e6.
   We override it here so light surfaces receive a soft modern border,
   and dark surfaces (sidebar, cards, headers) receive ultra-subtle 
   translucent borders instead of harsh, generic white wireframes.
   ======================================================================== */
:root {
    --bs-border-color: rgba(226, 232, 240, 0.8) !important;
    --bs-border-color-translucent: rgba(226, 232, 240, 0.8) !important;
}

/* Dark surfaces, sidebar, and cards: borders must NEVER be harsh white */
.sidebar-bg, 
aside, 
#main-sidebar, 
.dark, 
[data-bs-theme="dark"],
[class*="bg-slate-900"], 
[class*="bg-slate-800"], 
[class*="from-slate-900"], 
[class*="from-slate-800"],
.dark-surface {
    --bs-border-color: rgba(255, 255, 255, 0.08) !important;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.08) !important;
}

/* Override Bootstrap's shorthand .border */
.border {
    border-width: 1px !important;
    border-style: solid !important;
    border-color: var(--bs-border-color) !important;
}
.border-t, .border-top {
    border-top-width: 1px !important;
    border-top-style: solid !important;
    border-top-color: var(--bs-border-color) !important;
}
.border-b, .border-bottom {
    border-bottom-width: 1px !important;
    border-bottom-style: solid !important;
    border-bottom-color: var(--bs-border-color) !important;
}
.border-l, .border-start {
    border-left-width: 1px !important;
    border-left-style: solid !important;
    border-left-color: var(--bs-border-color) !important;
}
.border-r, .border-end {
    border-right-width: 1px !important;
    border-right-style: solid !important;
    border-right-color: var(--bs-border-color) !important;
}

/* Specific border color utilities with priority over Bootstrap */
[class*="border-slate-800"] { border-color: rgba(30, 41, 59, 0.8) !important; }
[class*="border-slate-700"] { border-color: rgba(51, 65, 85, 0.6) !important; }
[class*="border-slate-600"] { border-color: rgba(71, 85, 105, 0.5) !important; }
[class*="border-slate-200"] { border-color: #e2e8f0 !important; }
[class*="border-slate-100"] { border-color: #f1f5f9 !important; }
[class*="border-emerald-500"] { border-color: rgba(16, 185, 129, 0.25) !important; }
[class*="border-emerald-400"] { border-color: rgba(52, 211, 153, 0.25) !important; }
[class*="border-blue-500"] { border-color: rgba(59, 130, 246, 0.25) !important; }
[class*="border-blue-400"] { border-color: rgba(96, 165, 250, 0.25) !important; }
[class*="border-indigo-500"] { border-color: rgba(99, 102, 241, 0.25) !important; }
[class*="border-amber-500"] { border-color: rgba(245, 158, 11, 0.25) !important; }
[class*="border-red-500"] { border-color: rgba(239, 68, 68, 0.25) !important; }
[class*="border-white\/"] { border-color: rgba(255, 255, 255, 0.1) !important; }

/* ── 2. Base Resets ── */
body {
    font-family: var(--lb-font-sans);
    color: var(--lb-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Ensure Bootstrap doesn't override body bg set by Tailwind */
body.bg-background-light {
    background-color: var(--lb-bg-light) !important;
}

.font-display {
    font-family: var(--lb-font-display);
}

/* Remove underline from all links by default (Tailwind reset) */
a {
    text-decoration: none;
    transition: color 0.2s ease, opacity 0.2s ease;
}


/* ── 3. Reusable Interaction Utilities ── */

/* Hover lift — subtle rise on hover (used on buttons, cards) */
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

/* Hover scale — subtle press scale (used on action buttons) */
.hover-scale {
    transition: transform 0.15s ease;
}
.hover-scale:hover {
    transform: scale(1.05);
}
.hover-scale:active {
    transform: scale(0.95);
}

/* Clickable table rows */
tbody tr.clickable-row {
    transition: background-color 0.15s ease;
    cursor: pointer;
}
tbody tr.clickable-row:hover {
    background-color: #f8f9fa !important;
}

/* White button helper (Bootstrap doesn't have btn-white) */
.btn-white {
    background-color: #fff;
    border: 1px solid var(--lb-border);
}
.btn-white:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

/* Fade-in animation for dynamic content */
.fade-in {
    animation: fadeIn 0.2s ease-in;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* ── 4. Bootstrap Component Overrides ── */
/* These align Bootstrap defaults with the LiteBroadcast design language */

/* Cards — softer, more rounded */
.bootstrap-wrapper .card {
    border: none;
    border-radius: 12px;
    box-shadow: var(--lb-shadow-sm);
    background: var(--lb-bg-card);
}

.bootstrap-wrapper .card-header {
    background: var(--lb-bg-card);
    border-bottom: 1px solid var(--lb-border-light);
}

/* Primary button aligned to LiteBroadcast blue */
.bootstrap-wrapper .btn-primary {
    background-color: var(--lb-primary);
    border-color: var(--lb-primary);
    font-weight: 600;
}
.bootstrap-wrapper .btn-primary:hover,
.bootstrap-wrapper .btn-primary:focus {
    background-color: var(--lb-primary-dark);
    border-color: var(--lb-primary-dark);
}

/* Form controls — consistent feel */
.bootstrap-wrapper .form-control,
.bootstrap-wrapper .form-select {
    border-radius: 10px;
    border: 1px solid var(--lb-border);
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.bootstrap-wrapper .form-control:focus,
.bootstrap-wrapper .form-select:focus {
    border-color: var(--lb-primary);
    box-shadow: 0 0 0 3px rgba(var(--lb-primary-rgb), 0.08);
}

/* Form labels */
.bootstrap-wrapper .form-label {
    font-weight: 600;
    color: var(--lb-text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* Tables — cleaner headers */
.bootstrap-wrapper .table thead th {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--lb-text-muted);
    border-bottom: 1px solid var(--lb-border-light);
}

/* Pagination — rounded */
.bootstrap-wrapper .page-link {
    border-radius: 8px !important;
    margin: 0 2px;
    color: var(--lb-text-secondary);
    border: none;
}
.bootstrap-wrapper .page-item.active .page-link {
    background-color: var(--lb-primary);
    border-color: var(--lb-primary);
}


/* ── 5. Dropdown Layering (for tables with stretched-link) ── */
/* Used in template_list.html and similar tables */
.template-row {
    transition: background-color 0.2s;
    position: relative;
    z-index: 1;
}
.template-row:hover,
.template-row:focus-within {
    z-index: 1050;
}
.actions-column {
    position: relative;
    z-index: 1060 !important;
}
.bootstrap-wrapper .dropdown-menu {
    z-index: 1070 !important;
}


/* ── 6. Sidebar Styles ── */
/* Active link gradient (used in base.html sidebar) */
.active-link {
    background: var(--lb-gradient);
    box-shadow: 0 4px 15px -3px rgba(var(--lb-primary-rgb), 0.4);
    color: white !important;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: #1e293b;
    border-radius: 10px;
}


/* ── 7. Phone Preview (Shared across template_create, template_detail, broadcast) ── */
.phone-frame {
    background: #1e293b;
    border-radius: 40px;
    padding: 10px;
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.3);
    border: 6px solid #334155;
    max-width: 340px;
    width: 100%;
    margin: 0 auto;
    position: relative;
}
.phone-notch {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 20px;
    background: #1e293b;
    border-radius: 0 0 14px 14px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.phone-notch .cam {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #334155;
}
.phone-notch .speaker {
    width: 30px;
    height: 4px;
    border-radius: 4px;
    background: #334155;
}
.phone-screen {
    background: #efeae2;
    border-radius: 30px;
    height: 560px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* WhatsApp UI elements */
.wa-header {
    background: #008069;
    color: #fff;
    padding: 14px 16px;
    padding-top: 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.wa-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.wa-name {
    font-weight: 700;
    font-size: 14px;
}
.wa-sub {
    font-size: 10px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}
.wa-sub .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34d399;
}
.wa-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.wa-chat::-webkit-scrollbar {
    width: 4px;
}
.wa-chat::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}
.wa-date {
    align-self: center;
    background: rgba(255, 255, 255, 0.6);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 10px;
    color: #667781;
    font-weight: 600;
    margin-bottom: 12px;
}
.wa-bubble {
    background: #fff;
    border-radius: 0 12px 12px 12px;
    padding: 8px 10px;
    max-width: 95%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    position: relative;
    margin-bottom: 6px;
}
.wa-bubble::before {
    content: "";
    position: absolute;
    top: 0;
    left: -8px;
    border: 8px solid transparent;
    border-top-color: #fff;
    border-right-color: #fff;
}
.wa-bubble .header-text {
    font-weight: 800;
    font-size: 14px;
    color: #111b21;
    margin-bottom: 4px;
    overflow-wrap: break-word;
}
.wa-bubble .body-text {
    font-size: 14px;
    color: #111b21;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
}
.wa-bubble .footer-text {
    font-size: 11px;
    color: #667781;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #f0f2f5;
}
.wa-bubble .time-stamp {
    font-size: 10px;
    color: #667781;
    float: right;
    margin-top: 4px;
    margin-left: 8px;
}
.wa-media-box {
    background: #e9edef;
    border-radius: 8px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 6px;
    overflow: hidden;
}
.wa-media-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wa-media-box video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.wa-media-box i {
    font-size: 2.5rem;
    color: #8696a0;
}
.wa-media-box span {
    font-size: 10px;
    color: #8696a0;
    font-weight: 600;
}
.wa-action-btn {
    background: #fff;
    color: #0084ff;
    text-align: center;
    padding: 9px;
    border-radius: 8px;
    margin-top: 6px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.wa-action-btn i {
    font-size: 16px;
}
.wa-input-bar {
    flex-shrink: 0;
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
}
.wa-input-bar .input-fake {
    flex: 1;
    background: #fff;
    border-radius: 20px;
    height: 36px;
}
.wa-input-bar .mic-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #00a884;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

/* Phone preview responsive — column layout */
.editor-preview-col {
    position: sticky;
    top: 20px;
    flex: 0 0 370px;
    max-width: 370px;
    width: 100%;
}

@media (max-width: 991px) {
    .editor-preview-col {
        position: static;
        flex: 1 1 100%;
        max-width: 100%;
    }
}


/* ── 8. Scoped Form Styles ── */
/* Used in contact_form, number_create — scoped to avoid leaking */
.custom-form-field input[type="text"],
.custom-form-field input[type="tel"],
.custom-form-field input[type="password"],
.custom-form-field input[type="email"],
.custom-form-field input[type="number"],
.custom-form-field select,
.custom-form-field textarea {
    display: block;
    width: 100%;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    color: #0f172a;
    transition: all 0.2s;
    appearance: none;
    font-family: inherit;
    font-size: 0.875rem;
}
.custom-form-field input:focus,
.custom-form-field select:focus,
.custom-form-field textarea:focus {
    outline: none;
    border-color: var(--lb-primary);
    box-shadow: 0 0 0 4px rgba(var(--lb-primary-rgb), 0.1);
    background-color: #ffffff;
}
.custom-form-field input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 0.25rem;
    border: 1px solid #cbd5e1;
    cursor: pointer;
}


/* ── 9. Mobile API Key Cards ── */
.api-key-card {
    border: 1px solid var(--lb-border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    background: var(--lb-bg-card);
    transition: box-shadow 0.2s;
}
.api-key-card:hover {
    box-shadow: var(--lb-shadow-md);
}
.api-key-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--lb-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

/* API code blocks — scrollable on mobile */
.api-code-block {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.api-code-block pre {
    min-width: 0;
    font-size: 11px !important;
}
@media (max-width: 575.98px) {
    .api-code-block pre {
        font-size: 10px !important;
    }
}


/* ── 10. Select2 Alignment ── */
.select2-container .select2-selection {
    background-color: #f8fafc !important;
    border-color: #e2e8f0 !important;
    border-radius: 0.75rem !important;
    min-height: 48px !important;
    display: flex !important;
    align-items: center !important;
}
.select2-container .select2-selection:focus-within {
    border-color: var(--lb-primary) !important;
    box-shadow: 0 0 0 4px rgba(var(--lb-primary-rgb), 0.1) !important;
}


/* ── 11. Responsive Stat Cards ── */
/* Scale down display-6 on mobile for broadcast_detail stat cards */
@media (max-width: 575.98px) {
    .card .display-6 {
        font-size: 1.75rem;
    }
}


/* ── 12. Modern Aurora Hero Card (Company Owner & High-Profile Banners) ── */
.owner-hero-card {
    position: relative;
    background: linear-gradient(135deg, #090e1a 0%, #0f172a 45%, #1e1b4b 100%);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.owner-hero-glow {
    position: absolute;
    top: -60px;
    right: -60px;
    width: 280px;
    height: 280px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.2) 0%, rgba(99, 102, 241, 0) 70%);
    pointer-events: none;
    z-index: 1;
}

.owner-hero-avatar {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(135deg, #0066FF 0%, #6366f1 100%);
    border: 1.5px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 4px 16px rgba(0, 102, 255, 0.35);
}

.owner-badge-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.2px;
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25) !important;
    backdrop-filter: blur(8px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.owner-pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #34d399;
    box-shadow: 0 0 8px #34d399;
    animation: pulseDot 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulseDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.owner-tenant-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: #cbd5e1;
    backdrop-filter: blur(10px);
}


/* ── 13. Modern Sidebar PWA Install Card ── */
.sidebar-pwa-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-pwa-card:hover {
    background: linear-gradient(135deg, rgba(49, 46, 129, 0.4) 0%, rgba(15, 23, 42, 0.95) 100%);
    border-color: rgba(99, 102, 241, 0.45) !important;
    transform: translateY(-1px);
    box-shadow: 0 8px 24px -4px rgba(99, 102, 241, 0.25);
}

.sidebar-pwa-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #0066FF 0%, #6366f1 100%);
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(0, 102, 255, 0.35);
    border: none !important;
    transition: transform 0.2s ease;
}

.sidebar-pwa-card:hover .sidebar-pwa-icon {
    transform: scale(1.08);
}

.sidebar-pwa-badge {
    font-size: 9px;
    font-weight: 800;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3) !important;
    letter-spacing: 0.5px;
}