/* ============================================================
Design System & Interface Styles (AlmiCode Theme)
============================================================ */
:root {
--bg-primary: #0a0b10;
--bg-secondary: #0f1018;
--bg-card: rgba(16, 18, 30, 0.75);
--bg-card-hover: rgba(22, 25, 42, 0.85);
--bg-glass: rgba(255, 255, 255, 0.03);
--border-glass: rgba(255, 255, 255, 0.08);
--border-focus: #00e5ff;

--accent-cyan: #00e5ff;
--accent-violet: #8b5cf6;
--accent-pink: #d946ef;
--accent-green: #10b981;
--accent-red: #ef4444;

--text-primary: #eaedf3;
--text-secondary: #9aa1b9;
--text-muted: #5e6482;

--gradient-main: linear-gradient(135deg, #00e5ff, #8b5cf6);
--gradient-card: linear-gradient(135deg, rgba(0, 229, 255, 0.05), rgba(139, 92, 246, 0.05));

--font-display: 'Outfit', sans-serif;
--font-body: 'Inter', sans-serif;
--font-mono: 'JetBrains Mono', monospace;

--radius-sm: 8px;
--radius-md: 12px;
--radius-lg: 18px;
--radius-full: 9999px;
}

*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

/* Global Slim & Elegant Scrollbars (Horizontal & Vertical) */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 229, 255, 0.35) rgba(255, 255, 255, 0.02);
}

*::-webkit-scrollbar {
  width: 6px;
  height: 5px;
}

*::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 9999px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.35), rgba(139, 92, 246, 0.35));
  border-radius: 9999px;
  border: 1px solid rgba(0, 229, 255, 0.12);
  transition: all 0.2s ease;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, rgba(0, 229, 255, 0.75), rgba(139, 92, 246, 0.75));
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.45);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

body {
background-color: var(--bg-primary);
color: var(--text-primary);
font-family: var(--font-body);
line-height: 1.5;
min-height: 100vh;
display: flex;
flex-direction: column;
background-image: 
radial-gradient(circle at 15% 15%, rgba(0, 229, 255, 0.04) 0%, transparent 40%),
radial-gradient(circle at 85% 70%, rgba(139, 92, 246, 0.04) 0%, transparent 40%);
padding-top: 56px;
}

/* Fixed Unified Top Navigation */
#tools-navbar {
position: fixed !important;
top: 0 !important;
left: 0 !important;
right: 0 !important;
width: 100% !important;
z-index: 1000 !important;
}

.top-nav {
position: relative;
background: rgba(10, 11, 16, 0.85);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-bottom: 1px solid var(--border-glass);
padding: 0.85rem 1.5rem;
}

.nav-container {
max-width: 1280px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
}

.brand-link {
display: flex;
align-items: center;
gap: 0.75rem;
text-decoration: none;
color: var(--text-primary);
font-family: var(--font-display);
font-weight: 700;
font-size: 1.25rem;
}

.brand-link img {
width: 32px;
height: 32px;
border-radius: 8px;
object-fit: cover;
}

.brand-badge {
background: rgba(0, 229, 255, 0.12);
color: var(--accent-cyan);
border: 1px solid rgba(0, 229, 255, 0.25);
padding: 0.2rem 0.6rem;
border-radius: var(--radius-full);
font-size: 0.72rem;
font-weight: 600;
letter-spacing: 0.5px;
text-transform: uppercase;
}

.nav-actions {
display: flex;
align-items: center;
gap: 0.75rem;
}

.btn-nav-outline {
color: var(--text-secondary);
border: 1px solid var(--border-glass);
padding: 0.45rem 0.9rem;
border-radius: var(--radius-md);
font-size: 0.85rem;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 0.4rem;
transition: all 0.2s ease;
background: var(--bg-glass);
}

.btn-nav-outline:hover {
color: var(--text-primary);
border-color: rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.06);
}

