/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --background: 210 40% 98%;
    --foreground: 215 25% 15%;
    --card: 0 0% 100%;
    --card-foreground: 215 25% 15%;
    --primary: 214 95% 50%;
    --primary-foreground: 0 0% 100%;
    --primary-glow: 214 90% 60%;
    --secondary: 210 40% 96%;
    --secondary-foreground: 215 25% 15%;
    --muted: 210 40% 96%;
    --muted-foreground: 215 16% 47%;
    --accent: 212 85% 45%;
    --accent-foreground: 0 0% 100%;
    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 100%;
    --border: 214 32% 91%;
    --input: 214 32% 91%;
    --ring: 214 95% 50%;
    --success: 142 71% 45%;
    --success-foreground: 0 0% 100%;
    --warning: 38 92% 50%;
    --warning-foreground: 0 0% 100%;
    --radius: 0.75rem;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.6;
}

/* Smooth Transitions */
button, a, .btn, .nav-item, .card, .invoice-item, input, select, textarea, .sidebar {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.sidebar {
    width: 280px;
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 999;
}

.sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: hsl(var(--foreground));
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: background 0.2s ease;
    z-index: 1000;
}

.sidebar-close:hover {
    background: hsl(var(--muted));
}

.sidebar-close svg {
    width: 20px;
    height: 20px;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 2rem;
    height: 2rem;
    padding: 0.5rem;
    background: hsl(var(--primary));
    border-radius: var(--radius);
    color: white;
}

.app-name {
    font-weight: bold;
    font-size: 1.125rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.nav-item:hover {
    background: hsl(var(--accent) / 0.1);
    color: hsl(var(--foreground));
}

.nav-item.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.nav-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    width: calc(100% - 280px);
}

