/* ============================================================
   styles.css — CM Response Operations
   Responsive: iPhone, iPad, Desktop
============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── Sidebar Nav Items ─────────────────────────────────── */
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
    user-select: none;
}

.nav-active {
    background: rgba(255,255,255,0.10);
    color: #ffffff;
    border-left-color: #0d9488;
}

.nav-inactive { color: #94a3b8; }
.nav-inactive:hover {
    background: rgba(255,255,255,0.06);
    color: #cbd5e1;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── Status Badges ──────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge-blue       { background: #dbeafe; color: #1d4ed8; }
.badge-green      { background: #d1fae5; color: #065f46; }
.badge-amber      { background: #fef3c7; color: #92400e; }
.badge-red        { background: #fee2e2; color: #991b1b; }
.badge-teal       { background: #ccfbf1; color: #115e59; }
.badge-purple     { background: #ede9fe; color: #5b21b6; }
.badge-slate      { background: #f1f5f9; color: #475569; }
.badge-indigo     { background: #e0e7ff; color: #3730a3; }
.badge-violet     { background: #ede9fe; color: #6d28d9; }

/* ── Tables ─────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead tr { border-bottom: 1px solid #e2e8f0; }

.data-table thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.data-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.1s ease;
}

.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody td { padding: 11px 14px; color: #334155; }
.data-table tbody tr:last-child { border-bottom: none; }

/* Scrollable table wrapper for narrow screens */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── KPI Cards ──────────────────────────────────────────── */
.kpi-card {
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    padding: 16px 18px;
    border-left-width: 4px;
    min-width: 0;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: #1e293b;
    line-height: 1;
    margin-bottom: 4px;
}

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Progress Bars ───────────────────────────────────────── */
.progress-bar {
    height: 6px;
    border-radius: 999px;
    background: #f1f5f9;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

/* ── Tabs ────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-btn {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    user-select: none;
    flex-shrink: 0;
}

.tab-btn:hover { color: #1e293b; }
.tab-btn.active {
    color: #0d9488;
    border-bottom-color: #0d9488;
    font-weight: 600;
}

/* ── Timeline ────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 20px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 7px; top: 8px; bottom: 0;
    width: 2px;
    background: #e2e8f0;
}
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot {
    position: absolute;
    left: -16px; top: 6px;
    width: 10px; height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #e2e8f0;
}

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    backdrop-filter: blur(2px);
}

.modal-box {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
}

/* ── Form Elements ───────────────────────────────────────── */
.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    color: #1e293b;
    background: #ffffff;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    /* Prevent iOS zoom on focus */
    font-size: max(16px, 13px);
}

.form-input:focus {
    outline: none;
    border-color: #0d9488;
    box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 5px;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
    background: #0d9488;
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover { background: #0f766e; }
.btn-primary:active { background: #115e59; }

.btn-outline {
    background: transparent;
    color: #475569;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #d1d5db;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn-outline:hover { border-color: #94a3b8; color: #1e293b; background: #f8fafc; }

.btn-danger {
    background: #dc2626;
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}
.btn-danger:hover { background: #b91c1c; }


/* ── Operations Card ───────────────────────────────────────────── */

.op-card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
    transition: box-shadow 0.15s;
}
.op-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.op-card.expanded .expand-content { display: block !important; }
.op-card.expanded [data-lucide="chevron-down"] { transform: rotate(180deg); }
.op-header { padding: 14px 16px; }
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
}
.pulse-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d97706;
    animation: pulse 1.4s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.5; transform: scale(1.25); }
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Utility ─────────────────────────────────────────────── */
.truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot-green  { background: #10b981; }
.status-dot-amber  { background: #f59e0b; }
.status-dot-red    { background: #ef4444; }
.status-dot-gray   { background: #94a3b8; }

.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    color: #ffffff; flex-shrink: 0;
}

/* ── Loading Spinner ─────────────────────────────────────── */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid #e2e8f0;
    border-top-color: #0d9488;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.2s ease forwards; }

/* ── Sidebar overlay (mobile) ────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
    backdrop-filter: blur(1px);
}
.sidebar-overlay.open { display: block; }

.ap-part-wrapper { position: relative; }
#ap_partdropdown { z-index: 99999; pointer-events: auto; }
.ap-part-row { cursor: pointer; pointer-events: auto; }


/* ══════════════════════════════════════════════════════════
   TABLET  (≤ 1024px)
══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {

    /* Sidebar slides in as a drawer */
    #sidebar {
        position: fixed;
        left: -224px;
        top: 0; bottom: 0;
        z-index: 45;
        transition: left 0.25s ease;
        width: 224px !important;
    }

    #sidebar.open { left: 0; }

    /* Hamburger button — visible on tablet/mobile */
    #hamburger { display: flex !important; }

    /* Main content takes full width */
    #appShell > div { width: 100%; }

    /* KPI grid: 3 columns on tablet */
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }

    /* Dashboard: stack panels vertically */
    .dashboard-panels { flex-direction: column !important; }
    .dashboard-ncr-panel { width: 100% !important; }

    /* Jobs: narrow the list panel */
    .jobs-list-panel { width: 260px !important; }

}

/* ══════════════════════════════════════════════════════════
   MOBILE  (≤ 640px)
══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* KPI grid: 2 columns on phone */
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .kpi-card { padding: 12px 14px; }

    /* Smaller main content padding */
    #mainContent { padding: 12px !important; }

    /* Top bar: compact */
    #topBarDate { display: none; }

    /* Dashboard panels: full column */
    .dashboard-panels { flex-direction: column !important; gap: 12px !important; }
    .dashboard-ncr-panel { width: 100% !important; }

    /* Jobs split panel: stack, only show one at a time */
    .jobs-container {
        position: relative;
        overflow: hidden;
    }

    .jobs-list-panel {
        width: 100% !important;
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        transition: transform 0.3s ease;
        z-index: 2;
    }

    .jobs-detail-panel {
        width: 100% !important;
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 3;
    }

    /* When a job is selected on mobile, slide detail into view */
    .jobs-container.detail-open .jobs-list-panel  { transform: translateX(-100%); }
    .jobs-container.detail-open .jobs-detail-panel { transform: translateX(0); }

    /* Mobile back button in detail */
    .mobile-back-btn { display: flex !important; }

    /* Make tables horizontally scrollable */
    .card > table, .table-scroll > table {
        min-width: 500px;
    }

    /* Hide less critical table columns on mobile */
    .hide-mobile { display: none !important; }

    /* Modal full screen on mobile */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal-box {
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        max-width: 100%;
    }

    /* Welcome greeting compact */
    .welcome-actions { flex-direction: column; align-items: flex-start !important; gap: 8px; }
}
