/**
 * SitesByHugo Invoice System - Styles
 * Matches main-site aesthetic: dark theme, purple/cyan gradients, glassmorphism
 */

/* ===== CSS Variables ===== */
:root {
    /* Primary - Deep Purple/Indigo */
    --color-primary-50: #f5f3ff;
    --color-primary-100: #ede9fe;
    --color-primary-200: #ddd6fe;
    --color-primary-300: #c4b5fd;
    --color-primary-400: #a78bfa;
    --color-primary-500: #8b5cf6;
    --color-primary-600: #7c3aed;
    --color-primary-700: #6d28d9;
    --color-primary-800: #5b21b6;
    --color-primary-900: #4c1d95;
    
    /* Accent - Vibrant Cyan/Teal */
    --color-accent-400: #22d3ee;
    --color-accent-500: #06b6d4;
    --color-accent-600: #0891b2;
    
    /* Secondary - Warm Pink */
    --color-secondary-400: #f472b6;
    --color-secondary-500: #ec4899;
    --color-secondary-600: #db2777;
    
    /* Neutrals */
    --color-gray-50: #fafafa;
    --color-gray-100: #f4f4f5;
    --color-gray-200: #e4e4e7;
    --color-gray-300: #d4d4d8;
    --color-gray-400: #a1a1aa;
    --color-gray-500: #71717a;
    --color-gray-600: #52525b;
    --color-gray-700: #3f3f46;
    --color-gray-800: #27272a;
    --color-gray-900: #18181b;
    --color-gray-950: #09090b;
    
    /* Semantic */
    --color-success: #22c55e;
    --color-success-bg: rgba(34, 197, 94, 0.15);
    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.15);
    --color-error: #ef4444;
    --color-error-bg: rgba(239, 68, 68, 0.15);
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-secondary-500) 100%);
    --gradient-accent: linear-gradient(135deg, var(--color-accent-500) 0%, var(--color-primary-500) 100%);
    --gradient-dark: linear-gradient(180deg, var(--color-gray-900) 0%, var(--color-gray-950) 100%);
    --gradient-text: linear-gradient(135deg, var(--color-primary-400) 0%, var(--color-accent-400) 50%, var(--color-secondary-400) 100%);
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Plus Jakarta Sans', var(--font-sans);
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    
    /* Borders */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --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);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-glow: 0 0 40px rgb(139 92 246 / 0.3);
    
    /* Transitions */
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --duration-150: 150ms;
    --duration-200: 200ms;
    --duration-300: 300ms;
    
    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--color-gray-100);
    background: var(--color-gray-950);
    overflow-x: clip; /* clip (not hidden) so child overflow-x:auto containers can still scroll */
}

::selection {
    background: var(--color-primary-500);
    color: white;
}

:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

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

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

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ===== Logo ===== */
.logo {
    display: flex;
    align-items: center;
    gap: 0.3em;
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}

.logo--sm { font-size: 1.1rem; }

.logo__mark {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo__mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.logo span {
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-left: -0.3em;
    padding-left: 0;
}

/* ===== LOGIN VIEW ===== */
.login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.login-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
}

.login-glow--1 {
    top: -200px;
    right: -100px;
    background: var(--color-primary-600);
}

.login-glow--2 {
    bottom: -200px;
    left: -100px;
    background: var(--color-secondary-600);
}

.login-grid {
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(var(--color-gray-800) 1px, transparent 1px),
        linear-gradient(90deg, var(--color-gray-800) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
    opacity: 0.3;
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: var(--space-6);
}

.login-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-2xl);
    padding: var(--space-10);
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.login-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.login-header .logo {
    justify-content: center;
    margin-bottom: var(--space-6);
}

.login-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
    margin-bottom: var(--space-2);
}

.login-subtitle {
    color: var(--color-gray-400);
    font-size: 0.9375rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.login-footer {
    margin-top: var(--space-8);
    text-align: center;
}

.login-back {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-gray-400);
    font-size: 0.875rem;
    transition: color var(--duration-150) var(--ease-out);
}

.login-back:hover { color: white; }

.login-back svg {
    width: 16px;
    height: 16px;
}

