/* ═══════════════════════════════════════
   DPDP Compliance Platform - Styles
   Mobile-First Responsive Design
   ═══════════════════════════════════════ */

:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #4f46e5;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --topbar-height: 56px;
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --bg-main: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --transition: all 0.25s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    margin: 0;
    min-height: 100vh;
    font-size: 0.9375rem;
    line-height: 1.5;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════
   SIDEBAR - Mobile First
   ═══════════════════════════════════════ */

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
    /* Mobile: hidden by default */
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

.sidebar.show { transform: translateX(0); }

/* Overlay when sidebar open on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1039;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

.sidebar-brand {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid #1e293b;
    flex-shrink: 0;
}
.sidebar-brand i { font-size: 1.4rem; color: var(--primary-light); }

.sidebar-nav { flex: 1; padding: 8px 10px; }

.nav-section {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #475569;
    padding: 14px 12px 4px;
    text-transform: uppercase;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    min-height: 44px; /* Touch target */
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
    margin-bottom: 1px;
}
.sidebar .nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.sidebar .nav-link.active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.sidebar .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar .nav-link .badge { font-size: 0.65rem; margin-left: auto; }

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid #1e293b;
    text-align: center;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════
   MAIN CONTENT - Mobile First
   ═══════════════════════════════════════ */

#main-content {
    margin-left: 0;
    min-height: 100vh;
    transition: margin-left 0.3s cubic-bezier(.4,0,.2,1);
}

/* ─── Top Navbar ─── */
.top-navbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    gap: 8px;
}
.sidebar-toggle {
    color: var(--text-secondary);
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-main); }

.user-dropdown {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.8125rem;
    padding: 6px;
    min-height: 44px;
}
.user-dropdown::after { color: var(--text-muted); }
.user-dropdown span { display: none; } /* Hide name on mobile */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

/* ─── Main Content Area ─── */
.main-content-area { padding: 16px 12px; }

.flash-messages { margin-bottom: 16px; }
.flash-messages .alert {
    border-radius: var(--radius-sm);
    border: none;
    box-shadow: var(--shadow-sm);
    font-size: 0.8125rem;
    padding: 12px 16px;
}

/* ═══════════════════════════════════════
   PAGE HEADERS
   ═══════════════════════════════════════ */

.page-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 12px;
}
.page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}
.page-header .subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
}
.page-header .actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

/* ═══════════════════════════════════════
   CARDS
   ═══════════════════════════════════════ */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    overflow: hidden;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 16px;
    font-weight: 600;
    font-size: 0.875rem;
}
.card-body { padding: 16px; }

/* ─── Stat Cards ─── */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    margin-bottom: 10px;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-card .stat-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }
.stat-card .stat-change { font-size: 0.6875rem; margin-top: 8px; line-height: 1.3; }