/* App Header / Hero */
.app-hero {
text-align: center;
padding: 2.5rem 1rem 1.5rem;
max-width: 860px;
margin: 0 auto;
}

.hero-tag {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.35rem 0.9rem;
background: rgba(0, 229, 255, 0.08);
border: 1px solid rgba(0, 229, 255, 0.2);
border-radius: var(--radius-full);
color: var(--accent-cyan);
font-size: 0.8rem;
font-weight: 600;
margin-bottom: 1rem;
}

.app-hero h1 {
font-family: var(--font-display);
font-size: clamp(1.8rem, 4vw, 2.5rem);
font-weight: 800;
margin-bottom: 0.6rem;
letter-spacing: -0.5px;
}

.gradient-text {
background: var(--gradient-main);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

.app-hero p {
color: var(--text-secondary);
font-size: 1rem;
max-width: 680px;
margin: 0 auto;
}

/* Main Container & Layout */
.main-wrapper {
max-width: 1280px;
margin: 0 auto;
padding: 0 1.25rem 4rem;
flex: 1;
width: 100%;
}

.grid-container {
display: grid;
grid-template-columns: 1fr;
gap: 1.75rem;
min-width: 0;
}

@media (min-width: 1024px) {
.grid-container {
grid-template-columns: 1.15fr 0.85fr;
align-items: start;
}
}

/* Card Panels */
.panel-card {
background: var(--bg-card);
border: 1px solid var(--border-glass);
border-radius: var(--radius-lg);
padding: 1.5rem;
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(12px);
min-width: 0;
}

.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 0.5rem 0.65rem;
margin-bottom: 1.25rem;
padding-bottom: 0.85rem;
border-bottom: 1px solid var(--border-glass);
}

.panel-title {
font-family: var(--font-display);
font-size: 1.15rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 0.6rem;
color: var(--text-primary);
min-width: 0;
}

.panel-title svg {
color: var(--accent-cyan);
flex-shrink: 0;
}

.quick-actions {
display: flex;
align-items: center;
gap: 0.5rem;
flex-shrink: 0;
}

@media screen and (max-width: 580px) {
  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .panel-title {
    font-size: 1.05rem;
    width: 100%;
  }
  .quick-actions {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
  }
}

.btn-action-sm {
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--border-glass);
color: var(--text-secondary);
padding: 0.35rem 0.7rem;
border-radius: var(--radius-sm);
font-size: 0.78rem;
font-weight: 500;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 0.35rem;
transition: all 0.2s ease;
}

.btn-action-sm:hover {
background: rgba(255, 255, 255, 0.1);
color: var(--text-primary);
border-color: rgba(255, 255, 255, 0.2);
}

/* Sub-sections within form */
.form-section-title {
font-family: var(--font-display);
font-size: 0.92rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.8px;
color: var(--accent-cyan);
margin: 1.25rem 0 0.75rem;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 0.4rem;
}

.form-grid-2 {
display: grid;
grid-template-columns: 1fr;
gap: 0.75rem;
}

@media (min-width: 640px) {
.form-grid-2 {
grid-template-columns: 1fr 1fr;
}
}

.form-grid-3 {
display: grid;
grid-template-columns: 1fr;
gap: 0.75rem;
}

@media (min-width: 640px) {
.form-grid-3 {
grid-template-columns: 2fr 1fr 1fr;
}
}

.form-group {
display: flex;
flex-direction: column;
gap: 0.35rem;
margin-bottom: 0.65rem;
}

.form-group label {
font-size: 0.8rem;
font-weight: 500;
color: var(--text-secondary);
}

.input-row {
position: relative;
display: flex;
align-items: center;
}

input[type="text"],
input[type="number"],
select {
width: 100%;
background: rgba(0, 0, 0, 0.35);
border: 1px solid var(--border-glass);
color: var(--text-primary);
padding: 0.65rem 0.85rem;
border-radius: var(--radius-sm);
font-size: 0.88rem;
font-family: var(--font-body);
transition: all 0.2s ease;
outline: none;
}