/* ===== FORM ELEMENTS ===== */
.form-group { display: flex; flex-direction: column; }

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-gray-300);
    margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--color-gray-900);
    border: 1px solid var(--color-gray-700);
    border-radius: var(--radius-lg);
    color: white;
    font-size: 0.9375rem;
    transition: all var(--duration-150) var(--ease-out);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--color-gray-500);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.form-error {
    padding: var(--space-3) var(--space-4);
    background: var(--color-error-bg);
    border: 1px solid var(--color-error);
    border-radius: var(--radius-lg);
    color: var(--color-error);
    font-size: 0.875rem;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    border-radius: var(--radius-lg);
    transition: all var(--duration-200) var(--ease-out);
    white-space: nowrap;
}

.btn svg {
    width: 1.125em;
    height: 1.125em;
}

.btn--primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-lg), 0 0 20px rgb(139 92 246 / 0.3);
}

.btn--primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl), 0 0 30px rgb(139 92 246 / 0.4);
}

.btn--secondary {
    background: transparent;
    color: white;
    border: 1px solid var(--color-gray-700);
}

.btn--secondary:hover {
    background: var(--color-gray-800);
    border-color: var(--color-gray-600);
}

.btn--ghost {
    background: transparent;
    color: var(--color-gray-300);
}

.btn--ghost:hover {
    color: white;
    background: var(--color-gray-800);
}

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

.btn--success:hover {
    background: #16a34a;
}

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

.btn--danger:hover {
    background: #dc2626;
}

.btn--sm {
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
}

.btn--full { width: 100%; }

.btn-loader { display: flex; }

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

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

/* ===== APP LAYOUT ===== */
.app-view {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: rgba(24, 24, 27, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--color-gray-800);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--duration-300) var(--ease-out);
}

.sidebar-header {
    padding: var(--space-6);
    border-bottom: 1px solid var(--color-gray-800);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--color-gray-400);
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius-lg);
    transition: all var(--duration-150) var(--ease-out);
    width: 100%;
    text-align: left;
}

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

.nav-item:hover {
    color: white;
    background: var(--color-gray-800);
}

.nav-item.active {
    color: white;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--color-gray-800);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    background: var(--color-gray-900);
    border-radius: var(--radius-lg);
}

.user-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    font-weight: 700;
    color: white;
    font-size: 1rem;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    color: white;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    color: var(--color-gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-bar {
    height: var(--topbar-height);
    padding: 0 var(--space-8);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: rgba(24, 24, 27, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--color-gray-800);
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-400);
    border-radius: var(--radius-lg);
    transition: all var(--duration-150) var(--ease-out);
}

.sidebar-toggle:hover {
    color: white;
    background: var(--color-gray-800);
}

.sidebar-toggle svg {
    width: 24px;
    height: 24px;
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.content-container {
    flex: 1;
    padding: var(--space-8);
    overflow-y: auto;
}

/* ===== VIEW SECTIONS ===== */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

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

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.view-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.view-header-left h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
}

.view-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    gap: var(--space-3);
}

.filter-group .form-select {
    min-width: 140px;
    padding: var(--space-2) var(--space-3);
    font-size: 0.875rem;
}

/* ===== DASHBOARD ===== */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-2xl);
    padding: var(--space-6);
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    transition: all var(--duration-300) var(--ease-out);
}

.stat-card:hover {
    border-color: rgba(139, 92, 246, 0.3);
    transform: translateY(-2px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xl);
    flex-shrink: 0;
}

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

.stat-icon--primary {
    background: rgba(139, 92, 246, 0.15);
    color: var(--color-primary-400);
}

.stat-icon--success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.stat-icon--warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.stat-icon--accent {
    background: rgba(6, 182, 212, 0.15);
    color: var(--color-accent-400);
}

.stat-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--color-gray-400);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
}

.dashboard-grid {
    display: grid;
    gap: var(--space-6);
}

/* ===== CARDS ===== */
.card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-2xl);
    padding: var(--space-6);
    position: relative;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-5);
}

.card-title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
    color: white;
}

.card.full-width {
    grid-column: 1 / -1;
}

