:root {
    --bg-app: #f1f5f9;
    --bg-panel: #ffffff;
    --primary: #4f46e5; /* Indigo */
    --primary-hover: #4338ca;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-focus: #cbd5e1;
    
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.5);
    
    --danger: #ef4444;
    --success: #10b981;
    
    --radius-sm: 6px;
    --radius-md: 12px;
    
    --transition: 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
}

.hidden { display: none !important; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.w-full { width: 100%; }
.text-danger { color: var(--danger); }

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

/* Sidebar */
.sidebar {
    width: 300px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    z-index: 10;
    flex-shrink: 0;
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.logo-icon {
    color: var(--primary);
    width: 28px;
    height: 28px;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.control-group h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group h3 svg {
    width: 16px;
    height: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    background: #fff;
    color: var(--text-primary);
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.sidebar-footer {
    padding: 24px;
    border-top: 1px solid var(--border);
    background: #fff;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn svg {
    width: 18px;
    height: 18px;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-secondary {
    background: #f8fafc;
    border-color: var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: var(--border-focus);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-large {
    padding: 14px 20px;
    font-size: 1.05rem;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    color: var(--danger);
    background: #fee2e2;
}

/* Main Workspace */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.invoice-wrapper {
    background: #fff;
    width: 100%;
    max-width: 850px;
    min-height: 1100px; /* A4 aspect ratio approximation */
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
    border-radius: 4px; /* Slight radius, looks like paper */
    padding: 60px;
    position: relative;
}

/* Editable Fields */
.editable-field {
    padding: 4px 6px;
    margin: -4px -6px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: var(--transition);
    min-height: 1.5em;
    min-width: 50px;
    white-space: pre-wrap;
    word-break: break-word;
}

.editable-field:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.editable-field:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.editable-field[empty]:not(:focus):before,
[data-placeholder]:empty:before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}

.editable-field.large {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Invoice Header */
.invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 50px;
    align-items: flex-start;
}

.company-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    max-width: 50%;
}

.logo-upload-zone {
    width: 180px;
    height: 90px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.logo-upload-zone:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.05);
}

.logo-upload-zone img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    z-index: 1;
}

#logo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.remove-logo-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 10;
    background: rgba(255,255,255,0.9);
    border: 1px solid var(--border);
}

.invoice-meta {
    text-align: right;
    min-width: 250px;
}

.invoice-title {
    font-size: 3rem;
    font-weight: 300;
    letter-spacing: 4px;
    color: #e2e8f0;
    margin-bottom: 24px;
    text-transform: uppercase;
}

.meta-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px 16px;
    text-align: right;
    align-items: center;
}

.meta-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.meta-value {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.date-input {
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    border: 1px solid transparent;
    background: transparent;
    padding: 4px;
    margin: -4px;
    border-radius: 4px;
    text-align: right;
    cursor: pointer;
}

.date-input:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.date-input:focus {
    outline: none;
    background: #fff;
    border-color: var(--primary);
}

.due-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
    background: #f1f5f9;
    color: var(--text-secondary);
}

.due-badge.overdue {
    background: #fee2e2;
    color: var(--danger);
}

/* Billing Section */
.billing-section {
    margin-bottom: 50px;
}

.section-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.bill-to {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 50%;
}

/* Items Section */
.items-section {
    margin-bottom: 50px;
}

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

.items-table th {
    background: #f8fafc;
    padding: 12px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

.items-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.col-desc { width: 45%; }
.col-qty { width: 15%; text-align: right; }
.col-rate { width: 20%; text-align: right; }
.col-total { width: 15%; text-align: right; font-weight: 600; }
.col-actions { width: 5%; text-align: right; }

.items-table th.col-qty,
.items-table th.col-rate,
.items-table th.col-total {
    text-align: right;
}

.item-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    padding: 4px;
    margin: -4px;
}

.item-input:focus {
    outline: none;
    background: #f8fafc;
    border-radius: 4px;
}

.item-input.text-right {
    text-align: right;
}

/* Totals Section */
.totals-section {
    display: flex;
    justify-content: space-between;
    margin-bottom: 80px;
    align-items: flex-start;
}

.notes-area {
    width: 50%;
}

.notes-field {
    min-height: 100px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

.totals-area {
    width: 35%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 1.05rem;
}

.total-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.total-value {
    font-weight: 600;
}

.grand-total {
    font-size: 1.5rem;
    padding-top: 16px;
    border-top: 2px solid var(--text-primary);
    margin-top: 4px;
}

.grand-total .total-label {
    color: var(--text-primary);
    font-weight: 700;
}

/* Footer */
.invoice-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    animation: slideUp 0.3s forwards;
}

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

/* Print specific hiding */
@media print {
    .no-print {
        display: none !important;
    }
}