.stat-primary .stat-icon { background: #eef2ff; color: var(--primary); }
.stat-primary .stat-value { color: var(--primary); }
.stat-success .stat-icon { background: #ecfdf5; color: var(--success); }
.stat-success .stat-value { color: var(--success); }
.stat-warning .stat-icon { background: #fffbeb; color: var(--warning); }
.stat-warning .stat-value { color: var(--warning); }
.stat-danger .stat-icon { background: #fef2f2; color: var(--danger); }
.stat-danger .stat-value { color: var(--danger); }
.stat-info .stat-icon { background: #ecfeff; color: var(--info); }
.stat-info .stat-value { color: var(--info); }

/* ═══════════════════════════════════════
   TABLES - Fully Responsive
   ═══════════════════════════════════════ */

.table-container {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table-container .table-responsive { border-radius: var(--radius); }
.table-container .table { margin: 0; }

.table { font-size: 0.8125rem; }
.table th {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.6875rem;
    letter-spacing: 0.05em;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border-color);
    background: #f8fafc;
    white-space: nowrap;
}
.table td {
    padding: 10px 12px;
    vertical-align: middle;
    border-color: var(--border-color);
}
.table tbody tr { transition: background 0.15s ease; }
.table tbody tr:hover { background: #f8fafc; }

/* Make table rows more tappable */
.table td a { min-height: 32px; display: inline-flex; align-items: center; }

/* ═══════════════════════════════════════
   BADGES
   ═══════════════════════════════════════ */

.badge {
    font-weight: 600;
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
    padding: 4px 10px;
    border-radius: 50px;
    white-space: nowrap;
}
.badge-status { padding: 5px 12px; }

.badge-active, .badge-completed, .badge-compliant, .badge-approved { background: #ecfdf5; color: #065f46; }
.badge-pending, .badge-received, .badge-draft, .badge-pending_review { background: #fffbeb; color: #92400e; }
.badge-withdrawn, .badge-rejected, .badge-non_compliant, .badge-critical { background: #fef2f2; color: #991b1b; }
.badge-expired, .badge-archived, .badge-terminated { background: #f1f5f9; color: #475569; }
.badge-in_progress, .badge-investigating, .badge-in_review, .badge-acknowledged { background: #eff6ff; color: #1e40af; }
.badge-detected, .badge-contained { background: #fef3c7; color: #92400e; }
.badge-resolved, .badge-closed { background: #ecfdf5; color: #065f46; }

.badge-low { background: #ecfdf5; color: #065f46; }
.badge-medium { background: #fffbeb; color: #92400e; }
.badge-high { background: #fff7ed; color: #c2410c; }

.severity-low { color: var(--success); }
.severity-medium { color: var(--warning); }
.severity-high { color: #f97316; }
.severity-critical { color: var(--danger); }

/* ═══════════════════════════════════════
   FORMS - Touch Friendly
   ═══════════════════════════════════════ */

.form-label {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 6px;
}
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border-color);
    padding: 10px 14px;
    min-height: 44px; /* Touch target */
    font-size: 1rem; /* Prevent iOS zoom */
    transition: var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
textarea.form-control { min-height: 80px; }
.form-text { font-size: 0.75rem; color: var(--text-muted); }
.form-check { min-height: 44px; display: flex; align-items: center; }
.form-check-input {
    width: 20px;
    height: 20px;
    margin-top: 0;
    cursor: pointer;
}
.form-check-label { cursor: pointer; padding-left: 4px; }

/* ═══════════════════════════════════════
   BUTTONS - 44px minimum touch targets
   ═══════════════════════════════════════ */

.btn {
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #059669; border-color: #059669; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: #fff; }
.btn-outline-secondary { color: var(--text-secondary); border-color: var(--border-color); }
.btn-outline-danger { color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-sm {
    padding: 6px 14px;
    min-height: 36px;
    font-size: 0.8125rem;
}
.btn-icon { display: inline-flex; align-items: center; gap: 6px; }

/* Ensure table action buttons are tappable */
.table .btn-sm { min-height: 34px; min-width: 34px; }

/* ═══════════════════════════════════════
   FILTER BAR - Responsive
   ═══════════════════════════════════════ */

.filter-bar {
    display: flex;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-bar .form-control,
.filter-bar .form-select {
    min-height: 40px;
    font-size: 0.8125rem;
    flex: 1 1 100%; /* Full width on mobile */
}
.filter-bar .btn { flex-shrink: 0; }

/* ═══════════════════════════════════════
   DETAIL VIEW - Responsive Grid
   ═══════════════════════════════════════ */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr; /* Single column on mobile */
    gap: 12px;
}
.detail-item { padding: 10px 0; }
.detail-item .label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.detail-item .value { font-size: 0.9375rem; color: var(--text-primary); word-break: break-word; }

/* ═══════════════════════════════════════
   TIMELINE
   ═══════════════════════════════════════ */

.timeline { position: relative; padding-left: 24px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -21px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--card-bg);
}
.timeline-item .time { font-size: 0.75rem; color: var(--text-muted); }
.timeline-item .event { font-size: 0.8125rem; }

/* ═══════════════════════════════════════
   SLA TIMER
   ═══════════════════════════════════════ */

.sla-timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.8125rem;
    font-weight: 700;
    min-height: 36px;
}
.sla-timer.ok { background: #ecfdf5; color: #065f46; }
.sla-timer.warning { background: #fffbeb; color: #92400e; }
.sla-timer.danger { background: #fef2f2; color: #991b1b; animation: pulse 2s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ═══════════════════════════════════════
   CHARTS - Responsive
   ═══════════════════════════════════════ */

.chart-container {
    position: relative;
    padding: 12px;
    min-height: 200px;
    max-height: 50vh;
}

/* ═══════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════ */

.login-wrapper {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #312e81 100%);
    padding: 16px;
}
.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 440px;
    padding: 24px;
}
.login-card .brand {
    text-align: center;
    margin-bottom: 24px;
}
.login-card .brand i { font-size: 2.5rem; color: var(--primary); }
.login-card .brand h1 { font-size: 1.375rem; font-weight: 800; margin: 10px 0 4px; }
.login-card .brand p { color: var(--text-secondary); font-size: 0.8125rem; line-height: 1.4; }

/* ═══════════════════════════════════════
   EMPTY STATES
   ═══════════════════════════════════════ */

.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; color: var(--border-color); }
.empty-state h3 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 0.8125rem; max-width: 360px; margin: 0 auto; line-height: 1.5; }

/* ═══════════════════════════════════════
   NOTIFICATION BANNER
   ═══════════════════════════════════════ */

.notification-banner {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
}
.notification-banner i { font-size: 1.25rem; color: var(--danger); flex-shrink: 0; margin-top: 2px; }
.notification-banner .text { font-size: 0.8125rem; line-height: 1.5; }
.notification-banner .text strong { color: var(--danger); }

/* ═══════════════════════════════════════
   REPORT CARDS
   ═══════════════════════════════════════ */

.report-section { margin-bottom: 28px; }
.report-section h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.report-metric { text-align: center; padding: 16px 8px; }
.report-metric .number { font-size: 1.5rem; font-weight: 800; }
.report-metric .label {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* ═══════════════════════════════════════
   ERROR PAGE
   ═══════════════════════════════════════ */

.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
    padding: 24px;
}
.error-page .code { font-size: 4rem; font-weight: 900; color: var(--primary-light); line-height: 1; }
.error-page .message { font-size: 1rem; color: var(--text-secondary); margin-top: 8px; }

/* ═══════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ═══════════════════════════════════════
   UTILITY HELPERS
   ═══════════════════════════════════════ */

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.min-w-0 { min-width: 0; }
.gap-touch { gap: 8px; }

/* Action button group for table rows */
.action-btns { display: flex; gap: 4px; flex-wrap: nowrap; }

/* Mobile-friendly links in tables */
.table-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
}
.table-link:hover { color: var(--primary-dark); text-decoration: underline; }

/* ═══════════════════════════════════════
   RESPONSIVE: SM (≥576px)
   ═══════════════════════════════════════ */

@media (min-width: 576px) {
    .main-content-area { padding: 20px 16px; }
    .login-card { padding: 32px; }
    .login-card .brand i { font-size: 3rem; }
    .login-card .brand h1 { font-size: 1.5rem; }
    .stat-card { padding: 18px; }
    .stat-card .stat-value { font-size: 1.625rem; }
    .filter-bar .form-control,
    .filter-bar .form-select { flex: 0 1 auto; max-width: 200px; }
    .error-page .code { font-size: 5rem; }
    .page-header { flex-direction: row; align-items: center; justify-content: space-between; }
    .page-header .actions { width: auto; }
}

/* ═══════════════════════════════════════
   RESPONSIVE: MD (≥768px)
   ═══════════════════════════════════════ */

@media (min-width: 768px) {
    .main-content-area { padding: 24px 20px; }
    .top-navbar { padding: 0 20px; }
    .user-dropdown span { display: inline; } /* Show name */
    .detail-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .chart-container { min-height: 250px; }
    .card-header { padding: 16px 20px; }
    .card-body { padding: 20px; }
    .table { font-size: 0.8125rem; }
    .report-metric .number { font-size: 1.75rem; }
    .notification-banner { align-items: center; }
}

/* ═══════════════════════════════════════
   RESPONSIVE: LG (≥992px) - Sidebar visible
   ═══════════════════════════════════════ */

@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0); /* Always visible */
    }
    .sidebar-overlay { display: none !important; }
    #main-content { margin-left: var(--sidebar-width); }
    .main-content-area { padding: 24px; }
    .top-navbar { padding: 0 24px; }
    --topbar-height: 64px;
    .top-navbar { height: 64px; }
    .detail-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
    .chart-container { min-height: 280px; }
    .stat-card .stat-value { font-size: 1.75rem; }
    .stat-card .stat-icon { width: 48px; height: 48px; font-size: 1.25rem; }
    .stat-card { padding: 20px; }
    .page-header h1 { font-size: 1.5rem; }
}

/* ═══════════════════════════════════════
   RESPONSIVE: XL (≥1200px)
   ═══════════════════════════════════════ */

@media (min-width: 1200px) {
    .detail-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
    .report-metric .number { font-size: 2rem; }
    .error-page .code { font-size: 6rem; }
}

/* ═══════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════ */

@media print {
    .sidebar, .top-navbar, .sidebar-overlay, .btn, .filter-bar { display: none !important; }
    #main-content { margin-left: 0 !important; }
    .main-content-area { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    .stat-card:hover { transform: none !important; }
}