/* ===== TABLES ===== */
.table-container {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--color-gray-800);
}

.table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-gray-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table td {
    color: var(--color-gray-200);
}

.table tbody tr {
    transition: background var(--duration-150) var(--ease-out);
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.clickable-row {
    cursor: pointer;
}

.table-actions {
    display: flex;
    gap: var(--space-2);
}

/* ===== STATUS BADGES ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: var(--radius-full);
}

.status-badge--draft {
    background: rgba(161, 161, 170, 0.15);
    color: var(--color-gray-400);
}

.status-badge--sent {
    background: rgba(6, 182, 212, 0.15);
    color: var(--color-accent-400);
}

.status-badge--paid {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.status-badge--void {
    background: var(--color-error-bg);
    color: var(--color-error);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    padding: var(--space-12);
    text-align: center;
    color: var(--color-gray-400);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-4);
    opacity: 0.3;
}

.empty-state p {
    margin-bottom: var(--space-4);
}

/* ===== CLIENTS GRID ===== */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-6);
}

.client-card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-2xl);
    padding: var(--space-6);
    transition: all var(--duration-300) var(--ease-out);
}

.client-card:hover {
    border-color: rgba(139, 92, 246, 0.3);
    transform: translateY(-2px);
}

.client-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.client-avatar {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border-radius: var(--radius-xl);
    font-weight: 700;
    color: white;
    font-size: 1.25rem;
}

.client-card-actions {
    display: flex;
    gap: var(--space-2);
}

.client-name {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
    color: white;
    margin-bottom: var(--space-1);
}

.client-contact {
    font-size: 0.875rem;
    color: var(--color-gray-400);
    margin-bottom: var(--space-4);
}

.client-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-gray-800);
}

.client-meta-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.client-meta-label {
    font-size: 0.75rem;
    color: var(--color-gray-500);
    text-transform: uppercase;
}

.client-meta-value {
    font-weight: 600;
    color: white;
}

/* ===== INVOICE FORM ===== */
.invoice-form .form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
}

.invoice-form .form-grid .card {
    display: flex;
    flex-direction: column;
}

.invoice-form .form-group {
    margin-bottom: var(--space-5);
}

.invoice-form .card-title {
    margin-bottom: var(--space-5);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-4);
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-gray-800);
}

/* Work Items */
.work-item {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr 1fr auto;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-gray-900);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-3);
    border-top: 2px solid transparent;
}

.work-item[data-kind="header"] {
    border-top-color: var(--color-primary-500);
}

.work-item[data-kind="group"] {
    margin-left: var(--space-5);
}

.work-item[data-kind="subtotal"],
.work-item[data-kind="summary"] {
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
}

.work-item .work-kind {
    color: var(--color-gray-400);
    font-size: 0.8125rem;
}

.work-item .form-input {
    background: var(--color-gray-800);
}

.work-item-desc {
    grid-column: 1 / -1;
    margin-top: var(--space-3);
}

.work-item-desc textarea {
    min-height: 60px;
    font-size: 0.875rem;
}

.work-item-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.work-item-reorder,
.work-item-remove {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-500);
    border-radius: var(--radius-lg);
    transition: all var(--duration-150) var(--ease-out);
}

.work-item-reorder:hover {
    color: var(--color-primary-400);
    background: rgba(139, 92, 246, 0.15);
}

.work-item-remove:hover {
    color: var(--color-error);
    background: var(--color-error-bg);
}

.work-item-reorder svg,
.work-item-remove svg {
    width: 18px;
    height: 18px;
}

/* Invoice Totals */
.invoice-totals {
    margin-top: auto;
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-gray-800);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    color: var(--color-gray-400);
}

