/* ============================================
   JSNRLandTrack - Design System
   Brand: JS Realty (Red #DC2626 + Light Theme)
   ============================================ */

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

/* --- CSS Custom Properties --- */
:root {
    --brand-red: #DC2626;
    --brand-red-dark: #991B1B;
    --brand-red-light: #FCA5A5;
    --brand-red-glow: rgba(220, 38, 38, 0.08);

    --bg-primary: #F3F4F6;
    --bg-secondary: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F9FAFB;
    --bg-sidebar: #FFFFFF;
    --bg-input: #F9FAFB;
    --bg-modal: rgba(0, 0, 0, 0.4);
    --bg-table-hover: rgba(0, 0, 0, 0.04);

    --text-primary: #111827;
    --text-secondary: #4B5563;
    --text-muted: #6B7280;
    --text-dark: #111827;

    --border-color: #E5E7EB;
    --border-light: #D1D5DB;

    --success: #059669;
    --success-bg: rgba(5, 150, 105, 0.08);
    --warning: #D97706;
    --warning-bg: rgba(217, 119, 6, 0.08);
    --danger: #DC2626;
    --danger-bg: rgba(220, 38, 38, 0.06);
    --info: #2563EB;
    --info-bg: rgba(37, 99, 235, 0.06);

    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 64px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.1);
    --shadow-glow: 0 0 20px var(--brand-red-glow);

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Dark Mode --- */
html.dark-mode {
    --bg-primary: #111827;
    --bg-secondary: #1F2937;
    --bg-card: #1F2937;
    --bg-card-hover: #374151;
    --bg-sidebar: #1F2937;
    --bg-input: #374151;
    --bg-modal: rgba(0, 0, 0, 0.7);
    --bg-topbar: rgba(31, 41, 55, 0.9);
    --bg-table-hover: rgba(255, 255, 255, 0.06);

    --text-primary: #F9FAFB;
    --text-secondary: #D1D5DB;
    --text-muted: #9CA3AF;
    --text-dark: #F9FAFB;

    --border-color: #374151;
    --border-light: #4B5563;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-red); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--brand-red-dark); }

img { max-width: 100%; display: block; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* --- Layout --- */
.app-wrapper { display: flex; min-height: 100vh; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    transition: margin-left var(--transition-slow);
    min-height: 100vh;
}

.main-content.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

.page-content { padding: 24px 28px; }

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-slow);
    overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    min-height: 64px;
}

.sidebar-logo {
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.sidebar-brand span {
    font-size: 0.7rem;
    color: var(--brand-red);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.sidebar.collapsed .sidebar-brand { display: none; }

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

.nav-section-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 12px 12px 6px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .nav-section-title { opacity: 0; height: 0; padding: 0; margin: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    margin-bottom: 2px;
    text-decoration: none;
    position: relative;
}

.nav-item:hover {
    background: rgba(0,0,0,0.04);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--brand-red-glow);
    color: var(--brand-red);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 60%;
    background: var(--brand-red);
    border-radius: 0 3px 3px 0;
}

.nav-item i, .nav-item svg { width: 20px; height: 20px; flex-shrink: 0; stroke-width: 1.8; }

.nav-item-label { overflow: hidden; }
.sidebar.collapsed .nav-item-label { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

/* --- Topbar --- */
.topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: var(--bg-topbar, rgba(255, 255, 255, 0.9));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 999;
    transition: left var(--transition-slow);
}

.topbar.sidebar-collapsed { left: var(--sidebar-collapsed); }

.topbar-left { display: flex; align-items: center; gap: 16px; }

.sidebar-toggle {
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: flex; align-items: center; justify-content: center;
}

.sidebar-toggle:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text-muted); }
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--brand-red); }
.breadcrumb .separator { color: var(--border-light); }
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 12px; border-radius: var(--radius-md);
    cursor: pointer; transition: background var(--transition-fast);
}
.topbar-user:hover { background: rgba(0,0,0,0.04); }

.topbar-user-info { text-align: right; }
.topbar-user-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.topbar-user-role {
    font-size: 0.7rem; color: var(--brand-red);
    text-transform: capitalize; font-weight: 500;
}

.topbar-avatar {
    width: 36px; height: 36px;
    border-radius: var(--radius-full);
    background: var(--brand-red);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem; color: #fff;
}

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

.page-title { font-size: 1.6rem; font-weight: 700; }
.page-subtitle { color: var(--text-secondary); font-size: 0.85rem; margin-top: 2px; }

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-normal);
}

.card:hover { border-color: var(--border-light); }

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border-color);
}

.card-title { font-size: 1rem; font-weight: 600; }

/* --- KPI Stat Cards --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex; align-items: flex-start; justify-content: space-between;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 3px;
    background: var(--stat-accent, var(--brand-red));
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-light); }

.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1.1; margin-bottom: 4px; }
.stat-label { font-size: 0.78rem; color: var(--text-secondary); font-weight: 500; }
.stat-change { font-size: 0.72rem; font-weight: 600; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg, .stat-icon i { width: 22px; height: 22px; }

.stat-icon.red { background: var(--brand-red-glow); color: var(--brand-red); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-icon.blue { background: var(--info-bg); color: var(--info); }
.stat-icon.danger { background: var(--danger-bg); color: var(--danger); }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}

.btn svg, .btn i { width: 16px; height: 16px; }

.btn-primary {
    background: var(--brand-red);
    color: #fff;
}
.btn-primary:hover { background: var(--brand-red-dark); box-shadow: var(--shadow-glow); color: #fff; }

.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--border-color); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--brand-red); color: var(--brand-red); }

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; }
.btn-icon { padding: 8px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Badges --- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-available { background: var(--success-bg); color: var(--success); }
.badge-reserved { background: var(--warning-bg); color: var(--warning); }
.badge-sold { background: var(--danger-bg); color: var(--danger); }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-completed { background: var(--info-bg); color: var(--info); }
.badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-admin { background: var(--brand-red-glow); color: var(--brand-red); }
.badge-agent { background: var(--info-bg); color: var(--info); }
.badge-cashier { background: var(--warning-bg); color: var(--warning); }
.badge-viewer { background: rgba(107,114,128,0.15); color: var(--text-muted); }

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 80px; right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    display: flex; align-items: center; gap: 10px;
    min-width: 300px; max-width: 440px;
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s ease-out;
    font-size: 0.85rem;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }

.toast-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; margin-left: auto; padding: 4px;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-modal);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal { transform: scale(1) translateY(0); }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title { font-size: 1.1rem; font-weight: 700; }

.modal-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.modal-close:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
}

.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.3; }
.empty-state h3 { font-size: 1rem; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state p { font-size: 0.85rem; }

/* --- Loading Spinner --- */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--brand-red);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex; align-items: center; justify-content: center;
    border-radius: inherit;
    z-index: 10;
}

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.animate-fade { animation: fadeIn 0.4s ease-out; }
.animate-slide { animation: slideUp 0.4s ease-out; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content, .main-content.sidebar-collapsed { margin-left: 0; }
    .topbar, .topbar.sidebar-collapsed { left: 0; }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
    .modal { width: 95%; }
}

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-secondary); }
.text-red { color: var(--brand-red); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.hidden { display: none !important; }
