:root {
    /* Colors */
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    
    /* Light Mode */
    --bg-main: #F9F9FB;
    --bg-sidebar: #FFFFFF;
    --bg-card: #FFFFFF;
    --text-main: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --sidebar-active: #EFF6FF;
    --sidebar-text-active: #3B82F6;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.dark-mode {
    --bg-main: #0F172A;
    --bg-sidebar: #1E293B;
    --bg-card: #1E293B;
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --border: #334155;
    --sidebar-active: #334155;
    --sidebar-text-active: #3B82F6;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

h1, h2, h3, h4, .logo {
    font-family: 'Outfit', sans-serif;
}

.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

.view {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--sidebar-active);
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }

.btn-icon {
    padding: 0.5rem;
    background: transparent;
    color: var(--text-muted);
}

.btn-icon:hover { color: var(--text-main); }

.hidden { display: none !important; }

/* Auth Screen */
#auth-screen {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-main);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.auth-card {
    background: var(--bg-sidebar);
    padding: 2.5rem;
    border-radius: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 1.75rem;
    margin: 1rem 0 0.5rem;
}

.auth-header p {
    color: var(--text-muted);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

input, textarea, select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: inherit;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

.password-wrapper {
    position: relative;
}

.icon-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 1rem;
    text-align: center;
}

/* Main Layout */
#main-content {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    z-index: 10;
}

.sidebar-header {
    margin-bottom: 2rem;
}

.nav-menu {
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.nav-item:hover, .nav-item.active {
    background-color: var(--sidebar-active);
    color: var(--sidebar-text-active);
}

.nav-item.text-danger:hover {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

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

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    text-align: right;
}

.user-name {
    display: block;
    font-weight: 600;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* Dashboard View */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background-color: var(--bg-card);
    padding: 1.5rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon i { width: 24px; height: 24px; }

.bg-blue { background-color: rgba(59, 130, 246, 0.1); color: var(--primary); }
.bg-green { background-color: rgba(16, 185, 129, 0.1); color: var(--success); }
.bg-purple { background-color: rgba(168, 85, 247, 0.1); color: #A855F7; }

.stat-label { font-size: 0.875rem; color: var(--text-muted); }
.stat-info h3 { font-size: 1.5rem; margin-top: 0.25rem; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

/* Tables */
.table-container {
    background-color: var(--bg-card);
    border-radius: 1rem;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

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

.invoice-table th, .invoice-table td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.invoice-table th {
    background-color: var(--bg-main);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-Draft { background-color: rgba(107, 114, 128, 0.1); color: #6B7280; }
.status-Sent { background-color: rgba(59, 130, 246, 0.1); color: #3B82F6; }
.status-Paid { background-color: rgba(16, 185, 129, 0.1); color: #10B981; }

.action-btns { display: flex; gap: 0.5rem; }

/* Form View */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.form-section {
    padding: 1.5rem;
}

.form-section h4 { margin-bottom: 1.25rem; color: var(--text-muted); font-size: 0.875rem; text-transform: uppercase; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal-content {
    background-color: white; /* Invoice always white background */
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    border-radius: 1rem;
    overflow-y: auto;
    color: #1F2937;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #F9F9FB;
}

/* Invoice Template Styles - Saldo Theme */
#invoice-template-container {
    padding: 0;
    background: white;
}

.invoice-preview-card {
    color: #1a1a1a;
    padding: 3rem;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

/* Plum Theme Styles */
.invoice-plum-container {
    color: #333;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.plum-header {
    background-color: #511845; /* Deep Plum */
    padding: 3rem;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.plum-brand {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.plum-logo-box img {
    height: 60px;
    mix-blend-mode: screen; /* Makes black background transparent if it exists */
}

.plum-brand-info h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.plum-brand-info p {
    font-size: 0.875rem;
    opacity: 0.8;
    margin: 0;
}

.plum-header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 4px;
    margin: 0;
    text-transform: uppercase;
}

.plum-meta-bar {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 3rem;
    background-color: #f3f4f6;
    border-bottom: 4px solid #511845;
    font-size: 0.875rem;
    font-weight: 600;
}

.plum-content {
    padding: 3rem;
}

.plum-bill-to {
    margin-bottom: 3rem;
}

.plum-bill-to h5 {
    color: #666;
    margin-bottom: 0.5rem;
}

.plum-bill-to strong {
    font-size: 1.1rem;
    color: #000;
}

.plum-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 3rem;
}

.plum-table th {
    background-color: #511845;
    color: white;
    text-align: left;
    padding: 1rem;
    font-size: 0.875rem;
}

.plum-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #eee;
    font-size: 0.875rem;
}

.plum-table tr:nth-child(even) {
    background-color: #fafafa;
}

.plum-footer-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 4rem;
}

.plum-badge {
    display: inline-block;
    background-color: #511845;
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.plum-total-section {
    text-align: right;
}

.plum-total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.plum-total-row.grand-total {
    background-color: #511845;
    color: white;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.plum-bottom-text {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
    text-align: center;
    color: #999;
    font-size: 0.75rem;
}

.address-block h5 {
    font-size: 0.875rem;
    font-weight: 700;
    color: #000;
    margin-bottom: 0.75rem;
}

.address-block p {
    font-size: 0.875rem;
    line-height: 1.5;
    color: #374151;
}

.saldo-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 3rem;
}

.saldo-table th {
    background-color: var(--primary);
    color: white;
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.saldo-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.875rem;
}

.saldo-table tr:nth-child(even) {
    background-color: #f9fafb;
}

.invoice-bottom-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 4rem;
}

.bottom-left h5 {
    font-size: 0.875rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.bottom-left p {
    font-size: 0.875rem;
    color: #6b7280;
    white-space: pre-line;
}

.summary-table {
    width: 100%;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.summary-row.total {
    border-top: 2px solid #000;
    margin-top: 0.5rem;
    padding-top: 1rem;
    font-size: 1rem;
    font-weight: 800;
}

.summary-row.balance {
    background-color: #f3f4f6;
    padding: 1rem;
    margin-top: 1rem;
    font-weight: 700;
}

.signature-block {
    margin-top: 3rem;
    text-align: right;
}

.signature-img {
    height: 60px;
    margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    #main-content { flex-direction: column; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .nav-menu { display: flex; overflow-x: auto; padding: 0.5rem 0; }
    .nav-item { margin-bottom: 0; white-space: nowrap; }
    .sidebar-footer { display: none; }
    .stats-grid { grid-template-columns: 1fr; }
}