.total-row--grand {
    padding-top: var(--space-3);
    margin-top: var(--space-2);
    border-top: 1px solid var(--color-gray-700);
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

/* ===== INVOICE PREVIEW ===== */
.invoice-preview-container {
    display: flex;
    justify-content: center;
    padding: var(--space-6);
    background: var(--color-gray-900);
    border-radius: var(--radius-2xl);
    overflow: auto; /* Allow scrolling if pages exceed height */
}

/* The container for the pages */
.invoice-preview {
    background: transparent;
    width: auto;
    max-width: none;
    min-height: auto;
    padding: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 40px; /* Space between pages */
    align-items: center;
}

/* The actual paper sheets */
.invoice-page {
    background: white;
    color: #1f2937;
    width: 210mm;
    height: 297mm;
    min-height: 297mm;
    max-height: 297mm;
    overflow: hidden;
    padding: 28px 36px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    position: relative;
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
}

.invoice-page > .invoice-footer {
    margin-top: auto;
}

.invoice-page * {
    color: #1f2937;
}


.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 2px solid #e5e7eb;
}

.invoice-brand {
    display: flex;
    flex-direction: column;
}

.invoice-brand-logo-wrapper {
    margin-bottom: 4px;
    margin-left: -5px; /* Slight optical adjustment for SVG padding */
    margin-top: 2px;
}

/* Legacy - kept for safety if used elsewhere */
.invoice-brand-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.invoice-brand-logo img,
.invoice-brand-logo svg {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.invoice-brand-name {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    color: #111;
}

.invoice-brand-name span {
    background: var(--gradient-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.invoice-brand-tagline {
    font-size: 12px;
    color: #6b7280;
}

.invoice-title-section {
    text-align: right;
}

.invoice-title {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 800;
    color: #111;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.invoice-number {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-primary-600);
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 16px;
}

.invoice-party h4 {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.invoice-party-name {
    font-size: 16px;
    font-weight: 700;
    color: #111;
    margin-bottom: 4px;
}

.invoice-party p {
    font-size: 13px;
    color: #4b5563;
    line-height: 1.6;
}

.invoice-dates {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #f9fafb;
    border-radius: 8px;
}

.invoice-date-item {
    text-align: center;
}

.invoice-date-label {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.invoice-date-value {
    font-size: 15px;
    font-weight: 600;
    color: #111;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.invoice-items-table th {
    background: #1f2937;
    color: white;
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.invoice-items-table th:first-child {
    border-radius: 6px 0 0 6px;
}

.invoice-items-table th:last-child {
    border-radius: 0 6px 6px 0;
    text-align: right;
}

.invoice-items-table td {
    padding: 10px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 13px;
}

.invoice-items-table td:last-child {
    text-align: right;
    font-weight: 600;
}

.invoice-items-table tbody tr:hover {
    background: #f9fafb;
}

/* Work log structure rows (section headers, subsection headers, subtotals).
   Kept in the same light, hairline-bordered language as the rest of the table
   instead of introducing new heavy blocks: a purple rule marks a section,
   everything under it just indents and quiets down. */
.invoice-items-table tr.worklog-header-row td {
    padding: 14px 16px 8px;
    border-bottom: 1px solid #e5e7eb;
    border-top: 2px solid var(--color-primary-600);
}

.invoice-items-table tr.worklog-header-row:first-child td {
    border-top: none;
}

.worklog-header-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary-600);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.worklog-header-desc {
    font-size: 12px;
    font-weight: 400;
    color: #6b7280;
    margin-top: 3px;
    line-height: 1.4;
}

.invoice-items-table tr.worklog-group-row td {
    padding: 8px 16px 8px 30px;
    border-bottom: 1px solid #f3f4f6;
}

.worklog-group-title {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.worklog-group-desc {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    line-height: 1.4;
}

.invoice-items-table tr.worklog-subtotal-row td {
    padding: 8px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    color: #6b7280;
    font-size: 12px;
}

.invoice-items-table tr.worklog-subtotal-row td:first-child {
    padding-left: 30px;
    font-weight: 600;
    color: #374151;
}

.invoice-items-table tr.worklog-subtotal-row td:last-child {
    font-weight: 700;
    color: #1f2937;
}

.invoice-totals-section {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.invoice-totals-box {
    width: 280px;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
}

.invoice-total-row--grand {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 2px solid #1f2937;
    font-size: 20px;
    font-weight: 700;
}

.invoice-notes {
    padding: 14px 16px;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.invoice-notes h4 {
    font-size: 12px;
    font-weight: 700;
    color: #1f2937;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.invoice-notes p {
    font-size: 13px;
    color: #4b5563;
    white-space: pre-wrap;
}

.invoice-notes p + .invoice-bank {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
}

.invoice-bank h4 {
    font-size: 11px;
    font-weight: 700;
    color: #1f2937;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.invoice-bank p {
    font-size: 12px;
    color: #1f2937;
    line-height: 1.45;
    margin: 0;
}

.invoice-bank-address {
    color: #6b7280;
    font-weight: 400;
}

.invoice-footer {
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #9ca3af;
}

.invoice-footer a {
    color: var(--color-primary-600);
    text-decoration: none;
    font-weight: 600;
}

/* Paid Stamp */
.invoice-stamp {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    /* Color usage changed to support SVG currentColor */
    color: var(--color-success);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    
    /* Container sizing for the SVG */
    width: 500px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.invoice-page.is-paid .invoice-stamp {
    opacity: 0.4;
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-6);
}

.modal {
    background: var(--color-gray-900);
    border: 1px solid var(--color-gray-800);
    border-radius: var(--radius-2xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

.modal--sm { max-width: 400px; }

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

.modal-title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
    color: white;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-400);
    border-radius: var(--radius-lg);
    transition: all var(--duration-150) var(--ease-out);
}

.modal-close:hover {
    color: white;
    background: var(--color-gray-800);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
}

.modal-body .form-group {
    margin-bottom: var(--space-5);
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--color-gray-800);
    background: var(--color-gray-950);
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 280px;
    padding: var(--space-4) var(--space-5);
    background: var(--color-gray-800);
    border: 1px solid var(--color-gray-700);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    animation: toastIn 0.3s ease;
}

.toast--success {
    border-color: var(--color-success);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, var(--color-gray-800) 100%);
}

.toast--error {
    border-color: var(--color-error);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, var(--color-gray-800) 100%);
}

.toast--info {
    border-color: var(--color-primary-500);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, var(--color-gray-800) 100%);
}

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

.toast-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.toast--success .toast-icon { color: var(--color-success); }
.toast--error .toast-icon { color: var(--color-error); }
.toast--info .toast-icon { color: var(--color-primary-400); }

.toast-message {
    flex: 1;
    font-size: 0.875rem;
    color: white;
}

.toast-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-gray-500);
    border-radius: var(--radius-md);
    transition: all var(--duration-150) var(--ease-out);
}

.toast-close:hover {
    color: white;
    background: var(--color-gray-700);
}

.toast-close svg {
    width: 14px;
    height: 14px;
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(9, 9, 11, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    color: var(--color-gray-400);
}

.loading-spinner .spinner {
    width: 48px;
    height: 48px;
    color: var(--color-primary-500);
}

/* ===== SERVER WAKE SCREEN ===== */
.wake-screen {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--color-gray-950);
    overflow: hidden;
}

.wake-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    text-align: center;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-2xl);
    padding: var(--space-10) var(--space-8);
    box-shadow:
        0 25px 50px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.wake-mark {
    position: relative;
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-6);
}

