/* ============================================
   SSCC Label Generator v3.3
   Clean compact design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --surface: #f8fafc;
    --surface-elevated: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-focus: #3b82f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

.container { 
    max-width: 920px; 
    margin: 0 auto; 
    padding: 1.5rem; 
}

/* Header - Compact */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding: 1rem 1.5rem;
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

header h1 { 
    font-size: 1.25rem; 
    font-weight: 700; 
    color: var(--primary); 
    letter-spacing: -0.02em;
}

/* Database Status - Compact */
.db-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.status-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 1.5s infinite;
}

.db-status.connected .status-indicator {
    background: var(--success);
    animation: none;
}

.db-status.error .status-indicator {
    background: var(--error);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-text {
    color: var(--text-secondary);
}

/* Form */
.label-form {
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.form-section { 
    padding: 1.5rem 1.75rem; 
    border-bottom: 1px solid var(--border); 
}

.form-section:last-of-type { border-bottom: none; }

.form-section h2 { 
    font-size: 0.9rem; 
    font-weight: 600; 
    color: var(--primary); 
    margin-bottom: 1rem; 
}

/* Collapsible Sections */
details.collapsible {
    padding: 0;
    border-bottom: 1px solid var(--border);
}

details.collapsible summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.75rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    transition: background 0.2s;
}

details.collapsible summary:hover {
    background: var(--surface);
}

details.collapsible summary::-webkit-details-marker {
    display: none;
}

details.collapsible summary::before {
    content: '▶';
    font-size: 0.65rem;
    margin-right: 0.75rem;
    transition: transform 0.2s;
    color: var(--text-muted);
}

details.collapsible[open] summary::before {
    transform: rotate(90deg);
}

details.collapsible summary span:first-child {
    display: flex;
    align-items: center;
}

.summary-preview {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
    padding-left: 1rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

details.collapsible[open] .summary-preview {
    display: none;
}

details.collapsible .form-grid {
    padding: 0 1.75rem 1.5rem 1.75rem;
}

.form-grid { 
    display: grid; 
    grid-template-columns: repeat(2, 1fr); 
    gap: 0.85rem 1.25rem; 
}

.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: 1 / -1; }

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

.form-group input {
    padding: 0.65rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    transition: all 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: white;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.form-group input:hover {
    border-color: var(--text-muted);
}

.form-group small { 
    font-size: 0.7rem; 
    color: var(--text-muted); 
    margin-top: 0.25rem; 
}

/* SSCC Section */
.sscc-section { 
    background: linear-gradient(135deg, #f0fdf4 0%, #f8fafc 100%); 
}

.sscc-preview { grid-column: 1 / -1; }

.sscc-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--primary);
    background: white;
    padding: 0.9rem 1.25rem;
    border-radius: var(--radius-sm);
    border: 2px dashed var(--success);
    text-align: center;
    letter-spacing: 0.06em;
}

/* Buttons */
.button-group { 
    display: flex; 
    gap: 0.85rem; 
    padding: 1.25rem 1.75rem; 
    background: var(--surface); 
    border-top: 1px solid var(--border); 
}

.btn {
    flex: 1;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: var(--shadow-md), 0 2px 8px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover:not(:disabled) { 
    background: var(--accent-hover);
    transform: translateY(-1px); 
    box-shadow: var(--shadow-lg), 0 4px 12px rgba(59, 130, 246, 0.35);
}

.btn-secondary { 
    background: white; 
    color: var(--primary); 
    border: 1.5px solid var(--border); 
}

.btn-secondary:hover:not(:disabled) { 
    border-color: var(--primary);
    background: var(--surface);
}

/* Preview Section */
.preview-section {
    margin-top: 1.5rem;
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
}

.preview-section h2 { 
    font-size: 1rem; 
    font-weight: 600; 
    color: var(--primary); 
    margin-bottom: 1.25rem; 
    text-align: center; 
}

.preview-section.hidden { display: none; }

/* Recent SSCC Section */
.recent-section {
    margin-top: 1.5rem;
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
}

.recent-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 1rem;
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 250px;
    overflow-y: auto;
}

.recent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.85rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.recent-item .sscc-number {
    font-weight: 600;
    color: var(--primary);
}

.recent-item .sscc-meta {
    display: flex;
    gap: 0.85rem;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.recent-item .sscc-date {
    color: var(--text-secondary);
}

.loading-text {
    text-align: center;
    color: var(--text-muted);
    padding: 1.5rem;
}

.empty-text {
    text-align: center;
    color: var(--text-muted);
    padding: 1.5rem;
    font-style: italic;
}

/* ============================================
   LABEL PREVIEW - Simple Clean Layout
   ============================================ */

.label-preview {
    background: white;
    border: 2px solid #000;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    font-family: Arial, Helvetica, sans-serif;
    aspect-ratio: 100 / 150;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}

/* Addresses */
.label-addresses {
    display: flex;
    border-bottom: 1.5px solid #000;
}

.address-from, .address-to {
    flex: 1;
    padding: 10px 12px;
}

.address-from {
    border-right: 1.5px solid #000;
}

.address-header {
    font-size: 9px;
    font-weight: bold;
    margin-bottom: 4px;
}

.address-company {
    font-size: 11px;
    font-weight: bold;
    margin-bottom: 2px;
}

.address-line {
    font-size: 9px;
    line-height: 1.4;
}

/* Product */
.label-product {
    padding: 10px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: bold;
    border-bottom: 1.5px solid #000;
    background: #fafafa;
}

/* Data section - Compact text layout */
.label-data-simple {
    padding: 8px 12px;
    border-bottom: 1.5px solid #000;
}

.data-row-inline {
    display: flex;
    margin-bottom: 6px;
}

.data-item {
    flex: 1;
}

.data-row-single {
    margin-bottom: 4px;
}

.data-row-single:last-child {
    margin-bottom: 0;
}

.data-label {
    font-size: 8px;
    font-weight: bold;
    color: #333;
    display: block;
    margin-bottom: 1px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.data-text {
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    display: block;
}

.data-item:last-child .data-text {
    font-weight: bold;
}

.data-count {
    font-size: 26px;
    font-weight: bold;
    display: block;
    line-height: 1;
}

.data-sscc {
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: bold;
    display: block;
    letter-spacing: 0.3px;
}

/* Barcodes */
.label-barcode1 {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1.5px solid #000;
    flex: 1;
}

.label-barcode2 {
    padding: 10px 12px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.label-barcode1 svg, .label-barcode2 svg {
    width: 98%;
    max-width: 320px;
    margin: 0 auto;
    display: block;
}

.label-barcode1 svg {
    height: 60px;
}

.label-barcode2 svg {
    height: 70px;
}

.barcode-hri {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    margin-top: 5px;
    letter-spacing: 0.3px;
}

/* Notification Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: white;
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--error);
}

/* Footer */
footer { 
    text-align: center; 
    padding: 1.5rem; 
    color: rgba(255,255,255,0.5); 
    font-size: 0.8rem; 
}

/* Responsive */
@media (max-width: 640px) {
    .container { padding: 1rem; }
    .form-grid { grid-template-columns: 1fr; }
    .button-group { flex-direction: column; }
    header { flex-direction: column; gap: 0.75rem; text-align: center; }
    header h1 { font-size: 1.1rem; }
    .label-preview { max-width: 100%; }
    .recent-item { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
    .summary-preview { display: none; }
}

@media print {
    body { background: white; }
    header, .label-form, footer, .preview-section h2, .recent-section { display: none; }
    .preview-section { box-shadow: none; padding: 0; margin: 0; }
    .label-preview { max-width: 100mm; box-shadow: none; }
}
