/* ═══════════════════════════════════════════════════════════
   DMS Operations Dashboard — Design System
   Native Application Look & Feel
   ═══════════════════════════════════════════════════════════ */

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

/* ── CSS Variables ── */
:root {
    /* Sidebar */
    --sidebar-w: 248px;
    --sidebar-collapsed-w: 68px;
    --sidebar-bg: #0B1120;
    --sidebar-border: #1a2540;
    --sidebar-text: #8896b3;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(59,130,246,0.12);
    --sidebar-active-text: #60a5fa;
    --sidebar-active-indicator: #3b82f6;

    /* Top Bar */
    --topbar-h: 56px;
    --topbar-bg: #ffffff;
    --topbar-border: #e5e7eb;

    /* Content */
    --content-bg: #f0f2f5;
    --card-bg: #ffffff;
    --card-border: #e5e7eb;
    --card-radius: 10px;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);

    /* Typography */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-muted: #d1d5db;

    /* Accent Colors */
    --blue: #3b82f6;
    --blue-light: #eff6ff;
    --blue-dark: #1d4ed8;
    --green: #10b981;
    --green-light: #ecfdf5;
    --amber: #f59e0b;
    --amber-light: #fffbeb;
    --red: #ef4444;
    --red-light: #fef2f2;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;
    --cyan: #06b6d4;
    --cyan-light: #ecfeff;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
}

/* ── Global Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 13.5px;
    color: var(--text-primary);
    background: var(--content-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    height: 100vh;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ═══════════ SIDEBAR ═══════════ */
.app-sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
    overflow: hidden;
}
.app-sidebar.collapsed { width: var(--sidebar-collapsed-w); }

/* Sidebar Brand */
.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 12px;
    flex-shrink: 0;
}
.sidebar-brand-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-brand-icon i { color: #fff; font-size: 16px; }
.sidebar-brand-text {
    font-weight: 800;
    font-size: 15px;
    color: #ffffff;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
}
.collapsed .sidebar-brand-text { opacity: 0; width: 0; }

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 10px;
}
.sidebar-nav-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #4b5a75;
    padding: 16px 10px 6px;
    white-space: nowrap;
    overflow: hidden;
}
.collapsed .sidebar-nav-label { text-align: center; font-size: 0; padding: 12px 0 4px; }
.collapsed .sidebar-nav-label::after { content: '•••'; font-size: 8px; letter-spacing: 2px; display: block; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    white-space: nowrap;
    transition: all 0.15s ease;
    position: relative;
    margin-bottom: 2px;
}
.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: var(--sidebar-text-hover);
}
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: -10px; top: 6px; bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sidebar-active-indicator);
}
.sidebar-link i {
    font-size: 17px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-link span {
    overflow: hidden;
    white-space: nowrap;
}
.collapsed .sidebar-link span { opacity: 0; width: 0; }
.collapsed .sidebar-link { justify-content: center; padding: 10px; }
.collapsed .sidebar-link.active::before { left: -10px; }

/* Sidebar Badge */
.sidebar-badge {
    font-size: 10px;
    font-weight: 700;
    background: var(--blue);
    color: #fff;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: auto;
}
.collapsed .sidebar-badge { display: none; }

/* Sidebar Footer / User */
.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.sidebar-avatar {
    width: 34px; height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}
.sidebar-user-info { overflow: hidden; white-space: nowrap; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e5e7eb; }
.sidebar-user-role { font-size: 11px; color: #6b7280; }
.collapsed .sidebar-user-info { opacity: 0; width: 0; }

/* Collapse Toggle */
.sidebar-toggle {
    position: absolute;
    top: 16px;
    right: -13px;
    width: 26px; height: 26px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1060;
    color: var(--sidebar-text);
    transition: all 0.2s;
}
.sidebar-toggle:hover { background: #1a2540; color: #fff; }
.collapsed .sidebar-toggle { right: -13px; }

/* ═══════════ MAIN CONTENT AREA ═══════════ */
.app-main {
    margin-left: var(--sidebar-w);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.25s cubic-bezier(0.4,0,0.2,1);
    overflow: hidden;
}
.sidebar-collapsed .app-main { margin-left: var(--sidebar-collapsed-w); }

/* Top Bar */
.app-topbar {
    height: var(--topbar-h);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    z-index: 100;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.topbar-page-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}
.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.topbar-breadcrumb i { font-size: 10px; color: var(--text-tertiary); }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Page Scrollable Content */
.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
}

/* ═══════════ CARDS ═══════════ */
.ds-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
}
.ds-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ds-card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.1px;
}
.ds-card-body { padding: 20px; }

