/* ===== CSS Variables ===== */
:root {
    --primary: #1a1a2e;
    --primary-light: #16213e;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --success: #00d9a5;
    --background: #0f0f1a;
    --surface: #1a1a2e;
    --surface-light: #252542;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b80;
    --border: #2d2d44;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-lg: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== App Container ===== */
.app-container {
    display: grid;
    grid-template-columns: 480px 1fr;
    min-height: 100vh;
}

/* ===== Form Panel ===== */
.form-panel {
    background: var(--surface);
    padding: 40px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    max-height: 100vh;
}

.form-header {
    margin-bottom: 40px;
    text-align: center;
}

.form-logo {
    width: 60px;
    height: auto;
    margin-bottom: 16px;
    filter: brightness(1.1);
}

.form-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.form-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Form Groups ===== */
/* ===== Smart Import Section ===== */
.smart-import-section {
    margin-bottom: 32px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.smart-import-header {
    padding: 12px 16px;
    background: rgba(233, 69, 96, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.smart-import-header h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-paste {
    background: var(--surface);
    color: var(--success);
    border: 1px solid var(--success);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-paste:hover {
    background: var(--success);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 217, 165, 0.2);
}

.smart-import-body {
    padding: 16px;
}

.smart-import-textarea {
    width: 100%;
    height: 80px;
    padding: 11px;
    background: var(--primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 12.5px;
    font-family: inherit;
    resize: none;
    margin-bottom: 12px;
    transition: var(--transition);
}

.smart-import-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.smart-import-footer {
    display: flex;
    justify-content: flex-end;
}

.btn-smart-import {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-smart-import:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"] {
    width: 100%;
    padding: 14px 16px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* ===== Input with Prefix/Suffix ===== */
.input-with-prefix {
    display: flex;
    align-items: center;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.input-with-prefix:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.input-prefix,
.btn-refresh-num {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0 10px;
    cursor: pointer;
    font-size: 16px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-refresh-num:hover {
    color: var(--accent);
    transform: rotate(180deg);
}

.input-suffix {
    padding: 14px 12px;
    background: var(--primary);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.input-with-prefix input {
    flex: 1;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.input-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Radio Group ===== */
.radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.radio-option {
    position: relative;
    cursor: pointer;
}

.radio-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    background: var(--surface-light);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
    font-weight: 500;
}

.radio-icon {
    font-size: 20px;
}

.radio-option input:checked+.radio-label {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.radio-option:hover .radio-label {
    border-color: var(--text-muted);
}

/* ===== Calculated Field ===== */
.calculated-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.calculated-field span:first-child {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.auto-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    background: var(--success);
    color: var(--primary);
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Total Group ===== */
.total-group {
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.1), rgba(233, 69, 96, 0.05));
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid rgba(233, 69, 96, 0.3);
}

.total-display {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

/* ===== Form Row ===== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ===== Form Actions ===== */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(233, 69, 96, 0.4);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--primary-light);
    color: var(--text-primary);
}

/* ===== Preview Panel ===== */
.preview-panel {
    background: var(--primary-light);
    padding: 40px;
    overflow-y: auto;
    max-height: 100vh;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.preview-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
}

.preview-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ===== Invoice Preview Container ===== */
.preview-container {
    display: flex;
    justify-content: center;
}

.invoice-preview {
    width: 100%;
    max-width: 650px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.invoice-content {
    padding: 48px;
    color: #1a1a1a;
}

/* ===== Invoice Header ===== */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.invoice-logo img {
    width: 50px;
    height: auto;
}

.invoice-title {
    text-align: right;
}

.invoice-title h1 {
    font-size: 32px;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 4px;
    letter-spacing: 2px;
}

.invoice-number {
    font-size: 13px;
    color: #666;
}

/* ===== Invoice Info ===== */
.invoice-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid #eee;
}

.invoice-from {
    flex: 1;
}

.company-name {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 16px;
}

.bill-to .label {
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}

.bill-to .value {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
}

.invoice-details {
    text-align: right;
}

.detail-row {
    margin-bottom: 8px;
    font-size: 13px;
}

.detail-row .label {
    color: #888;
    margin-right: 8px;
}

.detail-row .value {
    color: #1a1a1a;
    font-weight: 500;
}

.detail-row .value.highlight {
    color: var(--accent);
}

.balance-row {
    margin-top: 16px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 8px;
}

.balance-row .label {
    font-weight: 600;
}

.balance-row .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent) !important;
}

/* ===== Invoice Table ===== */
.invoice-table {
    margin-bottom: 32px;
}

.table-header {
    display: grid;
    grid-template-columns: 2fr 0.8fr 1fr 1fr;
    gap: 12px;
    padding: 14px 16px;
    background: #2d2d44;
    color: white;
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table-body {
    border: 1px solid #eee;
    border-top: none;
}

.table-row {
    display: grid;
    grid-template-columns: 2fr 0.8fr 1fr 1fr;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}

.table-row:last-child {
    border-bottom: none;
}

.col-item {
    font-weight: 500;
    color: #1a1a1a;
}

.col-qty,
.col-rate,
.col-amount {
    text-align: right;
    color: #555;
}

.table-footer {
    display: flex;
    justify-content: flex-end;
    gap: 24px;
    padding: 16px;
    border: 1px solid #eee;
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.total-label {
    font-size: 14px;
    color: #888;
}

.total-value {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
}

/* ===== Invoice Notes ===== */
.invoice-notes {
    margin-bottom: 24px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.notes-title {
    font-size: 12px;
    font-weight: 600;
    color: #888;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.bank-info {
    font-size: 13px;
    color: #1a1a1a;
    line-height: 1.8;
}

.bank-info strong {
    color: #1a1a1a;
}

.transfer-note {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #ddd;
    font-weight: 500;
}

/* ===== Invoice Terms ===== */
.invoice-terms {
    font-size: 11px;
    color: #666;
    line-height: 1.7;
}

.terms-title {
    font-weight: 600;
    color: #888;
    margin-bottom: 8px;
}

.invoice-terms ol {
    padding-left: 16px;
}

.invoice-terms li {
    margin-bottom: 8px;
}

.invoice-terms strong {
    color: #555;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .form-panel {
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .preview-panel {
        max-height: none;
    }
}

@media (max-width: 600px) {

    .form-panel,
    .preview-panel {
        padding: 24px;
    }

    .radio-group {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .invoice-content {
        padding: 24px;
    }

    .table-header,
    .table-row {
        grid-template-columns: 1.5fr 0.5fr 1fr 1fr;
        font-size: 11px;
    }
}

/* ===== Print Styles ===== */
@media print {
    body {
        background: white;
    }

    .form-panel,
    .preview-header {
        display: none;
    }

    .preview-panel {
        padding: 0;
        background: white;
    }

    .invoice-preview {
        box-shadow: none;
        border-radius: 0;
    }
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: var(--transition);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    margin-bottom: 24px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-description {
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-body {
    margin-bottom: 32px;
    display: grid;
    gap: 16px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Items Row Styles */
.item-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: flex-start;
}

.item-row .input-wrapper {
    flex: 1;
}

.item-row .input-amount-wrapper {
    flex: 0 0 140px;
}

.item-row input {
    width: 100%;
}

.btn-remove-item {
    background: #ffebee;
    color: #e94560;
    border: 1px solid #ffcdd2;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    margin-top: 1px;
    /* Align with input */
}

.btn-remove-item:hover {
    background: #ffcdd2;
}

.btn-text {
    background: none;
    border: none;
    color: #00d9a5;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-text:hover {
    background: rgba(0, 217, 165, 0.1);
}

/* ===== Checkbox ===== */
.checkbox-group {
    margin-bottom: 24px;
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 32px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
    font-weight: 500;
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    height: 20px;
    width: 20px;
    background-color: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: var(--transition);
}

.checkbox-container:hover input~.checkmark {
    border-color: var(--text-muted);
}

.checkbox-container input:checked~.checkmark {
    background-color: var(--accent);
    border-color: var(--accent);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.checkbox-container input:checked~.checkmark:after {
    display: block;
}

.checkbox-container .checkmark:after {
    left: 7px;
    top: 3px;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}