:root {
    /* Main color scheme - highly modern */
    --primary: #2563EB; /* Vibrant Blue */
    --primary-hover: #1D4ED8;
    --primary-light: #EFF6FF;
    --secondary: #64748B;
    --accent: #F43F5E; /* Modern red for warnings */
    --bg-color: #F8FAFC;
    --surface: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --border-focus: #3B82F6;
    --error: #EF4444;
    --success: #10B981;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px 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);
    --shadow-glow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Typography */
    --font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Decorative Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    filter: blur(80px);
    border-radius: 50%;
    opacity: 0.6;
    animation: float 12s ease-in-out infinite alternate;
}

.blob-1 {
    top: -10%;
    right: -5%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, rgba(37, 99, 235, 0.05) 70%);
}

.blob-2 {
    bottom: -10%;
    left: -10%;
    width: 700px;
    height: 700px;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.1) 0%, rgba(52, 211, 153, 0.05) 70%);
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-40px, 40px) scale(1.05); }
}

/* Layout */
.page-wrapper {
    min-height: 100vh;
    padding: 4rem 1rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.form-container {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 25px 50px -12px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 1200px; /* Expanded for tabular grid rows */
    padding: 3.5rem;
    position: relative;
}

/* Header */
.form-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.icon-wrapper {
    background: linear-gradient(135deg, var(--primary), #60A5FA);
    color: white;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.4);
}

.header-text h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.03em;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.header-text .subtitle-1 {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.header-text .subtitle-2 {
    color: var(--accent); /* Light red text */
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background-color: rgba(244, 63, 94, 0.1);
    border-radius: 999px;
}

/* Typography & Layout Utilities */
.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 1.5rem;
    letter-spacing: -0.01em;
}

/* Supplier Tabs */
.supplier-tabs-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 2px solid var(--border);
    margin-bottom: 2rem;
    overflow-x: auto;
    padding-bottom: 1px;
}

.supplier-tab {
    background: transparent;
    border: none;
    padding: 0.75rem 1.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -3px; /* Pull down to overlap header border */
    transition: var(--transition);
    white-space: nowrap;
}

.supplier-tab:hover {
    color: var(--text-main);
}

.supplier-tab.active {
    color: var(--primary);
    font-weight: 600;
    border-bottom-color: var(--primary);
}

.supplier-tab-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-left: 0.5rem;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-muted);
    transition: var(--transition);
    border: none;
    background: transparent;
}

.supplier-tab-remove:hover {
    color: var(--accent);
    background-color: rgba(244, 63, 94, 0.1);
}

.supplier-tab-add {
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary);
    cursor: pointer;
    margin-left: 0.5rem;
    transition: var(--transition);
}

.supplier-tab-add:hover {
    background: var(--primary-light);
    border-style: solid;
}

.supplier-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.supplier-tab-content.active {
    display: block;
}

.form-section {
    margin-bottom: 2.5rem;
}

.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--border) 15%, var(--border) 85%, transparent 100%);
    margin: 2.5rem 0;
    border: none;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.grid-5 { display: grid; grid-template-columns: 1fr 2fr 1.5fr 1fr 1.5fr auto; gap: 0.75rem; align-items: end;}

.align-center { align-items: center; }
.align-end { align-items: flex-end; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 2rem; }

/* Inputs & Forms */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

.required {
    color: var(--accent);
}

input[type="text"],
input[type="email"],
input[type="number"],
textarea,
select.native-select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: var(--transition);
    outline: none;
    line-height: 1.5;
}

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

input::placeholder,
textarea::placeholder {
    color: #94A3B8;
}

input:hover:not([readonly]),
textarea:hover:not([readonly]),
select.native-select:hover {
    border-color: #CBD5E1;
}

input:focus:not([readonly]),
textarea:focus:not([readonly]),
select.native-select:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}

.readonly-input {
    background-color: var(--bg-color) !important;
    color: var(--text-muted) !important;
    cursor: default;
    border-color: transparent !important;
    font-weight: 500;
}

select.native-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748B'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1rem;
    padding-right: 2.5rem;
}

/* Choices.js Customization */
.choices__inner {
    background-color: var(--surface) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md) !important;
    min-height: 46px !important;
    padding: 6px 12px !important;
    font-size: 0.95rem !important;
    transition: var(--transition) !important;
    display: flex;
    align-items: center;
}

.choices.is-focused .choices__inner {
    border-color: var(--border-focus) !important;
    box-shadow: var(--shadow-glow) !important;
}

.choices__list--dropdown {
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-lg) !important;
    margin-top: 8px !important;
    z-index: 10 !important;
    padding: 0.5rem !important;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted {
    background-color: var(--primary-light) !important;
    color: var(--primary) !important;
    border-radius: var(--radius-sm);
}

/* Toggle Switch */
.toggle-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}
.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #CBD5E1;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}

input:checked + .slider { background-color: var(--primary); }
input:focus + .slider { box-shadow: var(--shadow-glow); }
input:checked + .slider:before { transform: translateX(20px); }

.toggle-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary);
    min-width: 32px;
}