input:focus, select:focus {
border-color: var(--accent-cyan);
box-shadow: 0 0 0 3px rgba(0, 229, 255, 0.15);
}

.cep-loading {
position: absolute;
right: 0.75rem;
font-size: 0.75rem;
color: var(--accent-cyan);
display: none;
animation: pulse 1s infinite;
}

@keyframes pulse {
0%, 100% { opacity: 0.4; }
50% { opacity: 1; }
}

/* Switch checkbox */
.switch-label {
display: inline-flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
font-size: 0.78rem;
color: var(--text-secondary);
}

.switch-label input[type="checkbox"] {
accent-color: var(--accent-cyan);
width: 15px;
height: 15px;
cursor: pointer;
}



.btn-add-item {
margin-top: 0.6rem;
background: rgba(0, 229, 255, 0.08);
border: 1px dashed rgba(0, 229, 255, 0.3);
color: var(--accent-cyan);
padding: 0.6rem 1rem;
border-radius: var(--radius-sm);
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
transition: all 0.2s ease;
}

.btn-add-item:hover {
background: rgba(0, 229, 255, 0.15);
border-color: var(--accent-cyan);
}

/* Print & Preview Section */
.preview-sticky {
position: sticky;
top: 5rem;
}

.preview-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
gap: 0.75rem;
flex-wrap: wrap;
}

.btn-primary-print {
background: var(--gradient-main);
color: #07090e;
border: none;
padding: 0.75rem 1.4rem;
border-radius: var(--radius-md);
font-size: 0.95rem;
font-weight: 700;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 0.5rem;
box-shadow: 0 4px 18px rgba(0, 229, 255, 0.3);
transition: all 0.25s ease;
font-family: var(--font-display);
}

.btn-primary-print:hover {
transform: translateY(-2px);
box-shadow: 0 6px 24px rgba(0, 229, 255, 0.45);
}

.btn-secondary {
background: rgba(255, 255, 255, 0.06);
border: 1px solid var(--border-glass);
color: var(--text-primary);
padding: 0.7rem 1.1rem;
border-radius: var(--radius-md);
font-size: 0.88rem;
font-weight: 600;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 0.45rem;
transition: all 0.2s;
}

.btn-secondary:hover {
background: rgba(255, 255, 255, 0.12);
}

/* Document Sheet Preview on Screen */
.sheet-preview-container {
background: #ffffff;
color: #111111;
border-radius: var(--radius-sm);
padding: 1.5rem;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
font-family: Arial, Helvetica, sans-serif;
font-size: 9.5pt;
line-height: 1.25;
overflow-y: auto;
max-height: 720px;
}

/* Official Correios Document Styling (Used in Screen Preview & @media print) */
.correios-doc {
width: 100%;
border-collapse: collapse;
color: #000;
}

.correios-doc table {
width: 100%;
border-collapse: collapse;
}

.correios-header {
text-align: center;
border: 1.5px solid #000;
padding: 6px 4px;
font-weight: bold;
font-size: 13pt;
letter-spacing: 0.5px;
background: #f3f3f3;
text-transform: uppercase;
margin-bottom: 2px;
}

.box-container {
border: 1.5px solid #000;
margin-bottom: 2px;
padding: 4px 6px;
}

.box-title {
font-weight: bold;
font-size: 8.5pt;
text-transform: uppercase;
border-bottom: 1px solid #000;
padding-bottom: 2px;
margin-bottom: 4px;
display: flex;
justify-content: space-between;
}

.doc-grid-row {
display: flex;
flex-wrap: wrap;
margin-bottom: 3px;
font-size: 8.5pt;
}

.doc-field {
padding: 2px 4px;
box-sizing: border-box;
}

.doc-label {
font-weight: bold;
text-transform: uppercase;
font-size: 7.5pt;
color: #222;
display: block;
margin-bottom: 1px;
}

