/* ============================================
   HD BSI Co-Monit — Main Stylesheet
   Bootstrap 5 Extensions + Custom Styles
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
    --cm-primary: #1a56db;
    --cm-primary-dark: #1240a8;
    --cm-secondary: #6366f1;
    --cm-success: #059669;
    --cm-warning: #d97706;
    --cm-danger: #dc2626;
    --cm-orange: #ea580c;
    --cm-info: #0891b2;
    
    --cm-bg: #f0f2f5;
    --cm-surface: #ffffff;
    --cm-surface-hover: #f8f9fa;
    --cm-sidebar-bg: #111827;
    --cm-sidebar-text: #d1d5db;
    --cm-sidebar-active: #1a56db;
    --cm-text: #1f2937;
    --cm-text-muted: #6b7280;
    --cm-border: #e5e7eb;
    --cm-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --cm-shadow-lg: 0 4px 14px rgba(0,0,0,0.1);
    --cm-radius: 12px;
    --cm-radius-sm: 8px;
    --cm-transition: 0.2s ease;

    --sidebar-width: 260px;
    --header-height: 64px;
}

/* ---------- Reset & Base ---------- */
* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--cm-bg);
    color: var(--cm-text);
    margin: 0;
    overflow-x: hidden;
}

a { color: var(--cm-primary); text-decoration: none; }
a:hover { color: var(--cm-primary-dark); }

/* ---------- Layout ---------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--header-height);
    transition: margin-left var(--cm-transition);
}

.page-content {
    padding: 24px;
    max-width: 1400px;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--cm-sidebar-bg);
    color: var(--cm-sidebar-text);
    z-index: 1040;
    overflow-y: auto;
    transition: transform var(--cm-transition);
}

.sidebar-brand {
    padding: 18px 20px;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand img {
    max-width: 100%;
    max-height: 45px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
}

.sidebar-brand .brand-subtitle {
    font-size: 0.7rem;
    font-weight: 400;
    color: #9ca3af;
    display: block;
    margin-top: 2px;
}

.sidebar-nav {
    list-style: none;
    padding: 12px 8px;
    margin: 0;
}

.sidebar-nav .nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6b7280;
    padding: 16px 12px 6px;
    font-weight: 600;
}

.sidebar-nav .nav-item {
    margin: 2px 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--cm-sidebar-text);
    border-radius: var(--cm-radius-sm);
    font-size: 0.875rem;
    transition: all var(--cm-transition);
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--cm-sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar-nav .nav-link .nav-icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
}

.sidebar-nav .nav-badge {
    margin-left: auto;
    background: var(--cm-danger);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
}

/* ---------- Top Header ---------- */
.top-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: var(--cm-surface);
    border-bottom: 1px solid var(--cm-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1050;
    transition: left var(--cm-transition);
}

.top-header .header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-header .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.top-header .header-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.btn-toggle-sidebar {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--cm-text);
    cursor: pointer;
    padding: 4px;
}

/* ---------- Summary Cards ---------- */
.summary-card {
    background: var(--cm-surface);
    border-radius: var(--cm-radius);
    padding: 20px;
    box-shadow: var(--cm-shadow);
    transition: transform var(--cm-transition), box-shadow var(--cm-transition);
    border: 1px solid var(--cm-border);
}

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--cm-shadow-lg);
}

.summary-card .card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 12px;
}

.summary-card .card-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.1;
}

.summary-card .card-label {
    font-size: 0.8rem;
    color: var(--cm-text-muted);
    margin-top: 4px;
}

/* ---------- Ticket Cards ---------- */
.ticket-card {
    background: var(--cm-surface);
    border-radius: var(--cm-radius);
    padding: 16px 20px;
    margin-bottom: 10px;
    box-shadow: var(--cm-shadow);
    border-left: 4px solid transparent;
    transition: all var(--cm-transition);
    cursor: pointer;
}

.ticket-card:hover {
    box-shadow: var(--cm-shadow-lg);
    transform: translateX(4px);
}

