/* CSS Variables - Color Palette and Design System */
:root {
    /* Main Backgrounds */
    --bg-main: #f4f6f9;
    --bg-sidebar: #1e293b;
    --bg-card: #ffffff;

    /* Text Colors */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;

    /* Accents */
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-red: #ef4444;

    /* Borders and Shadows */
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

/* Dark Mode Variables */
:root.dark {
    --bg-main: #0f172a;
    --bg-sidebar: #020617;
    --bg-card: #1e293b;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;

    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: 600;
}

/* Layout */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
}

.sidebar-header {
    padding: 24px;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-blue), #60a5fa);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

.nav-menu {
    list-style: none;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    border-right: 4px solid var(--accent-blue);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Topbar */
.topbar {
    height: 70px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    box-shadow: var(--shadow-sm);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--accent-blue);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Pages Section */
.page-container {
    padding: 32px;
    flex: 1;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-title {
    font-size: 1.8rem;
    color: var(--text-primary);
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 6px;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-secondary:hover {
    background-color: var(--bg-main);
    transform: translateY(-1px);
}

/* Invoice Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-paid { background: #dcfce7; color: #166534; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-voided { background: #f1f5f9; color: #64748b; text-decoration: line-through; }

/* Cards & Grid Layouts */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.metric-card {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid var(--border-color);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

.metric-title {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-value {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: var(--text-primary);
}

.metric-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    margin-top: 8px;
}

.trend-up {
    color: var(--accent-green);
}

.trend-down {
    color: var(--accent-red);
}

/* Table Styles for Invoices List */
.table-container {
    background-color: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 16px 24px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    color: var(--text-primary);
    font-size: 0.95rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #f8fafc;
}

/* Status Badges */
.badge {
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-block;
}

.badge-paid {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-pending {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-overdue {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-voided {
    background-color: #f1f5f9;
    color: #64748b;
    text-decoration: line-through;
}

.badge-draft {
    background-color: #e0e7ff;
    color: #3730a3;
}

.badge-accepted {
    background-color: #d1fae5;
    color: #065f46;
}

/* Glassmorphism utility */
.glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

:root.dark .glass {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Auth / Login Overlay */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.login-card {
    background: var(--bg-card);
    padding: 48px;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    width: 100%;
    max-width: 420px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.login-card h2 {
    margin-bottom: 24px;
    color: var(--text-primary);
    text-align: center;
}

.login-card input {
    width: 100%;
    padding: 12px;
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-body);
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-card button:hover {
    background: var(--accent-blue-hover);
}

/* Theme Toggle Button */
.theme-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

:root.dark .theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile Responsive */
.mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        top: 0;
        bottom: 0;
        z-index: 1000;
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-menu-btn {
        display: block;
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
        margin-right: 16px;
    }

    .topbar {
        padding: 0 16px;
    }

    .page-container {
        padding: 16px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }
}

/* Modal Overlay Base Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000 !important;
    justify-content: center;
    align-items: center;
}

/* Dark mode table hover fix */
:root.dark tr:hover td {
    background-color: rgba(255, 255, 255, 0.03);
}

:root.dark th {
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

/* Input focus state */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 1rem;
    font-weight: 500;
}

/* POS layout */
.pos-container {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 20px;
    height: calc(100vh - 140px);
    overflow: hidden;
}

.pos-catalog {
    overflow-y: auto;
    padding: 20px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.pos-ticket {
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Logout button in sidebar */
.btn-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: none;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 500;
    width: 100%;
    text-align: left;
    transition: all 0.2s;
    margin-top: auto;
}

.btn-logout:hover {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

/* ═══ SKELETON SCREENS ═══ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, #e2e8f0 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite ease-in-out;
    border-radius: 8px;
    min-height: 16px;
}

.skeleton-line {
    height: 14px;
    margin-bottom: 10px;
    border-radius: 4px;
}

.skeleton-line.short { width: 40%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.full { width: 100%; }

.skeleton-card {
    height: 120px;
    border-radius: 12px;
}

.skeleton-table-row {
    height: 48px;
    margin-bottom: 4px;
    border-radius: 6px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══ RESPONSIVE / MOBILE ═══ */
@media (max-width: 1024px) {
    .sidebar {
        width: 60px;
        overflow: hidden;
    }
    .sidebar .sidebar-header div:not(.logo-icon) { display: none; }
    .sidebar .nav-label { display: none; }
    .sidebar .nav-item {
        padding: 12px 0;
        justify-content: center;
    }
    .sidebar .nav-icon {
        font-size: 1.3rem;
        display: flex;
        justify-content: center;
        width: 100%;
    }
    .main-content { margin-left: 0; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 768px) {
    .sidebar { 
        position: fixed;
        z-index: 9000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar .nav-label { display: inline; }
    .sidebar .nav-item {
        padding: 12px 24px;
        justify-content: flex-start;
    }
    .sidebar .nav-icon {
        width: auto;
        font-size: 1.2rem;
    }
    .main-content { margin-left: 0 !important; }
    .metrics-grid { grid-template-columns: 1fr !important; }
    .page-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .topbar {
        padding: 12px 16px;
    }
    .pos-layout {
        grid-template-columns: 1fr !important;
    }
    table { font-size: 0.8rem; }
    th, td { padding: 8px 6px; }
    /* Mobile menu button */
    .mobile-menu-btn {
        display: flex;
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--accent-blue);
        color: white;
        border: none;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
        z-index: 8999;
        cursor: pointer;
    }
}

@media (min-width: 769px) {
    .mobile-menu-btn { display: none; }
    .sidebar-overlay { display: none !important; }
}

/* ═══ DARK MODE ═══ */
html.dark {
    --bg-main: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0c1222;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-sidebar: #cbd5e1;
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
}

html.dark .skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    background-size: 200% 100%;
}

html.dark .badge-paid { background: #166534; color: #dcfce7; }
html.dark .badge-pending { background: #854d0e; color: #fef9c3; }
html.dark .badge-overdue { background: #991b1b; color: #fee2e2; }
html.dark .badge-voided { background: #334155; color: #94a3b8; }

html.dark input, html.dark select, html.dark textarea {
    background: #0f172a !important;
    color: #f1f5f9 !important;
    border-color: #475569 !important;
}

html.dark .table-container table thead th {
    background: #1e293b;
    color: #94a3b8;
    border-color: #334155;
}

html.dark .table-container table tbody td {
    border-color: #1e293b;
}

html.dark .glass {
    background: #1e293b;
}

/* ═══ TOP NAVBAR STYLING ═══ */
.main-navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 70px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s, border-color 0.3s;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-left .company-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.navbar-toggle-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.navbar-toggle-btn:hover {
    background-color: var(--bg-main);
}

.navbar-center {
    display: flex;
    align-items: center;
}

.nav-links {
    display: flex;
    align-items: center;
    list-style: none;
    gap: 6px;
    margin: 0;
    padding: 0;
}

.nav-dropdown-trigger {
    position: relative;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    list-style: none;
}

.nav-link-item {
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    user-select: none;
    transition: color 0.2s;
}

.nav-link-item .arrow {
    font-size: 0.7rem;
    margin-left: 2px;
    opacity: 0.7;
    transition: transform 0.2s ease;
}

.nav-dropdown-trigger:hover {
    background-color: var(--bg-main);
}

.nav-dropdown-trigger:hover .nav-link-item {
    color: var(--text-primary);
}

.nav-dropdown-trigger:hover .arrow {
    transform: rotate(180deg);
}

.nav-dropdown-trigger.active {
    background-color: rgba(59, 130, 246, 0.08);
}

.nav-dropdown-trigger.active .nav-link-item {
    color: var(--accent-blue);
    font-weight: 600;
}

/* Dropdown Menu styling */
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    list-style: none;
    padding: 8px 0;
    min-width: 200px;
    z-index: 1010;
    margin-top: 6px;
    
    /* Smooth modern transition of opacity/transform */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

/* Bridge gap to maintain hover state while moving mouse down */
.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
    background: transparent;
}

.nav-dropdown-trigger:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    padding: 10px 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s, color 0.15s;
    list-style: none;
    border-radius: 6px;
    margin: 2px 8px;
}

.dropdown-item:hover {
    background-color: var(--bg-main);
    color: var(--text-primary);
}

.dropdown-item.active {
    background-color: rgba(59, 130, 246, 0.08);
    color: var(--accent-blue);
    font-weight: 600;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar-right .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar-right .user-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.navbar-right .avatar {
    width: 36px;
    height: 36px;
    background-color: var(--accent-blue);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.btn-navbar-logout {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.btn-navbar-logout:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--accent-red);
    transform: scale(1.05);
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive navbar center drawer for mobile screen sizes */
@media (max-width: 850px) {
    .navbar-toggle-btn {
        display: block;
    }

    .navbar-center {
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        background-color: var(--bg-card);
        border-bottom: 1px solid var(--border-color);
        box-shadow: var(--shadow-md);
        padding: 16px;
        display: none;
        flex-direction: column;
        align-items: stretch;
        z-index: 999;
        max-height: calc(100vh - 70px);
        overflow-y: auto;
    }

    .navbar-center.open {
        display: flex;
    }

    .nav-links {
        flex-direction: column;
        gap: 4px;
        width: 100%;
        align-items: stretch;
    }

    .nav-dropdown-trigger {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        padding: 6px 12px;
    }

    .nav-link-item {
        width: 100%;
        justify-content: space-between;
        padding: 8px 0;
    }

    .nav-dropdown-trigger:hover .arrow {
        transform: none;
    }

    .dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        border-left: 2px solid var(--border-color);
        margin-left: 12px;
        padding: 4px 0;
        width: calc(100% - 12px);
        display: block;
        margin-top: 0;
        animation: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        transition: none;
    }

    .dropdown-menu::before {
        display: none;
    }

    .dropdown-item {
        margin: 2px 0;
        padding: 8px 12px;
    }

    .navbar-right .user-name {
        display: none;
    }
}