.doc-val {
min-height: 14px;
word-break: break-word;
color: #000;
}

/* Goods Table */
.doc-table {
width: 100%;
border: 1.5px solid #000;
border-collapse: collapse;
margin-bottom: 2px;
}

.doc-table th, .doc-table td {
border: 1px solid #000;
padding: 3px 5px;
font-size: 8pt;
}

.doc-table th {
background: #f0f0f0;
font-weight: bold;
text-transform: uppercase;
text-align: left;
}

.doc-table .text-center { text-align: center; }
.doc-table .text-right { text-align: right; }

/* Totals */
.doc-totals {
border: 1.5px solid #000;
border-top: none;
margin-bottom: 2px;
}

/* Legal text */
.doc-legal {
border: 1.5px solid #000;
padding: 4px 6px;
font-size: 7.2pt;
text-align: justify;
margin-bottom: 2px;
line-height: 1.2;
}

.doc-signature-block {
border: 1.5px solid #000;
border-top: none;
padding: 8px 6px 4px;
display: flex;
justify-content: space-between;
align-items: flex-end;
font-size: 8pt;
margin-bottom: 4px;
}

.sig-line {
border-top: 1px solid #000;
width: 250px;
text-align: center;
padding-top: 3px;
font-size: 7.5pt;
text-transform: uppercase;
}

.doc-alert {
font-size: 6.8pt;
border: 1px dashed #666;
padding: 3px 5px;
color: #333;
text-align: justify;
line-height: 1.15;
}

/* Footer Info & AlmiCode Banner */
.site-footer {
border-top: 1px solid var(--border-glass);
padding: 2.5rem 1.5rem 2rem;
margin-top: 3rem;
background: rgba(10, 11, 16, 0.6);
text-align: center;
}

.promo-box {
max-width: 860px;
margin: 0 auto 2rem;
background: var(--gradient-card);
border: 1px solid rgba(0, 229, 255, 0.2);
border-radius: var(--radius-md);
padding: 1.25rem 1.75rem;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
text-align: left;
}

.promo-box h4 {
font-family: var(--font-display);
font-size: 1.05rem;
color: var(--text-primary);
margin-bottom: 0.2rem;
}

.promo-box p {
color: var(--text-secondary);
font-size: 0.85rem;
}

.btn-promo {
background: var(--gradient-main);
color: #07090e;
padding: 0.55rem 1.1rem;
border-radius: var(--radius-sm);
font-weight: 700;
font-size: 0.85rem;
text-decoration: none;
white-space: nowrap;
}

/* Modal de Confirmação de Limpar */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(5, 6, 10, 0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
z-index: 10000;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
opacity: 0;
pointer-events: none;
transition: opacity 0.25s ease, visibility 0.25s ease;
visibility: hidden;
}

.modal-overlay.active {
opacity: 1;
pointer-events: auto;
visibility: visible;
}

.modal-card-confirm {
background: #11131c;
background-image: radial-gradient(circle at 50% 0%, rgba(239, 68, 68, 0.1) 0%, transparent 70%);
border: 1px solid var(--border-glass);
border-radius: var(--radius-lg);
padding: 2rem 1.75rem 1.5rem;
max-width: 460px;
width: 100%;
text-align: center;
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
transform: scale(0.92) translateY(10px);
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card-confirm {
transform: scale(1) translateY(0);
}

.modal-confirm-icon {
width: 56px;
height: 56px;
border-radius: var(--radius-full);
background: rgba(239, 68, 68, 0.12);
border: 1px solid rgba(239, 68, 68, 0.3);
color: #ef4444;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 1.25rem;
}

.modal-card-confirm h3 {
font-family: var(--font-display);
font-size: 1.35rem;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 0.5rem;
}

.modal-card-confirm p {
font-size: 0.9rem;
color: var(--text-secondary);
margin-bottom: 1.5rem;
}

.modal-confirm-options {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-bottom: 1.25rem;
text-align: left;
}

.btn-clean-opt {
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--border-glass);
border-radius: var(--radius-md);
padding: 0.9rem 1.1rem;
cursor: pointer;
display: flex;
flex-direction: column;
gap: 0.25rem;
transition: all 0.2s ease;
color: var(--text-primary);
}