/* ═══════════ STAT CARDS ═══════════ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.ds-stat {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    padding: 18px 20px;
    box-shadow: var(--card-shadow);
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
}
.ds-stat:hover { border-color: var(--blue); box-shadow: 0 2px 8px rgba(59,130,246,0.08); }
.ds-stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.ds-stat-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.5px;
}
.ds-stat-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 32px;
    opacity: 0.08;
}
.ds-stat.accent-blue { border-left: 3px solid var(--blue); }
.ds-stat.accent-blue .ds-stat-value { color: var(--blue); }
.ds-stat.accent-green { border-left: 3px solid var(--green); }
.ds-stat.accent-green .ds-stat-value { color: var(--green); }
.ds-stat.accent-amber { border-left: 3px solid var(--amber); }
.ds-stat.accent-amber .ds-stat-value { color: var(--amber); }
.ds-stat.accent-red { border-left: 3px solid var(--red); }
.ds-stat.accent-red .ds-stat-value { color: var(--red); }
.ds-stat.accent-purple { border-left: 3px solid var(--purple); }
.ds-stat.accent-purple .ds-stat-value { color: var(--purple); }
.ds-stat.accent-cyan { border-left: 3px solid var(--cyan); }
.ds-stat.accent-cyan .ds-stat-value { color: var(--cyan); }

/* ═══════════ TABLES ═══════════ */
.ds-table-wrap {
    border-radius: var(--card-radius);
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}
.ds-table-wrap .table { margin-bottom: 0; font-size: 13px; }
.ds-table-wrap .table thead th {
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 10px 14px;
    white-space: nowrap;
}
.ds-table-wrap .table tbody td {
    padding: 9px 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.ds-table-wrap .table tbody tr:hover { background: #f9fafb; }
.ds-table-wrap .table tbody tr:last-child td { border-bottom: none; }

/* DataTables overrides */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--card-border) !important;
    border-radius: 6px !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
    outline: none !important;
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--blue) !important;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1) !important;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--card-border) !important;
    border-radius: 6px !important;
    padding: 4px 8px !important;
    font-size: 13px !important;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length { font-size: 12px; color: var(--text-secondary); }
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 6px !important;
    font-size: 12px !important;
}

