/*
 * DSR — Daily Sales & Cash Management Modern Design System
 * Aesthetic, Ultra-Responsive, Dark/Light Theme with Glassmorphism & Micro-animations
 */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.08);
    --secondary: #64748b;
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.12);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.12);
    --info: #06b6d4;
    --info-light: rgba(6, 182, 212, 0.12);

    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-sidebar: #0f172a;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #ffffff;
    --sidebar-active-bg: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;
    --border-color: #e2e8f0;
    --border-subtle: #f1f5f9;

    --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
    --card-hover-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.08), 0 4px 10px -2px rgba(0, 0, 0, 0.03);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --sidebar-width: 270px;
    --topbar-height: 64px;
}

[data-theme="dark"] {
    --bg-body: #090d16;
    --bg-surface: #111827;
    --bg-surface-elevated: #1f2937;
    --bg-sidebar: #0b0f19;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-subtle: #6b7280;
    --border-color: #1f2937;
    --border-subtle: #111827;
    --card-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
    --card-hover-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.6);
}

/* Base resets & prevent mobile horizontal scroll */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    font-size: 0.925rem;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Typography & Numerics */
.font-mono {
    font-family: var(--font-mono);
}

.currency-symbol {
    font-family: var(--font-sans);
    font-weight: 600;
}

/* App Layout Wrapper */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    position: relative;
    overflow-x: hidden;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    color: #ffffff;
}

.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    flex-shrink: 0;
}

.brand-text h5 {
    font-weight: 800;
    font-size: 1.1rem;
    margin: 0;
    letter-spacing: -0.5px;
    color: #ffffff;
}

.brand-text span {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

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

.nav-section-title {
    font-size: 0.675rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    color: #64748b;
    padding: 12px 12px 6px;
}

.sidebar-nav .nav-item {
    margin-bottom: 2px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(3px);
}

.sidebar-nav .nav-link.active {
    color: var(--text-sidebar-active);
    background: var(--sidebar-active-bg);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
    font-weight: 600;
}

.sidebar-nav .nav-link.active i {
    color: #ffffff;
}

.sidebar-user {
    padding: 14px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.15);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    color: #ffffff;
    font-size: 0.825rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.7rem;
    color: #94a3b8;
}

/* Main Content Area */
.app-main {
    flex: 1 1 auto;
    width: calc(100% - var(--sidebar-width));
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0; /* Critical for flex child shrink */
    transition: margin-left 0.3s ease, width 0.3s ease;
}

/* Top Navigation Bar */
.app-topbar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 990;
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
    width: 100%;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.global-search-form {
    position: relative;
    width: 260px;
}

.global-search-form input {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 7px 14px 7px 34px;
    font-size: 0.825rem;
    width: 100%;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.global-search-form input:focus {
    background: var(--bg-surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    outline: none;
    width: 300px;
}

.global-search-form i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Page Container */
.page-container {
    padding: 24px;
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.5px;
    margin: 0;
    word-break: break-word;
}

.page-subtitle {
    font-size: 0.825rem;
    color: var(--text-muted);
    margin-top: 3px;
    margin-bottom: 0;
}

/* KPI / Metric Cards */
.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--card-shadow);
    position: relative;
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    height: 100%;
    min-width: 0;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-hover-shadow);
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.kpi-icon.primary { background: var(--primary-light); color: var(--primary); }
.kpi-icon.success { background: var(--success-light); color: var(--success); }
.kpi-icon.warning { background: var(--warning-light); color: var(--warning); }
.kpi-icon.danger  { background: var(--danger-light); color: var(--danger); }
.kpi-icon.info    { background: var(--info-light); color: var(--info); }

.kpi-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-main);
    margin-bottom: 2px;
    font-family: var(--font-mono);
    word-break: break-word;
}

.kpi-subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Glass & Surface Cards */
.card-custom {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    transition: all 0.2s ease;
}

.card-custom .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 0.925rem;
    color: var(--text-main);
    flex-wrap: wrap;
    gap: 8px;
}

.card-custom .card-body {
    padding: 18px;
    min-width: 0;
}

/* Modern Responsive Data Tables with Touch Horizontal Scroll */
.table-custom-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    position: relative;
}

.table-custom {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--text-main);
    min-width: 600px; /* Ensures readable columns when scrolling */
}

.table-custom th {
    background: var(--bg-body);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.725rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 14px;
    border-top: none;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table-custom td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: 0.85rem;
}

.table-custom tbody tr {
    transition: background-color 0.15s ease;
}

.table-custom tbody tr:hover {
    background-color: rgba(79, 70, 229, 0.03);
}

/* Status Badges */
.badge {
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 50px;
    font-size: 0.725rem;
    letter-spacing: 0.2px;
}

.badge-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-danger  { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge-info    { background: var(--info-light); color: var(--info); border: 1px solid rgba(6, 182, 212, 0.2); }
.badge-locked  { background: #334155; color: #f8fafc; border: 1px solid #475569; }

/* Form Controls */
.form-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.form-control, .form-select {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    padding: 8px 12px;
    font-size: 0.875rem;
    width: 100%;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    color: var(--text-main);
    outline: none;
}

/* Custom Buttons */
.btn-primary-custom {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 7px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary-custom:hover {
    background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
    transform: translateY(-1px);
}

.btn-secondary-custom {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-weight: 600;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-secondary-custom:hover {
    background: var(--border-color);
    color: var(--text-main);
}

/* Live Reconciliation Highlight Boxes */
.recon-summary-card {
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 12px;
}

.recon-summary-card.matched {
    background: var(--success-light);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.recon-summary-card.shortage {
    background: var(--danger-light);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.recon-summary-card.excess {
    background: var(--warning-light);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 58px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    z-index: 1040;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    gap: 2px;
    flex: 1;
    padding: 6px 0;
}

.mobile-nav-item i {
    font-size: 1.15rem;
}

.mobile-nav-item.active {
    color: var(--primary);
}

/* Overlay */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1045;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

#sidebarOverlay.show {
    display: block;
}

/* RESPONSIVE BREAKPOINTS (Mobile & Tablet) */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

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

    .app-main {
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
    }

    .app-topbar {
        padding: 0 14px;
        height: 58px;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .page-container {
        padding: 14px 12px;
        padding-bottom: 80px; /* Space for mobile bottom bar */
    }

    .global-search-form {
        display: none;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .page-header > div:last-child {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .page-title {
        font-size: 1.2rem;
    }

    .kpi-value {
        font-size: 1.25rem;
    }

    .card-custom .card-header {
        padding: 12px 14px;
    }

    .card-custom .card-body {
        padding: 14px;
    }
}

@media (max-width: 575.98px) {
    .page-container {
        padding: 10px 8px;
        padding-bottom: 75px;
    }

    .btn-primary-custom, .btn-secondary-custom {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .kpi-card {
        padding: 14px;
    }

    .kpi-icon {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
}

/* Print Specific Media Styles */
@media print {
    .app-sidebar, .app-topbar, .mobile-bottom-nav, .btn, .no-print, #sidebarOverlay {
        display: none !important;
    }

    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
    }

    .page-container {
        padding: 0 !important;
    }

    .card-custom {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