.btn-clean-opt:hover {
background: rgba(255, 255, 255, 0.08);
border-color: rgba(255, 255, 255, 0.25);
transform: translateY(-1px);
}

.btn-clean-opt strong {
font-size: 0.95rem;
font-family: var(--font-display);
display: flex;
align-items: center;
gap: 0.45rem;
}

.btn-clean-opt span {
font-size: 0.8rem;
color: var(--text-secondary);
line-height: 1.4;
}

.btn-clean-all strong {
color: #ef4444;
}

.btn-clean-all:hover {
border-color: rgba(239, 68, 68, 0.4);
background: rgba(239, 68, 68, 0.06);
}

.btn-clean-dest strong {
color: var(--accent-cyan);
}

.btn-clean-dest:hover {
border-color: rgba(0, 229, 255, 0.4);
background: rgba(0, 229, 255, 0.06);
}

.modal-confirm-footer {
display: flex;
justify-content: center;
}

.btn-modal-cancel {
background: transparent;
border: 1px solid var(--border-glass);
color: var(--text-secondary);
padding: 0.6rem 1.4rem;
border-radius: var(--radius-sm);
font-size: 0.88rem;
cursor: pointer;
transition: all 0.2s;
}

.btn-modal-cancel:hover {
color: var(--text-primary);
border-color: rgba(255, 255, 255, 0.3);
}

/* Smart Form Grids */
.form-grid-2 {
display: grid;
grid-template-columns: 1fr;
gap: 0.65rem;
}
@media (min-width: 580px) {
.form-grid-2 {
grid-template-columns: 1fr 1fr;
}
}

.form-row-cep-uf {
display: grid;
grid-template-columns: 1.6fr 1fr;
gap: 0.65rem;
}

.form-row-cidade-bairro {
display: grid;
grid-template-columns: 1.25fr 1fr;
gap: 0.65rem;
}

/* Mobile Tabs Container */
.mobile-tabs-container {
display: none;
width: 100%;
justify-content: center;
margin: 1.15rem auto 0.25rem;
}

.preview-sticky .mobile-tabs-container {
margin: 0.75rem auto 0.85rem;
}

