/* ================================
   CSS Variables & Base Styles
   ================================ */
:root {
    /* Colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;

    /* Backgrounds */
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;

    /* Text */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --text-inverse: #f8fafc;

    /* Borders */
    --border-color: #e2e8f0;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px 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);

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 60px;

    /* Transitions */
    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* ================================
   Sidebar
   ================================ */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--bg-sidebar-hover);
}

.sidebar-logo {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    border-radius: var(--border-radius);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-inverse);
    margin: 0;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-light);
    display: block;
    margin-top: 4px;
}

.subtitle a {
    color: var(--primary-light);
    text-decoration: none;
    transition: var(--transition);
}

.subtitle a:hover {
    color: var(--text-inverse);
    text-decoration: underline;
}

.nav-menu {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.9375rem;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: var(--transition);
    width: 100%;
    text-align: left;
}

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

.nav-item.active {
    background-color: var(--primary);
    color: var(--text-inverse);
}

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

/* ================================
   Mobile Header
   ================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--bg-sidebar);
    color: var(--text-inverse);
    padding: 0 16px;
    align-items: center;
    gap: 16px;
    z-index: 90;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--text-inverse);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.mobile-logo {
    font-size: 1.125rem;
    font-weight: 600;
}

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

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

/* ================================
   Main Content
   ================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    max-width: 1400px;
}

/* ================================
   Views
   ================================ */
.view {
    display: none;
}

.view.active {
    display: block;
}

.view-header {
    margin-bottom: 24px;
}

.view-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.view-header p {
    color: var(--text-secondary);
}

/* ================================
   Cards
   ================================ */
.card {
    background-color: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.section-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 24px 0 12px;
    color: var(--text-secondary);
}

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.9375rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
}

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

.form-control:disabled {
    background-color: var(--bg-main);
    cursor: not-allowed;
}

.form-control::placeholder {
    color: var(--text-light);
}

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

select.form-control {
    cursor: pointer;
}

input[type="number"]#defaultRate {
    max-width: 200px;
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

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

.form-hint a:hover {
    text-decoration: underline;
}

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

.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button .form-control {
    flex: 1;
}

/* ================================
   Buttons
   ================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--border-color);
}

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

.btn-success:hover:not(:disabled) {
    background-color: var(--success-hover);
}

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

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger-hover);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8125rem;
}

.btn-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ================================
   Date Range Picker
   ================================ */
.date-range-picker {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.date-range-picker .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

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

.data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background-color: var(--bg-main);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background-color: var(--bg-main);
}

/* ================================
   Summary Stats
   ================================ */
.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
}

.summary-stats {
    display: flex;
    gap: 32px;
}

.stat {
    text-align: right;
}

.stat-label {
    display: block;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-value.accent {
    color: var(--success);
}

/* ================================
   Loading & Empty States
   ================================ */
.loading-state,
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.loading-state svg,
.empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-light);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.125rem;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

/* ================================
   API Status
   ================================ */
.api-status {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    display: none;
}