.ticket-card.sla-safe    { border-left-color: var(--cm-success); }
.ticket-card.sla-prepare { border-left-color: var(--cm-warning); }
.ticket-card.sla-warning { border-left-color: var(--cm-orange); }
.ticket-card.sla-critical { border-left-color: var(--cm-danger); }
.ticket-card.sla-overdue { border-left-color: var(--cm-danger); }
.ticket-card.sla-kpi_fail { border-left-color: #000; background: #fef2f2; }

.ticket-card .ticket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.ticket-card .ticket-number {
    font-size: 0.8rem;
    color: var(--cm-text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.ticket-card .ticket-timer {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    padding: 3px 10px;
    border-radius: 6px;
    min-width: 70px;
    text-align: center;
}

.ticket-card .ticket-subject {
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 6px;
    line-height: 1.3;
}

.ticket-card .ticket-meta {
    font-size: 0.78rem;
    color: var(--cm-text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.ticket-card .ticket-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

/* Timer Colors */
.timer-safe     { background: #dcfce7; color: #166534; }
.timer-prepare  { background: #fef3c7; color: #92400e; }
.timer-warning  { background: #fed7aa; color: #9a3412; }
.timer-critical { background: #fee2e2; color: #991b1b; }
.timer-overdue  { background: #fee2e2; color: #991b1b; animation: blink 0.8s infinite; }
.timer-kpi_fail { background: #1f2937; color: #ef4444; animation: blink 0.5s infinite; }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---------- SLA Section Headers ---------- */
.sla-section {
    margin-bottom: 20px;
}

.sla-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ---------- Complaint Cards ---------- */
.complaint-card {
    background: var(--cm-surface);
    border-radius: var(--cm-radius);
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: var(--cm-shadow);
    border: 1px solid var(--cm-border);
}

.complaint-card .nojar-badge {
    background: var(--cm-primary);
    color: #fff;
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-down  { background: #fee2e2; color: #991b1b; }
.status-up    { background: #dcfce7; color: #166534; }
.status-updown { background: #fef3c7; color: #92400e; }

/* ---------- Buttons ---------- */
.btn-cm {
    border-radius: var(--cm-radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 6px 14px;
    transition: all var(--cm-transition);
}

.btn-cm-primary {
    background: var(--cm-primary);
    color: #fff;
    border: none;
}

.btn-cm-primary:hover {
    background: var(--cm-primary-dark);
    color: #fff;
    transform: translateY(-1px);
}

.btn-cm-outline {
    background: transparent;
    border: 1px solid var(--cm-border);
    color: var(--cm-text);
}

.btn-cm-outline:hover {
    background: var(--cm-surface-hover);
    border-color: var(--cm-primary);
    color: var(--cm-primary);
}

.btn-cm-danger {
    background: var(--cm-danger);
    color: #fff;
    border: none;
}

.btn-cm-success {
    background: var(--cm-success);
    color: #fff;
    border: none;
}

.btn-cm-ai {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
}

.btn-cm-ai:hover {
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: #fff;
}

/* ---------- Search Bar ---------- */
.search-box {
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border-radius: var(--cm-radius);
    border: 1px solid var(--cm-border);
    background: var(--cm-surface);
    font-size: 0.875rem;
    transition: border-color var(--cm-transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--cm-primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

.search-box .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--cm-text-muted);
}

/* ---------- Mode Toggle ---------- */
.theme-toggle {
    background: none;
    border: 1px solid var(--cm-border);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all var(--cm-transition);
}

.theme-toggle:hover {
    background: var(--cm-surface-hover);
}

/* ---------- Extension Status Indicator ---------- */
.ext-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--cm-surface-hover);
    border: 1px solid var(--cm-border);
}

.ext-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
}

.ext-status.connected .dot {
    background: var(--cm-success);
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(5, 150, 105, 0); }
}

/* ---------- Modals ---------- */
.modal-content {
    border-radius: var(--cm-radius);
    border: none;
    box-shadow: var(--cm-shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--cm-border);
    padding: 16px 20px;
}

.modal-body {
    padding: 20px;
}

/* ---------- Login Page ---------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    padding: 20px;
}

.login-card {
    background: var(--cm-surface);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card .login-logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-card .login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--cm-primary);
    margin: 10px 0 4px;
}

.login-card .login-logo p {
    color: var(--cm-text-muted);
    font-size: 0.85rem;
}

.login-card .form-floating {
    margin-bottom: 16px;
}

.login-card .btn-login {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--cm-radius-sm);
    background: var(--cm-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: all var(--cm-transition);
}

.login-card .btn-login:hover {
    background: var(--cm-primary-dark);
    transform: translateY(-1px);
}

/* ---------- Responsive ---------- */
/* v1.2 — Mobile UI Complete Fix 2026-05-07 12:50 WIB */
@media (max-width: 768px) {
    /* Sidebar: hidden off-screen + NO pointer events when hidden */
    .sidebar {
        transform: translateX(-100%);
        z-index: 1060;
        pointer-events: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 25px rgba(0,0,0,0.4);
        pointer-events: auto;
    }

    /* Sidebar overlay backdrop — MUST NOT block clicks when hidden */
    .sidebar-overlay {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1055;
        display: none;
        pointer-events: none;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    .sidebar-overlay.show {
        display: block;
        pointer-events: auto;
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0 !important;
    }

    /* Header: full width */
    .top-header {
        left: 0 !important;
        padding: 0 12px;
        z-index: 1040 !important;
    }

    /* Hamburger menu button: MUST be visible */
    .btn-toggle-sidebar {
        display: block !important;
        position: relative;
        z-index: 1041;
        min-width: 44px;
        min-height: 44px;
        font-size: 1.5rem;
    }

    /* Fix header right items overflow */
    .top-header .header-right {
        gap: 6px;
    }
    .top-header .header-right .dropdown .btn,
    .top-header .header-right > .btn {
        font-size: 0.75rem;
        padding: 4px 8px;
    }
    .top-header .header-right .ext-status {
        font-size: 0.7rem;
    }

    .page-content {
        padding: 16px;
        width: 100%;
    }

    /* AI FAB button: mobile size */
    .ai-fab {
        bottom: 20px !important;
        right: 20px !important;
        width: 52px !important;
        height: 52px !important;
        font-size: 20px !important;
        z-index: 1030 !important;
    }

    /* AI Sidebar: full width on mobile */
    .ai-sidebar {
        width: 100% !important;
        right: -100% !important;
        z-index: 1060 !important;
    }
    .ai-sidebar.open {
        right: 0 !important;
    }

    /* Complaint detail: stack columns vertically */
    .row.g-4 > .col-lg-7,
    .row.g-4 > .col-lg-5 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Update form: stack inputs vertically */
    .summary-card .row.g-2 .col-md-6,
    .summary-card .row.g-2 .col-md-4,
    .summary-card .row.g-2 .col-md-3,
    .summary-card .row.g-2 .col-md-9 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .ticket-card .ticket-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .ticket-card .ticket-meta {
        flex-direction: column;
        gap: 4px;
    }

    .summary-card .card-value {
        font-size: 1.4rem;
    }

    /* Fix update category buttons wrap */
    .update-cat-btn {
        font-size: 0.75rem;
        padding: 4px 10px;
    }

    /* Fix modal content overflow */
    .modal-body {
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Fix d-flex gap spacing on mobile */
    .d-flex.gap-2 {
        gap: 6px;
    }

    /* Nojar badge text overflow */
    .nojar-badge {
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 576px) {
    .login-card {
        padding: 28px 20px;
    }

    .top-header .header-right .ext-status span {
        display: none; /* Hide text, keep dot on small screens */
    }
}

/* ---------- Utility ---------- */
.text-muted { color: var(--cm-text-muted) !important; }
.bg-orange { background-color: var(--cm-orange) !important; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* ---------- Mobile Responsive Tables & Layout Fixes ---------- */
@media (max-width: 768px) {
    /* Prevent any body scrolling left/right which causes "over" */
    body, .app-wrapper, .main-content, .page-content {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .sidebar-nav .nav-link {
        white-space: normal;
        word-wrap: break-word;
    }

    /* Transform Tables into Mobile Cards (Google Stitch / Modern Vibe) */
    .table-mobile-cards thead {
        display: none;
    }
    .table-mobile-cards, .table-mobile-cards tbody, .table-mobile-cards tr, .table-mobile-cards td {
        display: block;
        width: 100%;
    }
    .table-mobile-cards tr {
        background: var(--cm-surface);
        border-radius: var(--cm-radius);
        margin-bottom: 12px;
        box-shadow: var(--cm-shadow);
        border: 1px solid var(--cm-border);
        overflow: hidden;
    }
    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 14px !important;
        border-bottom: 1px dashed var(--cm-border) !important;
        font-size: 0.85rem;
        text-align: right;
    }
    .table-mobile-cards td:last-child {
        border-bottom: none !important;
    }
    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--cm-text-muted);
        text-transform: uppercase;
        font-size: 0.7rem;
        letter-spacing: 0.5px;
        margin-right: 15px;
        flex-shrink: 0;
        text-align: left;
    }
    
    /* Ensure action buttons wrap properly into the flex flow */
    .table-mobile-cards td > div.btn-group, 
    .table-mobile-cards td > a.btn {
        margin-left: auto;
    }

    /* Fix text overflow in detail cards */
    .summary-card, .complaint-card, .ticket-card {
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
    }
    
    /* Allow flex children to shrink below their content size */
    .d-flex > div, .row > div {
        min-width: 0;
    }
    
    /* Pre-formatted text overflow fix */
    pre, code {
        white-space: pre-wrap;
        word-wrap: break-word;
    }
}