.mobile-view-tabs {
display: flex;
background: rgba(14, 16, 26, 0.95);
border: 1px solid var(--border-glass);
border-radius: var(--radius-full);
padding: 0.25rem;
max-width: 440px;
width: 100%;
gap: 0.35rem;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

@media screen and (max-width: 1023px) {
.mobile-tabs-container {
display: flex;
}

.preview-sticky {
position: static;
}

body.view-sheet .form-panel {
display: none !important;
}

body.view-sheet .app-hero {
display: none !important;
}

body.view-sheet .site-footer {
display: none !important;
}

body.view-form .preview-sticky {
display: none !important;
}

.app-hero {
padding: 1.75rem 0.75rem 0.85rem !important;
}

body.view-form .main-wrapper {
padding: 0.5rem 0.65rem 3rem !important;
}

body.view-sheet .main-wrapper {
padding: 1.25rem 0.45rem 2rem !important;
}

body.view-sheet .panel-card {
padding: 0.5rem 0.35rem 1rem !important;
background: rgba(14, 16, 26, 0.98) !important;
}

.preview-toolbar {
display: none !important;
}

.print-hint-banner {
display: none !important;
}

.panel-card {
padding: 1.15rem 0.9rem !important;
border-radius: 16px !important;
}

.app-hero h1 {
font-size: 1.45rem !important;
margin-bottom: 0.3rem !important;
}

.app-hero p {
font-size: 0.86rem !important;
line-height: 1.45 !important;
}

input[type="text"],
input[type="number"],
select {
font-size: 16px !important; /* Prevents iOS Safari auto-zoom */
min-height: 44px !important;
border-radius: 8px !important;
}
}

.mobile-tab-btn {
flex: 1;
background: transparent;
border: none;
color: var(--text-secondary);
padding: 0.55rem 0.75rem;
border-radius: var(--radius-full);
font-family: var(--font-display);
font-size: 0.85rem;
font-weight: 600;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.45rem;
transition: all 0.2s ease;
white-space: nowrap;
}

.mobile-tab-btn.active {
background: var(--gradient-main);
color: #07090e;
box-shadow: 0 4px 15px rgba(0, 229, 255, 0.25);
}

.tab-badge {
background: rgba(0, 229, 255, 0.15);
color: var(--accent-cyan);
font-size: 0.72rem;
font-weight: 700;
padding: 0.1rem 0.45rem;
border-radius: 9999px;
line-height: 1.2;
}

.mobile-tab-btn.active .tab-badge {
background: rgba(7, 9, 14, 0.25);
color: #07090e;
}

/* Button at bottom of form to advance to A4 preview */
.form-bottom-nav {
margin-top: 1.5rem;
padding-top: 1rem;
border-top: 1px solid var(--border-glass);
}

.btn-goto-sheet {
background: var(--gradient-main);
color: #07090e;
border: none;
padding: 0.85rem 1.4rem;
border-radius: var(--radius-md);
font-family: var(--font-display);
font-size: 0.95rem;
font-weight: 700;
cursor: pointer;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
box-shadow: 0 6px 20px rgba(0, 229, 255, 0.3);
transition: all 0.2s ease;
}

.btn-goto-sheet:hover {
transform: translateY(-2px);
box-shadow: 0 8px 26px rgba(0, 229, 255, 0.45);
}


/* Scroll Hint Bar (OUTSIDE the PDF scroll container) */
.sheet-scroll-hint {
display: flex;
align-items: center;
gap: 0.45rem;
background: rgba(0, 229, 255, 0.06);
border: 1px solid rgba(0, 229, 255, 0.18);
border-radius: var(--radius-sm);
padding: 0.45rem 0.75rem;
font-size: 0.76rem;
color: var(--accent-cyan);
margin-bottom: 0.75rem;
width: 100%;
}

.sheet-scroll-hint svg {
flex-shrink: 0;
color: var(--accent-cyan);
}

/* Independent Scroll Container ONLY for the PDF Sheet */
.sheet-scroll-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  position: relative;
  margin-bottom: 1rem;
}

.sheet-preview-container {
  background: #ffffff;
  color: #111111;
  border-radius: var(--radius-sm);
  padding: 1.25rem 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 9pt;
  line-height: 1.2;
  box-sizing: border-box;
  width: 794px;
  min-width: 794px;
  margin: 0;
  transform-origin: top left;
}

/* On screens narrower than the A4 width, the JS handles scaling dynamically */
@media screen and (max-width: 1023px) {
  .sheet-scroll-container {
    overflow: visible;
  }
}

@media screen and (min-width: 1024px) {
  .mobile-tabs-container {
    display: none !important;
  }

  .sheet-scroll-hint {
    display: none !important;
  }

  .sheet-bottom-actions {
    display: none !important;
  }

  .btn-goto-sheet {
    display: none !important;
  }

  .sheet-preview-container {
    width: 100% !important;
    min-width: 100% !important;
    max-height: 750px;
    overflow-y: auto;
    padding: 1.5rem;
    margin: 0 auto;
    transform: none;
  }
}

.correios-doc {
  width: 100%;
  min-width: 100%;
}

/* Bottom actions after A4 sheet */
.sheet-bottom-actions {
margin-top: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.65rem;
align-items: center;
}

