/* ===================================================================
   NimbleNest — Modern UI Design System
   Layman-friendly, mobile-first, accessible
   =================================================================== */

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

:root {
    /* Colors */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #06b6d4;
    --info-light: #cffafe;

    /* Neutrals */
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --text-light: #9ca3af;

    /* Sidebar */
    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --sidebar-active: #4f46e5;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);

    /* Radii */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Sidebar width */
    --sidebar-w: 250px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========== LAYOUT ========== */
.app-wrapper { display: flex; min-height: 100vh; }
.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; transition: margin 0.3s; }
.app-content { padding: 1.5rem; flex: 1; max-width: 1400px; width: 100%; margin: 0 auto; }
.app-footer { padding: 1.25rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface); font-size: 0.85rem; color: var(--text-muted); }

/* ========== SIDEBAR ========== */
.app-sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    scrollbar-width: thin;
    scrollbar-color: #374151 transparent;
}
.app-sidebar::-webkit-scrollbar { width: 5px; }
.app-sidebar::-webkit-scrollbar-thumb { background: #374151; border-radius: 5px; }

.sidebar-brand {
    padding: 1.5rem 1.25rem 1.25rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid #1f2937;
}
.sidebar-brand-icon {
    width: 40px; height: 40px; border-radius: 10px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
}
.sidebar-brand .brand-name { font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; }
.sidebar-brand .brand-tag { font-size: 0.68rem; color: #94a3b8; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; }

.sidebar-user {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid #1f2937;
}
.sidebar-user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 0.9rem;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info .name { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info .role { font-size: 0.72rem; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.05em; }

.sidebar-nav { padding: 0.75rem 0 4rem; }
.sidebar-nav ul { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li a {
    display: flex;
    align-items: center;
    padding: 0.65rem 1.25rem;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s;
    gap: 0.85rem;
}
.sidebar-nav li a:hover {
    background: var(--sidebar-hover);
    color: #fff;
}
.sidebar-nav li a.active {
    background: rgba(79, 70, 229, 0.15);
    color: #fff;
    border-left-color: var(--primary);
    font-weight: 600;
}
.sidebar-nav li a i { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-nav .nav-header {
    padding: 1.25rem 1.25rem 0.35rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    font-weight: 700;
}
.sidebar-nav .nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 0.68rem;
    padding: 2px 7px;
    border-radius: 20px;
    font-weight: 700;
}

/* ========== TOPBAR ========== */
.app-topbar {
    background: var(--surface);
    padding: 0.85rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}
.topbar-title { font-size: 1.15rem; font-weight: 700; color: var(--text); margin: 0; }
.topbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
}
.topbar-search input {
    width: 100%;
    padding: 0.55rem 0.9rem 0.55rem 2.35rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.topbar-search input:focus {
    outline: 0;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
    background: #fff;
}
.topbar-search i {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.95rem;
}
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 10px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg); color: var(--text); border: 0;
    font-size: 1.05rem; transition: all 0.15s;
    position: relative; text-decoration: none;
}
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn .dot {
    position: absolute; top: 8px; right: 8px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--danger); border: 2px solid #fff;
}

/* ========== CARDS ========== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1.15rem 1.35rem;
    font-weight: 600;
    font-size: 0.95rem;
}
.card-body { padding: 1.35rem; }

/* ========== STAT CARDS ========== */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; color: #fff;
    margin-bottom: 0.85rem;
    box-shadow: var(--shadow);
}
.stat-card .stat-icon.bg-primary { background: linear-gradient(135deg, #4f46e5, #6366f1); }
.stat-card .stat-icon.bg-success { background: linear-gradient(135deg, #10b981, #059669); }
.stat-card .stat-icon.bg-warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-card .stat-icon.bg-danger  { background: linear-gradient(135deg, #ef4444, #dc2626); }
.stat-card .stat-icon.bg-info    { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.8rem; font-weight: 500; margin-bottom: 0.25rem; }
.stat-card .stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; color: var(--text); line-height: 1.15; }
.stat-card .stat-change { font-size: 0.8rem; margin-top: 0.4rem; }

/* ========== QUICK ACTION TILES (Dashboard) ========== */
.quick-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.quick-action {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1rem;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: all 0.2s;
    cursor: pointer;
    display: block;
}
.quick-action:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    color: var(--primary);
}
.quick-action-icon {
    width: 56px; height: 56px; border-radius: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.5rem; margin-bottom: 0.75rem;
}
.quick-action:nth-child(6n+1) .quick-action-icon { background: var(--primary-light); color: var(--primary); }
.quick-action:nth-child(6n+2) .quick-action-icon { background: var(--success-light); color: var(--success); }
.quick-action:nth-child(6n+3) .quick-action-icon { background: var(--warning-light); color: var(--warning); }
.quick-action:nth-child(6n+4) .quick-action-icon { background: var(--info-light); color: var(--info); }
.quick-action:nth-child(6n+5) .quick-action-icon { background: #fce7f3; color: #db2777; }
.quick-action:nth-child(6n+6) .quick-action-icon { background: #ede9fe; color: #7c3aed; }
.quick-action-label { font-weight: 600; font-size: 0.88rem; }

/* ========== BUTTONS ========== */
.btn { font-weight: 500; border-radius: 8px; padding: 0.5rem 1rem; transition: all 0.15s; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-primary {
    background: var(--primary); border-color: var(--primary);
    box-shadow: 0 1px 3px rgba(79, 70, 229, 0.2);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 8px rgba(79, 70, 229, 0.25); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #059669; border-color: #059669; }

/* ========== TABLES ========== */
.table { color: var(--text); margin-bottom: 0; }
.table thead { background: var(--bg); }
.table thead th { font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--border); }
.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: var(--primary-light); }
.table td { padding: 0.85rem 1.1rem; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 0.88rem; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-sm td, .table-sm th { padding: 0.55rem 0.85rem; }

/* ========== BADGES ========== */
.badge {
    padding: 0.35em 0.7em;
    font-weight: 600;
    font-size: 0.72rem;
    border-radius: 6px;
    letter-spacing: 0.02em;
}
.bg-primary-soft { background: var(--primary-light) !important; color: var(--primary) !important; }
.bg-success-soft { background: var(--success-light) !important; color: #047857 !important; }
.bg-warning-soft { background: var(--warning-light) !important; color: #92400e !important; }
.bg-danger-soft { background: var(--danger-light) !important; color: #991b1b !important; }
.bg-info-soft { background: var(--info-light) !important; color: #155e75 !important; }

/* ========== FORMS ========== */
.form-control, .form-select {
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    transition: all 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.form-label { font-weight: 500; color: var(--text); margin-bottom: 0.3rem; font-size: 0.82rem; }

/* ========== LOGIN PAGE ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #ec4899 100%);
    padding: 2rem 1rem;
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%;
    width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 1px, transparent 1px) 0 0 / 40px 40px;
    animation: float 30s linear infinite;
    pointer-events: none;
}
@keyframes float {
    from { transform: translate(0, 0); }
    to { transform: translate(-40px, -40px); }
}
.login-card {
    background: #fff;
    padding: 2.5rem;
    border-radius: 20px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.25);
    position: relative;
    z-index: 1;
}
.login-logo {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 2rem;
    margin: 0 auto 1.25rem;
    box-shadow: 0 10px 25px rgba(79, 70, 229, 0.3);
}

/* ========== MOBILE BOTTOM NAV ========== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.5rem 0.25rem env(safe-area-inset-bottom);
    z-index: 900;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
}
.mobile-bottom-nav .nav-items { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.mobile-bottom-nav a {
    text-decoration: none;
    padding: 0.5rem 0.25rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 10px;
    transition: all 0.15s;
}
.mobile-bottom-nav a i { display: block; font-size: 1.25rem; margin-bottom: 2px; }
.mobile-bottom-nav a.active { color: var(--primary); background: var(--primary-light); }
.mobile-bottom-nav a.primary-action {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff !important;
    margin: -14px 0.25rem 0;
    padding: 0.65rem 0.25rem;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
.mobile-bottom-nav a.primary-action i { font-size: 1.4rem; }

/* ========== EMPTY STATES ========== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}
.empty-state-icon {
    width: 80px; height: 80px;
    border-radius: 24px;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 2rem;
    margin-bottom: 1rem;
}
.empty-state h3 { color: var(--text); font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; }
.empty-state p { font-size: 0.9rem; margin-bottom: 1.5rem; max-width: 360px; margin-left: auto; margin-right: auto; }

/* ========== POS / INVOICE ========== */
.invoice-print { background: #fff; padding: 2rem; max-width: 900px; margin: 0 auto; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.invoice-header { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 1rem; margin-bottom: 1rem; }
.invoice-table { width: 100%; border-collapse: collapse; }
.invoice-table th, .invoice-table td { padding: 0.5rem; border: 1px solid #000; }
.invoice-table th { background: #f1f5f9; text-align: left; }

/* ========== BARCODE INPUT ========== */
.barcode-input {
    font-size: 1.1rem;
    padding: 0.75rem 1rem;
    letter-spacing: 0.05em;
    font-family: 'SF Mono', ui-monospace, Menlo, monospace;
    border: 2px solid var(--primary);
    background: #fafbff;
}
.barcode-input:focus { background: #fff; }

/* ========== PAGE HEADERS ========== */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.page-header .page-sub { color: var(--text-muted); font-size: 0.88rem; margin-top: 0.25rem; }
.page-header .actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ========== RESPONSIVE ========== */
@media (max-width: 992px) {
    :root { --sidebar-w: 220px; }
    .app-content { padding: 1rem; }
}
@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: 20px 0 50px rgba(0,0,0,0.3); }
    .app-sidebar.show { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem; padding-bottom: 80px; }
    .mobile-bottom-nav { display: block; }
    .topbar-search { display: none; }
    .topbar-title { font-size: 1rem; }
    .stat-card .stat-value { font-size: 1.4rem; }
    .page-header h1 { font-size: 1.2rem; }
}

/* ========== SIDEBAR OVERLAY (Mobile) ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* ========== PRINT ========== */
@media print {
    .app-sidebar, .app-topbar, .app-footer, .mobile-bottom-nav, .no-print, .sidebar-overlay { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }
    body { background: #fff; }
    .invoice-print { box-shadow: none; border: none; }
}

/* ========== UTILITIES ========== */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }

/* Alerts */
.alert { border-radius: var(--radius); border: 0; padding: 0.85rem 1.15rem; font-size: 0.88rem; }
.alert-success { background: var(--success-light); color: #065f46; }
.alert-warning { background: var(--warning-light); color: #92400e; }
.alert-danger { background: var(--danger-light); color: #991b1b; }
.alert-info { background: var(--info-light); color: #155e75; }

/* POS wrapper (kept for create_invoice compatibility) */
.pos-wrapper { display: grid; grid-template-columns: 1fr 400px; gap: 1rem; height: calc(100vh - 130px); }
.pos-products { background: #fff; border-radius: var(--radius); padding: 1rem; overflow-y: auto; }
.pos-cart { background: #fff; border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; }
