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

:root {
    --bg-color: #F8FAFC;
    --surface: #FFFFFF;
    --primary: #0F172A;
    --primary-hover: #1E293B;
    --secondary: #334155;
    --secondary-hover: #475569;
    --text-primary: #0b1c30;
    --text-secondary: #45464d;
    --border-color: #E2E8F0;
    --success: #10B981;
    --success-bg: #D1FAE5;
    --danger: #EF4444;
    --danger-bg: #FEE2E2;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;

    --font-family: 'Inter', sans-serif;
    --radius: 4px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --shadow-md: 0px 4px 12px rgba(15, 23, 42, 0.08);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    width: 100%;
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

.sidebar {
    width: 240px;
    background-color: var(--surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    transition: transform 0.3s ease;
    z-index: 1000;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

.sidebar-header {
    padding: 20px;
    font-size: 20px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary);
}

.nav-links {
    list-style: none;
    padding: 20px 0;
}

.nav-links li a {
    display: block;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-links li a:hover, .nav-links li a.active {
    background-color: var(--bg-color);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
    width: calc(100% - 240px);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -0.02em;
}

/* Cards & Containers */
.card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: var(--font-family);
    font-size: 14px;
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 3px var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-family: var(--font-family);
}

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

.btn-secondary {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--primary);
}
.btn-secondary:hover { background-color: var(--bg-color); }

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

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

/* Tables */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #F1F5F9;
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    font-size: 13px;
    color: var(--text-primary);
}

tbody tr:hover {
    background-color: var(--bg-color);
}

.text-right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }

/* Chips */
.chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
}
.chip-success { background: var(--success-bg); color: #065F46; }
.chip-warning { background: var(--warning-bg); color: #92400E; }
.chip-danger { background: var(--danger-bg); color: #991B1B; }
.chip-neutral { background: #E2E8F0; color: #334155; }

/* Utility */
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

/* Grid */
.grid { display: grid; gap: 16px; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-split { grid-template-columns: 2fr 1fr; }

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--primary);
}

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; padding: 12px; }
    .mobile-toggle { display: block; }
    .grid-cols-2, .grid-cols-3, .grid-cols-4, .grid-split { grid-template-columns: 1fr !important; }
    .card { padding: 16px; }
    .page-title { font-size: 20px; }
    
    /* Mobile Tables to Cards */
    .table-responsive { overflow-x: hidden; border: none; }
    table, thead, tbody, th, td, tr { display: block; width: 100%; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    tr {
        margin-bottom: 16px;
        background: #fff;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        padding: 8px 0;
    }
    td {
        border: none;
        position: relative;
        padding: 8px 16px;
        padding-left: 45%;
        text-align: right !important;
        min-height: 40px;
    }
    td:before {
        content: attr(data-label);
        position: absolute;
        left: 16px;
        top: 8px;
        width: 40%;
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--secondary);
        font-size: 12px;
        text-transform: uppercase;
    }
    /* Fix Create Invoice form specific elements for mobile */
    .invoice-item-row { padding: 16px !important; }
    .invoice-item-row td { padding: 8px 0 !important; text-align: left !important; min-height: auto; }
    .invoice-item-row td:before { display: none; } /* Hide labels on invoice inputs, we'll use placeholder or they are self explanatory */
    .invoice-item-row select, .invoice-item-row input { margin-bottom: 8px; }
    .remove-row { width: 100%; margin-top: 8px; }
}
