* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 240px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--card);
    border-radius: 12px;
    padding: 40px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 24px;
    color: var(--text);
}

.login-header p {
    color: var(--text-muted);
    margin-top: 4px;
}

.login-hint {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-muted);
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: #1e293b;
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-icon {
    font-size: 24px;
}

.nav-menu {
    list-style: none;
    padding: 16px 0;
    flex: 1;
}

.nav-menu a {
    display: block;
    padding: 12px 20px;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 14px;
}

.nav-menu a:hover,
.nav-menu a.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #94a3b8;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 18px;
    font-weight: 600;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

/* Logo Upload */
.logo-upload-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.logo-upload-section > label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.logo-upload-area {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.logo-preview {
    width: 160px;
    height: 100px;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    overflow: hidden;
    flex-shrink: 0;
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.logo-placeholder {
    width: 160px;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-shrink: 0;
}

.logo-placeholder span {
    font-size: 32px;
    margin-bottom: 4px;
}

.logo-placeholder p {
    font-size: 12px;
}

.logo-upload-controls {
    flex: 1;
}

.logo-upload-controls input[type="file"] {
    font-size: 14px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.remove-logo-label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--danger);
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table td {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table-responsive {
    overflow-x: auto;
}

.text-right {
    text-align: right;
}

.actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.inline-form {
    display: inline;
}

/* Items Table */
.items-table input,
.items-table select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
}

.items-table .line-total {
    font-weight: 600;
    white-space: nowrap;
}

.grand-total-row td {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    border-top: 2px solid var(--border);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

/* Invoice Preview */
.invoice-preview {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    overflow: hidden;
}

.invoice-document {
    width: 100%;
    max-width: 210mm;
    margin: 0 auto;
    font-family: 'Segoe UI', Georgia, serif;
    font-size: 11px;
    color: #2d3748;
    background: #fff;
    line-height: 1.4;
    position: relative;
}

/* Letterhead */
.lh-accent {
    height: 4px;
    background: linear-gradient(90deg, #1a365d 0%, #2b6cb0 50%, #1a365d 100%);
    margin-bottom: 14px;
}

.lh-header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding-bottom: 12px;
}

.lh-header-left {
    flex-shrink: 0;
}

.lh-logo {
    display: block;
    max-height: 64px;
    max-width: 160px;
    object-fit: contain;
}

.lh-header-right {
    flex: 1;
    text-align: right;
    border-left: 2px solid #e2e8f0;
    padding-left: 20px;
}

.lh-company-name {
    font-size: 13px;
    font-weight: 700;
    color: #1a365d;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
    line-height: 1.3;
}

.lh-company-info {
    font-size: 10px;
    color: #4a5568;
    line-height: 1.5;
}

.lh-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.lh-divider-line {
    flex: 1;
    height: 1px;
    background: #cbd5e0;
}

.lh-divider-diamond {
    width: 6px;
    height: 6px;
    background: #2b6cb0;
    transform: rotate(45deg);
    flex-shrink: 0;
}

.lh-doc-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 14px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #2b6cb0;
}

.lh-doc-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    color: #1a365d;
}

.lh-doc-meta {
    font-size: 10px;
    color: #4a5568;
}

.lh-doc-meta span {
    margin-left: 16px;
}

.lh-doc-meta span:first-child {
    margin-left: 0;
}

.lh-customer {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 2px;
}

.lh-customer-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #2b6cb0;
    margin-bottom: 4px;
}

.lh-customer-name {
    font-size: 12px;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 3px;
}

.lh-customer-info {
    font-size: 10px;
    color: #4a5568;
    line-height: 1.5;
}

.inv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    margin-bottom: 8px;
}

.inv-table thead {
    display: table-header-group;
}

.inv-table th {
    padding: 5px 6px;
    text-align: left;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #fff;
    background: #1a365d;
    border: none;
}

.inv-table th:first-child {
    border-radius: 2px 0 0 0;
}

.inv-table th:last-child {
    border-radius: 0 2px 0 0;
}

.inv-table td {
    padding: 4px 6px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: top;
    color: #2d3748;
}

.inv-table tbody tr:nth-child(even) td {
    background: #f7fafc;
}

.inv-table tbody tr:last-child td {
    border-bottom: 1px solid #cbd5e0;
}

.inv-table th:nth-child(1),
.inv-table td:nth-child(1) { width: 24px; text-align: center; }
.inv-table th:nth-child(3),
.inv-table td:nth-child(3),
.inv-table th:nth-child(4),
.inv-table td:nth-child(4),
.inv-table th:nth-child(5),
.inv-table td:nth-child(5),
.inv-table th:nth-child(6),
.inv-table td:nth-child(6) { text-align: center; white-space: nowrap; }
.inv-table th:nth-child(7),
.inv-table td:nth-child(7) { text-align: right; white-space: nowrap; font-weight: 600; }

.td-desc {
    word-break: break-word;
}

.inv-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-top: 6px;
    page-break-inside: avoid;
}

.inv-notes {
    flex: 1;
    font-size: 10px;
    color: #4a5568;
    line-height: 1.4;
    max-width: 60%;
    padding: 8px 10px;
    border-left: 2px solid #ecc94b;
    background: #fffff0;
}

.inv-totals {
    border-collapse: collapse;
    font-size: 10px;
    margin-left: auto;
    min-width: 190px;
}

.inv-totals td {
    padding: 3px 0 3px 12px;
    text-align: right;
    white-space: nowrap;
}

.inv-totals td:first-child {
    color: #718096;
    padding-left: 0;
    padding-right: 20px;
}

.inv-total-grand td {
    font-weight: 700;
    font-size: 11px;
    color: #1a365d;
    padding-top: 5px;
    border-top: 2px solid #1a365d;
}

.lh-footer {
    margin-top: 16px;
    page-break-inside: avoid;
}

.lh-footer-line {
    height: 2px;
    background: linear-gradient(90deg, transparent, #2b6cb0, transparent);
    margin-bottom: 8px;
}

.lh-footer-text {
    font-size: 9px;
    color: #4a5568;
    text-align: center;
    line-height: 1.5;
    margin-bottom: 6px;
}

.lh-footer-text strong {
    color: #1a365d;
}

.inv-foot {
    font-size: 8px;
    color: #a0aec0;
    text-align: center;
    font-style: italic;
}

/* Print */
@media print {
    @page {
        size: A4 portrait;
        margin: 10mm 12mm;
    }

    body {
        background: #fff;
        margin: 0;
        padding: 0;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .sidebar,
    .no-print,
    .page-header {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .invoice-preview {
        box-shadow: none;
        padding: 0;
        border-radius: 0;
    }

    .invoice-document {
        max-width: 100%;
        width: 100%;
    }

    .inv-table tr {
        page-break-inside: avoid;
    }

    .inv-bottom,
    .lh-footer {
        page-break-inside: avoid;
    }
}

.print-page {
    padding: 0;
    margin: 0;
    background: #fff;
}

.print-page .invoice-document {
    max-width: 100%;
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .lh-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .lh-header-right {
        text-align: left;
        border-left: none;
        padding-left: 0;
        border-top: 1px solid #e2e8f0;
        padding-top: 10px;
        width: 100%;
    }

    .lh-doc-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .lh-doc-meta span {
        margin-left: 0;
        display: block;
    }

    .inv-bottom {
        flex-direction: column;
    }

    .inv-notes {
        max-width: 100%;
    }
}