.btn-primary-print-full {
background: var(--gradient-main);
color: #07090e;
border: none;
padding: 0.85rem 1.5rem;
border-radius: var(--radius-md);
font-family: var(--font-display);
font-size: 1rem;
font-weight: 700;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
box-shadow: 0 4px 18px rgba(0, 229, 255, 0.35);
transition: all 0.2s ease;
width: 100%;
}

.btn-primary-print-full:hover {
transform: translateY(-2px);
box-shadow: 0 6px 24px rgba(0, 229, 255, 0.5);
}

.btn-back-form-subtle {
background: transparent;
border: none;
color: var(--text-secondary);
font-size: 0.85rem;
cursor: pointer;
padding: 0.5rem 1rem;
text-decoration: underline;
transition: color 0.2s;
}

.btn-back-form-subtle:hover {
color: var(--accent-cyan);
}

/* CEP status badges */
.cep-status-tag {
font-size: 0.75rem;
padding: 0.2rem 0.5rem;
border-radius: var(--radius-sm);
margin-left: 0.5rem;
display: none;
font-weight: 500;
}

.cep-status-tag.loading {
display: inline-block;
color: var(--accent-cyan);
background: rgba(0, 229, 255, 0.1);
animation: pulse 1s infinite;
}

.cep-status-tag.success {
display: inline-block;
color: #10b981;
background: rgba(16, 185, 129, 0.12);
border: 1px solid rgba(16, 185, 129, 0.25);
}

.cep-status-tag.error {
display: inline-block;
color: #ef4444;
background: rgba(239, 68, 68, 0.12);
border: 1px solid rgba(239, 68, 68, 0.25);
}

/* Item Card Responsive styling */
.item-card-row {
background: rgba(0, 0, 0, 0.32);
border: 1px solid var(--border-glass);
border-radius: var(--radius-md);
padding: 0.75rem 0.8rem;
margin-bottom: 0.65rem;
display: flex;
flex-direction: column;
gap: 0.55rem;
position: relative;
transition: all 0.2s ease;
}

.item-card-row:hover {
border-color: rgba(0, 229, 255, 0.25);
background: rgba(0, 0, 0, 0.42);
}

.item-card-desc-group {
display: flex;
align-items: center;
gap: 0.5rem;
}

.item-card-num {
width: 26px;
height: 26px;
border-radius: var(--radius-full);
background: rgba(0, 229, 255, 0.12);
color: var(--accent-cyan);
font-size: 0.78rem;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}

.item-card-bottom-row {
display: grid;
grid-template-columns: auto 1fr auto;
gap: 0.55rem;
align-items: flex-end;
}

.item-stepper {
display: flex;
align-items: center;
background: rgba(0, 0, 0, 0.35);
border: 1px solid var(--border-glass);
border-radius: var(--radius-sm);
overflow: hidden;
height: 42px;
}

.item-stepper button {
background: transparent;
border: none;
color: var(--text-secondary);
width: 34px;
height: 42px;
cursor: pointer;
font-size: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.15s;
}

.item-stepper button:hover {
background: rgba(255, 255, 255, 0.1);
color: var(--text-primary);
}

.item-stepper input {
border: none !important;
background: transparent !important;
text-align: center;
padding: 0 !important;
width: 38px !important;
font-weight: 700;
font-size: 16px !important;
color: var(--text-primary) !important;
-moz-appearance: textfield;
}

.item-stepper input::-webkit-inner-spin-button,
.item-stepper input::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

.btn-del-item-card {
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.25);
color: #ef4444;
width: 42px;
height: 42px;
border-radius: var(--radius-sm);
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.2s;
flex-shrink: 0;
}

.btn-del-item-card:hover {
background: rgba(239, 68, 68, 0.2);
border-color: #ef4444;
}