/* Dynamic Rows */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px dashed var(--primary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-outline:hover {
    background: var(--primary-light);
    border-style: solid;
}

/* Dynamic Table Rows (Reference Image Style) */
.product-table-wrapper {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: visible;
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.product-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.product-table th {
    background-color: #F8FAFC;
    color: var(--text-main);
    font-weight: 600;
    padding: 0.5rem 0.5rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.product-table td {
    padding: 0;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.product-table tr:hover {
    background-color: #F8FAFC;
}

.table-input-wrapper {
    position: relative;
    width: 100%;
}

.table-input {
    width: 100%;
    padding: 0.75rem 0.5rem;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-main);
    background-color: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    transition: var(--transition);
    outline: none !important;
    margin: 0 !important;
    box-shadow: none !important;
}

.table-input:hover:not(.readonly-input),
.table-input:focus:not(.readonly-input) {
    background-color: rgba(248, 250, 252, 0.5); /* Very subtle hover */
}

.table-input:focus:not(.readonly-input) {
    box-shadow: inset 0 0 0 1px var(--primary); /* Inner highlight instead of outer ring */
}

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

.bold-text {
    font-weight: 600;
    color: var(--text-main);
}

.currency-wrapper-table::before {
    content: "R$";
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
    pointer-events: none;
}

.currency-wrapper-table input {
    padding-left: 2.25rem;
}

.action-cell {
    text-align: center;
    width: 40px;
}

.remove-row-btn-table {
    background: transparent;
    color: var(--text-muted);
    border: none;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    font-size: 1.25rem;
    line-height: 1;
    transition: var(--transition);
}

.remove-row-btn-table:hover {
    color: var(--accent);
    background-color: rgba(244, 63, 94, 0.1);
}

/* Adjust Choices inside table to look like plain inputs until focused */
.product-table .choices {
    margin-bottom: 0; /* Remove choices default bottom margin */
}

.product-table .choices__inner {
    background-color: transparent !important;
    border: none !important;
    min-height: auto !important;
    padding: 0.75rem 0.5rem !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.product-table .choices__list--dropdown {
    border-radius: 0 !important;
    border: 1px solid var(--border);
    margin-top: 0;
}

.product-table .choices:hover .choices__inner {
    background-color: rgba(248, 250, 252, 0.5) !important;
}

.product-table .choices.is-focused .choices__inner {
    background-color: transparent !important;
    box-shadow: inset 0 0 0 1px var(--primary) !important;
}

/* Table Footer Actions row */
.table-actions-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.25rem;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
}

.btn-text {
    background: transparent;
    border: none;
    color: #6366f1; /* Purple-blue tone from reference */
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    padding: 0;
}

.btn-text:hover {
    color: #4f46e5;
    text-decoration: underline;
}

.currency-wrapper { position: relative; }
.currency-wrapper::before {
    content: "R$";
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-weight: 500;
    z-index: 1;
}
.currency-wrapper input { padding-left: 2.75rem; }

.totals-row {
    background-color: var(--primary-light);
    border: 1px solid rgba(37, 99, 235, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.total-label {
    font-weight: 600;
    color: var(--text-main);
}

.total-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* Submit Area */
.form-actions {
    margin-top: 3rem;
    display: flex;
    justify-content: flex-end;
}

.btn-submit {
    background: var(--primary);
    color: white;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 1rem 2.5rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: var(--transition);
    box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.39);
}

.btn-submit:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

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

/* Modals & Loading */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.spinner-container {
    text-align: center;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary-light);
    border-bottom-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-container p {
    font-weight: 600;
    color: var(--text-main);
    font-size: 1.1rem;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 600px;
    box-shadow: var(--shadow-lg), 0 25px 50px -12px rgba(0,0,0,0.25);
    transform: scale(0.95) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 1rem;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-overlay.active .modal-card {
    transform: scale(1) translateY(0);
}

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

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.5rem;
    border-radius: 50%;
    transition: var(--transition);
}

.btn-close:hover {
    background-color: var(--bg-color);
    color: var(--text-main);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
}

.modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background-color: var(--bg-color);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.btn-secondary {
    background: white;
    color: var(--text-main);
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.4);
}

/* Receipt Card Customizations */
.receipt-card {
    max-width: 500px;
    max-height: 90vh; /* Don't exceed screen height */
    display: flex;
    flex-direction: column;
}

.receipt-header {
    text-align: center;
    padding: 2.5rem 2rem 1.5rem;
    border-bottom: 1px dashed var(--border);
}

.success-icon {
    width: 64px;
    height: 64px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.success-icon svg {
    width: 32px;
    height: 32px;
}

.receipt-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.receipt-header p {
    color: var(--text-muted);
}

.receipt-body {
    padding: 2rem;
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: center;
    overflow-y: auto; /* Enable scrolling if content overflows */
    flex: 1; /* Take up remaining space */
}

.receipt-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.receipt-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.receipt-label { color: var(--text-muted); font-size: 0.95rem; }
.receipt-value { font-weight: 600; color: var(--text-main); text-align: right; }
.receipt-value.large { font-size: 1.25rem; color: var(--primary); }

@media print {
    body * { visibility: hidden; }
    .receipt-card, .receipt-card * { visibility: visible; }
    .receipt-card { position: absolute; left: 0; top: 0; box-shadow: none; border: none; width: 100%; }
    .print-hide { display: none !important; }
}

/* Responsive */
@media (max-width: 1024px) {
    .grid-5 { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
}

@media (max-width: 768px) {
    .form-container {
        padding: 2rem 1.5rem;
        border-radius: var(--radius-lg);
    }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-actions { justify-content: stretch; }
    .btn-submit { width: 100%; justify-content: center; }
}