.wake-mark img {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
}

.wake-pulse {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 2px solid var(--color-primary-500);
    animation: wake-pulse 1.8s var(--ease-out, ease-out) infinite;
}

@keyframes wake-pulse {
    from { transform: scale(0.7); opacity: 0.8; }
    to { transform: scale(1.5); opacity: 0; }
}

.wake-title {
    font-family: var(--font-display);
    font-size: 1.375rem;
    font-weight: 700;
    color: white;
    margin-bottom: var(--space-2);
}

.wake-text {
    color: var(--color-gray-400);
    font-size: 0.9375rem;
    line-height: 1.5;
    margin-bottom: var(--space-6);
}

.wake-progress {
    height: 6px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.wake-progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.5s linear;
}

.wake-meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    margin-top: var(--space-3);
    font-size: 0.8125rem;
    color: var(--color-gray-500);
    text-align: left;
}

.wake-elapsed {
    font-variant-numeric: tabular-nums;
    color: var(--color-gray-300);
}

.wake-screen .wake-when-failed { display: none; }
.wake-screen--failed .wake-when-waking { display: none; }
.wake-screen--failed .wake-when-failed { display: revert; }
.wake-screen--failed .wake-pulse { animation: none; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
    .wake-pulse { animation: none; opacity: 0.4; }
    .wake-progress-bar { transition: none; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1280px) {
    .dashboard-stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1024px) {
    .invoice-form .form-grid {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .sidebar-toggle {
        display: flex;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 100%;
    }

    /* ── Spacing ── */
    .content-container {
        padding: var(--space-4);
    }

    .top-bar {
        padding: 0 var(--space-4);
    }

    .page-title {
        font-size: 1.125rem;
    }

    /* ── Dashboard stats ── */
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
        margin-bottom: var(--space-5);
    }

    .stat-card {
        padding: var(--space-4);
        gap: var(--space-3);
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
    }

    .stat-value {
        font-size: 1.375rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* ── View headers ── */
    .view-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .view-header-left h2 {
        font-size: 1.125rem;
    }

    .view-header-right {
        width: 100%;
        flex-wrap: wrap;
    }

    /* ── Filters ── */
    .filter-group {
        flex-wrap: wrap;
        width: 100%;
    }

    .filter-group .form-select {
        flex: 1;
        min-width: 0;
    }

    /* ── Forms ── */
    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: var(--space-3);
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* ── Work items ── */
    .work-item {
        grid-template-columns: 1fr auto;
    }

    .work-item > *:nth-child(2),
    .work-item > *:nth-child(3),
    .work-item > *:nth-child(4) {
        grid-column: 1 / 2;
    }

    .work-item-actions {
        grid-column: 2 / 3;
        grid-row: 1 / 5;
        flex-direction: column;
    }

    /* ── Invoice preview (view-invoice) ── */
    /* JS zoom handles the scale; just reduce padding so preview has maximum space */
    .invoice-preview-container {
        padding: 8px;
    }

    /* ── View-invoice action buttons ── */
    #viewInvoiceView .view-header-right {
        gap: var(--space-2);
    }

    #viewInvoiceView .view-header-right .btn,
    #viewInvoiceView .view-header-right .status-toggle {
        flex: 1 1 calc(50% - var(--space-2));
    }

    #viewInvoiceView .view-header-right .btn {
        font-size: 0.8125rem;
        padding: var(--space-2) var(--space-3);
    }

    /* ── Clients ── */
    .clients-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    @page {
        margin: 0;
        size: A4;
    }

    html, body {
        background: white !important;
        height: initial !important;
        overflow: initial !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .sidebar,
    .top-bar,
    .view-header,
    .view-actions,
    .loading-overlay,
    .modal-overlay,
    .toast-container {
        display: none !important;
    }
    
    .app-view {
        display: block !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    .content-container {
        padding: 0 !important;
        max-width: none !important;
    }
    
    .invoice-preview-view {
        padding: 0 !important;
        background: none !important;
    }

    .invoice-preview-container {
        display: block !important;
        background: none !important;
        padding: 0 !important;
        box-shadow: none !important;
        overflow: visible !important;
    }
    
    .invoice-preview {
        display: block !important;
        gap: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .invoice-page {
        box-shadow: none !important;
        border: none !important;
        max-width: none !important;
        width: 100% !important;
        padding: 2.5cm !important; /* Standard A4 margin */
        margin: 0 !important;
        min-height: 29.7cm;
        page-break-after: always;
    }
    
    .invoice-page:last-child {
        page-break-after: auto;
    }

    /* Force the beautiful preview background and colors */
    .invoice-items-table th {
        background-color: #1f2937 !important;
        color: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .invoice-dates {
        background-color: #f9fafb !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .invoice-notes {
        background-color: #f9fafb !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .invoice-brand-name span {
        background: var(--gradient-text) !important;
        -webkit-background-clip: text !important;
        background-clip: text !important;
        -webkit-text-fill-color: transparent !important;
        color: var(--color-primary-500) !important; /* Fallback for browsers that don't support text-clip print */
    }

    .invoice-stamp {
        opacity: 0.3 !important;
    }
}