.api-status.success {
    display: block;
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.api-status.error {
    display: block;
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ================================
   Invoice Layout
   ================================ */
.invoice-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

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

.invoice-preview-container {
    position: sticky;
    top: 32px;
}

.invoice-preview-card {
    margin-bottom: 0;
}

.invoice-actions {
    display: flex;
    gap: 12px;
    margin-top: 0;
}

/* ================================
   Line Items
   ================================ */
.line-items-container {
    margin-bottom: 8px;
}

.line-item {
    display: grid;
    grid-template-columns: 1fr 80px 60px 100px 36px;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background-color: var(--bg-main);
    border-radius: var(--border-radius);
    margin-bottom: 6px;
}

.line-item .line-item-desc {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.line-item input {
    padding: 6px 8px;
    font-size: 0.875rem;
    text-align: right;
}

.line-item .line-item-amount {
    font-size: 0.875rem;
    font-weight: 500;
    text-align: right;
    color: var(--text-primary);
}

.line-item .remove-item {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.line-item .remove-item:hover {
    color: var(--danger);
}

.line-item-header {
    display: grid;
    grid-template-columns: 1fr 80px 60px 100px 36px;
    gap: 8px;
    padding: 8px 12px 4px;
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-row {
    display: grid;
    grid-template-columns: 1fr 80px 100px 36px;
    gap: 8px;
    padding: 12px;
    margin-top: 8px;
    background-color: var(--primary-light);
    border-radius: var(--border-radius);
    font-weight: 600;
}

.summary-label {
    color: var(--text-primary);
}

.summary-hours {
    text-align: right;
    color: var(--text-secondary);
}

.summary-amount {
    text-align: right;
    color: var(--success);
    font-size: 1rem;
}

/* ================================
   Invoice Preview / Document
   ================================ */
.invoice-preview {
    background-color: var(--bg-main);
    border-radius: var(--border-radius);
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
}

.invoice-document {
    background-color: white;
    padding: 40px;
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.6;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--primary);
}

.company-info {
    max-width: 60%;
}

.company-logo {
    max-width: 150px;
    max-height: 60px;
    margin-bottom: 12px;
}

.company-name {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.company-details {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

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

.invoice-title h1 {
    font-size: 2rem;
    color: var(--primary);
    margin: 0;
    letter-spacing: 2px;
}

.invoice-number {
    color: var(--text-secondary);
    margin-top: 8px;
}

.invoice-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 32px;
}

.bill-to h4 {
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.bill-to p {
    margin: 4px 0;
}

.invoice-dates {
    text-align: right;
}

.invoice-dates p {
    margin: 4px 0;
}

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

.invoice-table th {
    background-color: var(--bg-main);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.invoice-table th:last-child,
.invoice-table td:last-child {
    text-align: right;
}

.invoice-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.invoice-table .empty-row {
    text-align: center;
    color: var(--text-secondary);
    padding: 32px;
}

.invoice-total {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 32px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    gap: 48px;
    padding: 16px 24px;
    background-color: var(--bg-main);
    border-radius: var(--border-radius);
    font-size: 1.25rem;
    font-weight: 600;
}

.total-amount {
    color: var(--success);
}

.invoice-footer {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* ================================
   App Footer
   ================================ */
.app-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-main);
}

.app-footer p {
    margin-bottom: 4px;
}

.app-footer .trademark {
    color: var(--text-light);
    margin-bottom: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.app-footer a:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* ================================
   Toast Notification
   ================================ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: var(--bg-sidebar);
    color: var(--text-inverse);
    padding: 12px 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

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

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

/* ================================
   Responsive Styles
   ================================ */

/* Tablet */
@media (max-width: 1200px) {
    .invoice-layout {
        grid-template-columns: 1fr;
    }

    .invoice-preview-container {
        position: static;
    }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

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

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: calc(var(--header-height) + 16px);
    }

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

    .card {
        padding: 16px;
    }

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

    .date-range-picker {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .date-range-picker .form-group {
        min-width: 100%;
    }

    .date-range-picker .btn {
        width: 100%;
    }

    /* Line items mobile layout */
    .line-item-header {
        display: none;
    }

    .line-item {
        grid-template-columns: 1fr auto;
        gap: 8px;
        padding: 12px;
    }

    .line-item .line-item-desc {
        grid-column: 1 / -1;
        font-weight: 500;
        margin-bottom: 4px;
    }

    .line-item input {
        width: 80px;
    }

    .line-item .line-item-amount {
        flex: 1;
    }

    .line-item .remove-item {
        position: absolute;
        top: 8px;
        right: 8px;
    }

    .line-item {
        position: relative;
        padding-right: 40px;
    }

    .summary-row {
        grid-template-columns: 1fr auto auto;
        gap: 12px;
    }

    /* Invoice document mobile */
    .invoice-preview {
        padding: 8px;
        max-height: 60vh;
    }

    .invoice-document {
        padding: 20px;
        font-size: 12px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 16px;
    }

    .company-info {
        max-width: 100%;
    }

    .invoice-title {
        text-align: left;
    }

    .invoice-title h1 {
        font-size: 1.5rem;
    }

    .invoice-meta {
        flex-direction: column;
        gap: 16px;
    }

    .invoice-dates {
        text-align: left;
    }

    .invoice-table th,
    .invoice-table td {
        padding: 8px;
        font-size: 11px;
    }

    .total-row {
        padding: 12px 16px;
        font-size: 1rem;
        gap: 24px;
    }

    .invoice-actions {
        flex-direction: column;
    }

    .invoice-actions .btn {
        width: 100%;
    }

    .btn-group {
        flex-direction: column;
    }

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

    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .main-content {
        padding: 12px;
        padding-top: calc(var(--header-height) + 12px);
    }

    .card {
        padding: 12px;
        border-radius: var(--border-radius);
    }

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

    .invoice-document {
        padding: 16px;
    }

    .invoice-table th:nth-child(3),
    .invoice-table td:nth-child(3) {
        display: none;
    }

    .summary-row {
        grid-template-columns: 1fr auto;
    }

    .summary-hours {
        display: none;
    }
}

/* ================================
   Print Styles
   ================================ */
@media print {
    body {
        background: white;
    }

    .sidebar,
    .mobile-header,
    .invoice-form-container,
    .invoice-actions,
    .card-title,
    .toast {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .invoice-preview-container {
        position: static;
    }

    .invoice-preview-card {
        box-shadow: none;
        padding: 0;
    }

    .invoice-preview {
        background: none;
        padding: 0;
        max-height: none;
        overflow: visible;
    }

    .invoice-document {
        box-shadow: none;
        padding: 0;
    }
}