/* ═══════════ STATUS BADGES ═══════════ */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    letter-spacing: 0.1px;
}
.status-pending   { background: #fef3c7; color: #92400e; }
.status-assigned  { background: #d1fae5; color: #065f46; }
.status-out       { background: #dbeafe; color: #1e40af; }
.status-delivered { background: #f3f4f6; color: #374151; }
.status-cancelled { background: #fee2e2; color: #991b1b; }

/* ═══════════ BUTTONS ═══════════ */
.ds-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.ds-btn:hover { transform: translateY(-1px); }
.ds-btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.ds-btn-primary:hover { background: var(--blue-dark); color: #fff; }
.ds-btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.ds-btn-success:hover { background: #059669; color: #fff; }
.ds-btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.ds-btn-danger:hover { background: #dc2626; color: #fff; }
.ds-btn-warning { background: var(--amber); color: #fff; border-color: var(--amber); }
.ds-btn-warning:hover { background: #d97706; color: #fff; }
.ds-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--card-border);
}
.ds-btn-ghost:hover { background: #f9fafb; color: var(--text-primary); }
.ds-btn-sm { font-size: 12px; padding: 5px 12px; }
.ds-btn-xs { font-size: 11px; padding: 3px 8px; border-radius: 5px; }

/* ═══════════ FORM CONTROLS ═══════════ */
.ds-form-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}
.ds-input,
.ds-select {
    font-family: var(--font);
    font-size: 13px;
    padding: 7px 12px;
    border: 1px solid var(--card-border);
    border-radius: 7px;
    background: #fff;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
.ds-input:focus,
.ds-select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
    outline: none;
}

/* ═══════════ INLINE EDITING ═══════════ */
.cell-editable {
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}
.cell-editable:hover { background: var(--blue-light) !important; }
.cell-editable:hover .edit-hint { opacity: 1; }
.edit-hint {
    opacity: 0;
    font-size: 9px;
    color: var(--blue);
    transition: 0.15s;
    position: absolute;
    top: 3px; right: 5px;
}
.inline-select {
    font-family: var(--font);
    font-size: 12px;
    border: 2px solid var(--blue);
    border-radius: 6px;
    padding: 3px 6px;
    background: #fff;
    width: 100%;
    outline: none;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
td.saving { opacity: 0.4; pointer-events: none; }
.saved-flash { animation: flashSuccess 0.8s ease; }
@keyframes flashSuccess { 0% { background: #d1fae5; } 100% { background: transparent; } }

/* ═══════════ TOAST NOTIFICATIONS ═══════════ */
.ds-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    min-width: 300px;
    padding: 14px 20px;
    border-radius: 10px;
    background: #fff;
    border: 1px solid var(--card-border);
    box-shadow: 0 10px 40px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    animation: toastSlide 0.3s ease;
    transition: opacity 0.3s;
}
@keyframes toastSlide { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.ds-toast.success { border-left: 4px solid var(--green); }
.ds-toast.error { border-left: 4px solid var(--red); }

/* ═══════════ TRUNCATION ═══════════ */
.truncate-debtor {
    max-width: 175px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    font-weight: 600;
}

/* ═══════════ UPLOAD AREA ═══════════ */
.upload-zone {
    border: 2px dashed #d1d5db;
    border-radius: 10px;
    padding: 24px;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--blue);
    background: var(--blue-light);
}

/* ═══════════ RESOURCE ITEMS (Settings) ═══════════ */
.resource-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-bottom: 1px solid #f3f4f6;
    font-size: 13px;
    transition: background 0.1s;
}
.resource-item:hover { background: #f9fafb; }
.resource-item:last-child { border-bottom: none; }

/* ═══════════ ALERT / FILE INFO ═══════════ */
#file-info {
    display: none;
    background: var(--blue-light);
    color: var(--blue-dark);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #bfdbfe;
    font-size: 12px;
}

/* ═══════════ PRINT ═══════════ */
@media print {
    .app-sidebar, .sidebar-toggle, .app-topbar, .no-print { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; overflow: visible !important; }
    body { overflow: visible; height: auto; }
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
    .app-sidebar.mobile-open { transform: translateX(0); }
    .app-main { margin-left: 0 !important; }
    .sidebar-toggle { display: none; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════ MOBILE OPTIMIZATIONS ═══════════ */
@media (max-width: 768px) {
    /* Hide Sidebar and Toggle Button completely */
    .app-sidebar, 
    .sidebar-toggle {
        display: none !important;
    }

    /* Remove margin from main content */
    .app-main {
        margin-left: 0 !important;
    }
    body.sidebar-collapsed .app-main {
        margin-left: 0 !important;
    }

    /* Reduce content padding for more screen space */
    .app-content {
        padding: 12px !important;
    }

    /* Adjust Topbar padding */
    .app-topbar {
        padding: 0 16px !important;
    }

    /* Show the Home Button on Mobile */
    .topbar-home-btn {
        display: flex !important;
    }
}

/* Base style for the Home Button (Hidden on Desktop) */
.topbar-home-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--blue-light);
    color: var(--blue);
    border-radius: 8px;
    text-decoration: none;
    font-size: 18px;
    transition: background 0.2s;
}
.topbar-home-btn:hover {
    background: var(--blue);
    color: #fff;
}