.header {
    height: 4rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsl(var(--card) / 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 3px hsl(var(--border));
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: hsl(var(--foreground));
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-icon {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.5rem;
    background: hsl(var(--primary));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px hsl(var(--primary) / 0.2);
}

.header-icon svg {
    width: 1.25rem;
    height: 1.25rem;
    color: white;
}

.header-title {
    font-weight: bold;
    font-size: 1.125rem;
}

.content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 2.25rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.gradient-text {
    color: hsl(var(--primary));
}

.page-subtitle {
    color: hsl(var(--muted-foreground));
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: hsl(var(--card));
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    border-left: 4px solid hsl(var(--primary) / 0.5);
    transition: all 0.3s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px hsl(var(--border));
}

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

.stat-title {
    font-size: 0.875rem;
    text-transform: uppercase;
    color: hsl(var(--muted-foreground));
    font-weight: 600;
    letter-spacing: 0.05em;
}

.stat-icon {
    padding: 0.5rem;
    border-radius: var(--radius);
    width: 2.5rem;
    height: 2.5rem;
}

.stat-icon svg {
    width: 100%;
    height: 100%;
}

.bg-primary { background: hsl(var(--primary) / 0.1); color: hsl(var(--primary)); }
.bg-success { background: hsl(var(--success) / 0.1); color: hsl(var(--success)); }
.bg-destructive { background: hsl(var(--destructive) / 0.1); color: hsl(var(--destructive)); }
.bg-warning { background: hsl(var(--warning) / 0.1); color: hsl(var(--warning)); }
.bg-card { background: hsl(var(--card) / 0.5); }
.bg-success-light { background: hsl(var(--success) / 0.05); }
.bg-warning-light { background: hsl(var(--warning) / 0.05); }

.stat-value {
    font-size: 1.875rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.stat-description {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* Cards */
.card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px hsl(var(--border));
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 8px 24px hsl(var(--primary) / 0.1);
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gradient-header {
    background: hsl(var(--primary) / 0.05);
}

.card-title {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.card-title-flex {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: bold;
}

.card-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.card-content {
    padding: 1.5rem;
}

.gradient-card-primary {
    background: hsl(var(--primary) / 0.05);
    border-color: hsl(var(--primary) / 0.3);
}

.gradient-card-success {
    background: hsl(var(--success) / 0.05);
    border-color: hsl(var(--success) / 0.3);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.875rem;
}

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

.btn-primary:hover {
    background: hsl(var(--primary) / 0.9);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-outline:hover {
    background: hsl(var(--muted));
    transform: translateY(-1px);
}

.btn-outline:active {
    transform: translateY(0);
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 1rem;
    height: 1rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1.5rem;
}

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

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 0.875rem;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px hsl(var(--ring) / 0.1);
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-icon {
    width: 3rem;
    height: 3rem;
    color: hsl(var(--muted-foreground));
    margin: 0 auto 1rem;
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: hsl(var(--muted-foreground));
    margin-bottom: 1rem;
}

/* Grid */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Icon Badge */
.icon-badge {
    padding: 0.5rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
}

.icon-badge svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Revenue Grid */
.revenue-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.revenue-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-radius: var(--radius);
    font-weight: 500;
}

.revenue-value {
    font-size: 1.125rem;
    font-weight: bold;
}

.text-success { color: hsl(var(--success)); }
.text-warning { color: hsl(var(--warning)); }

/* Invoice List */
.invoice-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: hsl(var(--card));
    transition: all 0.3s ease;
}

.invoice-item:hover {
    transform: translateX(4px);
    border-color: hsl(var(--primary));
    box-shadow: 0 4px 12px hsl(var(--primary) / 0.15);
}

.invoice-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.invoice-icon-box {
    width: 3rem;
    height: 3rem;
    background: hsl(var(--primary) / 0.1);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

.invoice-icon-box svg {
    width: 1.5rem;
    height: 1.5rem;
    color: hsl(var(--primary));
}

.invoice-details h4 {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.invoice-details p {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid;
}

.badge-paid {
    background: hsl(var(--success) / 0.1);
    color: hsl(var(--success));
    border-color: hsl(var(--success) / 0.2);
}

.badge-sent {
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
    border-color: hsl(var(--primary) / 0.2);
}

.badge-draft {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    border-color: hsl(var(--border));
}

.badge-overdue {
    background: hsl(var(--destructive) / 0.1);
    color: hsl(var(--destructive));
    border-color: hsl(var(--destructive) / 0.2);
}

/* Invoice form styles */
.invoice-items {
    margin-bottom: 2rem;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: start;
}

.item-row .form-group {
    margin-bottom: 0;
}

.item-row .btn-danger {
    min-width: auto;
    padding: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-row .btn-danger svg {
    width: 20px;
    height: 20px;
}

.btn-danger {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    border: none;
}

.btn-danger:hover {
    background: hsl(var(--destructive) / 0.9);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px hsl(var(--destructive) / 0.3);
}

.btn-danger:active {
    transform: translateY(0);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        z-index: 999;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .sidebar-toggle {
        display: block;
    }

    .header {
        padding: 0.75rem 1rem;
    }

    .header-logo {
        gap: 0.5rem;
    }

    .header-title {
        font-size: 1rem;
    }

    .sidebar-toggle {
        padding: 0.5rem;
        font-size: 1.25rem;
    }

    .content {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.75rem;
        margin-bottom: 0.5rem;
    }

    .page-subtitle {
        font-size: 0.875rem;
        margin-bottom: 1.5rem;
    }

    .card {
        padding: 1rem;
        margin-bottom: 1.5rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1rem;
    }

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

    .card-content {
        padding: 1rem;
    }

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

    .btn-lg {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

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

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        margin-bottom: 1.5rem;
    }

    .invoice-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1rem;
    }

    .invoice-item > div:last-child {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .invoice-item .invoice-info {
        width: 100%;
    }

    .import-area, .export-area {
        padding: 2rem 1rem;
        text-align: center;
    }

    .import-area h3, .export-area h3 {
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }

    .import-area p, .export-area p {
        font-size: 0.875rem;
        margin-bottom: 1.25rem;
    }

    table {
        font-size: 0.875rem;
    }

    table th, table td {
        padding: 0.75rem 0.5rem;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.375rem;
    }

    .form-input, .form-select, .form-textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.625rem 0.875rem;
    }

    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-icon {
        width: 2.5rem;
        height: 2.5rem;
    }

    .invoice-paper {
        padding: 0.75rem !important;
    }
    
    #invoiceContent {
        font-size: 0.875rem !important;
    }
    
    #invoiceContent .invoice-header {
        flex-direction: column !important;
        gap: 1rem !important;
        margin-bottom: 1.5rem !important;
        padding-bottom: 1rem !important;
    }
    
    #invoiceContent .invoice-header > div {
        min-width: 100% !important;
    }
    
    #invoiceContent .invoice-title-section {
        text-align: left !important;
    }
    
    #invoiceContent .invoice-title-section > div {
        text-align: left !important;
    }
    
    #invoiceContent .invoice-title-section h1 {
        font-size: 1.5rem !important;
    }
    
    #invoiceContent .invoice-title-section p {
        font-size: 0.875rem !important;
    }
    
    #invoiceContent .invoice-title-section > div > div {
        justify-content: flex-start !important;
    }
    
    #invoiceContent h1 {
        font-size: 1.5rem !important;
    }
    
    #invoiceContent h2 {
        font-size: 1rem !important;
    }
    
    #invoiceContent h3 {
        font-size: 0.75rem !important;
    }
    
    #invoiceContent table {
        font-size: 0.7rem !important;
    }
    
    #invoiceContent table th,
    #invoiceContent table td {
        padding: 0.5rem 0.5rem !important;
        font-size: 0.7rem !important;
    }
    
    #invoiceContent img {
        max-width: 100px !important;
        max-height: 60px !important;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        position: relative;
        padding-right: 3rem;
    }
    
    .item-row .form-group label {
        font-size: 0.875rem;
    }
    
    .item-row .btn-danger {
        position: absolute;
        top: 0;
        right: 0;
        min-width: auto;
        padding: 0.5rem;
    }
    
    .item-row .btn-danger span {
        display: none;
    }
    
    .item-row .btn-danger svg {
        width: 18px;
        height: 18px;
    }
    
    .remove-text {
        display: none;
    }
}

/* Tablet Responsive */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }

    .main-content {
        margin-left: 200px;
        width: calc(100% - 200px);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Print Styles */
@media print {
    /* Hide everything except invoice content */
    .sidebar,
    .header,
    .btn,
    .btn-primary,
    .btn-outline,
    .sidebar-overlay,
    .sidebar-toggle {
        display: none !important;
    }
    
    /* Reset main content layout */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .content {
        padding: 0 !important;
        max-width: 100% !important;
    }
    
    /* Make card fill page */
    .card {
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    .card-content {
        padding: 1.5rem !important;
    }
    
    /* Optimize for printing */
    body {
        background: white !important;
    }
    
    /* Ensure proper page breaks */
    #invoiceContent {
        page-break-inside: avoid;
    }
    
    /* Hide print button's parent container */
    .content > div:first-child {
        display: none !important;
    }
}