.item-card-subtotal {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.78rem;
color: var(--text-muted);
padding-top: 0.4rem;
margin-top: 0.2rem;
border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.item-subtotal-val {
color: var(--accent-cyan);
font-weight: 700;
font-size: 0.85rem;
font-family: var(--font-mono, monospace);
}

/* Print hint banner */
.print-hint-banner {
background: rgba(0, 229, 255, 0.05);
border: 1px solid rgba(0, 229, 255, 0.15);
border-radius: var(--radius-md);
padding: 0.65rem 0.85rem;
font-size: 0.8rem;
color: var(--text-secondary);
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
}

.print-hint-banner svg {
color: var(--accent-cyan);
flex-shrink: 0;
}

/* Expand Sheet Button (Mobile only) */
.btn-expand-sheet {
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: var(--accent-violet);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  width: 100%;
}

.btn-expand-sheet:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-violet);
  transform: translateY(-1px);
}

@media screen and (min-width: 1024px) {
  .btn-expand-sheet {
    display: none !important;
  }
}

/* ============================================================
   Fullscreen Expand Modal (Pinch to Zoom)
   ============================================================ */
.sheet-expand-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sheet-expand-overlay.active {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.sheet-expand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(10, 11, 16, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  flex-shrink: 0;
}

.sheet-expand-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sheet-expand-title svg {
  color: var(--accent-cyan);
}

.sheet-expand-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.sheet-expand-close:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

.sheet-expand-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--accent-cyan);
  padding: 0.5rem 1rem;
  background: rgba(0, 229, 255, 0.06);
  border-bottom: 1px solid rgba(0, 229, 255, 0.12);
  flex-shrink: 0;
}

.sheet-expand-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #e0e0e0;
  padding: 1rem;
  touch-action: pan-x pan-y pinch-zoom;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 180, 216, 0.45) #e0e0e0;
}

.sheet-expand-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.sheet-expand-body::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 9999px;
}

.sheet-expand-body::-webkit-scrollbar-thumb {
  background: rgba(0, 180, 216, 0.5);
  border-radius: 9999px;
  transition: all 0.2s;
}

.sheet-expand-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 180, 216, 0.85);
}

.sheet-expand-body .sheet-preview-container {
  width: 794px;
  min-width: 794px;
  margin: 0 auto;
  transform: none !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ============================================================
   PRINT MEDIA QUERY (Exact Official A4 Print Form)
   ============================================================ */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  *, *:before, *:after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    display: block !important;
    overflow: visible !important;
  }

  /* Hide absolutely everything except the declaration document */
  #tools-navbar,
  .tools-top-nav,
  .tools-mobile-drawer,
  .tools-modal-overlay,
  .app-hero,
  .form-panel,
  .preview-toolbar,
  .site-footer,
  .promo-box,
  .mobile-view-tabs,
  .mobile-tabs-container,
  .mobile-floating-bar,
  .modal-overlay,
  .print-hint-banner,
  .sheet-scroll-hint,
  .sheet-bottom-actions,
  .sheet-expand-overlay,
  .form-bottom-nav,
  .btn-goto-sheet,
  .panel-header {
    display: none !important;
  }

  .main-wrapper {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  .grid-container {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  /* Force preview section to display on all devices/states (desktop and mobile) */
  body.view-form .preview-sticky,
  body.view-sheet .preview-sticky,
  body .preview-sticky,
  .preview-sticky {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }

  .panel-card {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }

  .sheet-scroll-container,
  #sheetScrollWrapper {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  .sheet-preview-container,
  #sheetDoc {
    display: block !important;
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
    /* Clean physical margins on paper without browser header/footer rebarbas */
    padding: 8mm 10mm 6mm 10mm !important;
    margin: 0 auto !important;
    border-radius: 0 !important;
    transform: none !important;
    box-sizing: border-box !important;
    background: #ffffff !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .correios-doc {
    display: block !important;
    width: 100% !important;
    min-width: 100% !important;
    box-sizing: border-box !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}