/* ========================================
   Sonkit Data Sheet Generator - Styles
   ======================================== */

/* CSS Variables */
:root {
    /* Brand Colors */
    --color-primary: #C41E3A;
    --color-primary-dark: #9B1830;
    --color-primary-light: #E8435A;

    /* Neutral Colors */
    --color-bg-dark: #1a1a2e;
    --color-bg-darker: #16162a;
    --color-bg-card: #252545;
    --color-text-light: #ffffff;
    --color-text-muted: #a0a0b8;
    --color-border: #3a3a5c;

    /* Paper Colors */
    --color-paper: #ffffff;
    --color-paper-text: #333333;
    --color-paper-muted: #666666;
    --color-table-header: #f5f5f5;
    --color-table-border: #dddddd;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg-dark);
    color: var(--color-text-light);
    min-height: 100vh;
    line-height: 1.5;
}

/* ========================================
   App Container
   ======================================== */
.app-container {
    display: grid;
    grid-template-columns: 380px 1fr;
    min-height: 100vh;
}

/* ========================================
   Input Panel (Left Side)
   ======================================== */
.input-panel {
    background: var(--color-bg-darker);
    padding: var(--space-lg);
    overflow-y: auto;
    height: 100vh;
    border-right: 1px solid var(--color-border);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.panel-header .logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
}

.panel-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-light);
}

/* Form Sections */
.form-section {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

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

.section-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-primary-light);
    margin-bottom: var(--space-md);
}

/* Form Groups */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

/* Form Hint */
.form-hint {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    margin-top: var(--space-sm);
    margin-bottom: 0;
    opacity: 0.75;
    line-height: 1.5;
}

.form-hint a {
    color: var(--color-primary-light);
    text-decoration: none;
    font-weight: 500;
}

.form-hint a:hover {
    text-decoration: underline;
}

/* Input Fields */
.input-field {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-light);
    font-size: 0.875rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-field:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(196, 30, 58, 0.2);
}

.input-field::placeholder {
    color: var(--color-text-muted);
    opacity: 0.6;
}

/* Input with unit */
.input-with-unit {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.input-with-unit .input-field {
    flex: 1;
}

.input-with-unit .unit {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    min-width: 40px;
}

/* Temperature range */
.temp-range {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.temp-range .input-field {
    width: 80px;
}

.temp-range .unit-select {
    width: 60px;
}

.range-separator {
    color: var(--color-text-muted);
}

/* Radio Groups */
.radio-group {
    display: flex;
    gap: var(--space-md);
}

.radio-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.radio-item input[type="radio"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-bg-card);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.radio-item input[type="radio"]:checked {
    border-color: var(--color-primary);
    background: var(--color-primary);
    box-shadow: inset 0 0 0 3px var(--color-bg-card);
}

.radio-item span {
    font-size: 0.875rem;
    color: var(--color-text-light);
}

/* Parsed Section */
.parsed-section {
    background: var(--color-bg-card);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.parsed-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.parsed-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.parsed-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.parsed-value {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-light);
}

/* Section Label Row - for inline label + toggle */
.section-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.section-label-row .section-label {
    margin-bottom: 0;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    background: var(--color-bg-dark);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.mode-btn {
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 500;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: transparent;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.mode-btn:hover {
    color: var(--color-text-light);
}

.mode-btn.active {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 1px 3px rgba(196, 30, 58, 0.3);
}

/* Parsed Panel */
.parsed-panel {
    /* inherits parsed-grid styles */
}

/* Parameter Input Form */
.param-panel {
    /* Container for param input form */
}

.param-form-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.param-form-grid .form-group {
    margin-bottom: 0;
}

.param-form-grid .form-group label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 2px;
}

.param-form-grid .input-field {
    padding: 5px var(--space-sm);
    font-size: 0.8rem;
}

.coating-thickness-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.coating-thickness-row .input-field {
    flex: 1;
}

.coating-thickness-row .range-separator {
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Generated Model Result */
.param-result {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-dark);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.param-result-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.param-result-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-primary-light);
    margin-top: 2px;
    word-break: break-all;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    width: 100%;
    padding: var(--space-md);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    font-size: 1rem;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(196, 30, 58, 0.3);
}

.btn-secondary {
    background: var(--color-bg-card);
    color: var(--color-text-light);
    border: 1px solid var(--color-border);
    margin-top: var(--space-sm);
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover {
    color: var(--color-text-light);
    background: var(--color-bg-card);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

/* ========================================
   Preview Panel (Right Side)
   ======================================== */
.preview-panel {
    background: var(--color-bg-dark);
    padding: var(--space-lg);
    overflow-y: auto;
    height: 100vh;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.preview-header h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-light);
}

.preview-size {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-bg-card);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}

.preview-container {
    display: flex;
    justify-content: center;
    padding: var(--space-lg);
    background: #2a2a4a;
    border-radius: var(--radius-lg);
    min-height: calc(100vh - 120px);
}

/* ========================================
   Data Sheet (A4 Preview)
   ======================================== */
.datasheet {
    width: 210mm;
    height: 297mm;
    max-height: 297mm;
    overflow: hidden;
    background: var(--color-paper);
    color: var(--color-paper-text);
    padding: 12mm 15mm;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    font-family: Arial, sans-serif;
    font-size: 9pt;
    line-height: 1.4;
    box-sizing: border-box;
}

/* DS Header */
.ds-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--color-primary);
    margin-bottom: 10px;
}

.ds-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ds-logo {
    width: 40px;
    height: 40px;
}

.ds-company {
    display: flex;
    flex-direction: column;
}

.ds-company-zh {
    font-size: 11pt;
    font-weight: bold;
    color: var(--color-paper-text);
}

.ds-company-en {
    font-size: 8pt;
    color: var(--color-paper-muted);
}

.ds-rev {
    font-size: 8pt;
    color: var(--color-paper-muted);
}

/* DS Title */
.ds-title {
    text-align: center;
    margin-bottom: 8px;
}

.ds-title-zh {
    font-size: 14pt;
    font-weight: bold;
    color: var(--color-paper-text);
    margin: 0;
}

.ds-title-en {
    font-size: 10pt;
    font-weight: normal;
    color: var(--color-paper-muted);
    margin: 2px 0 0 0;
}

/* DS Model Number */
.ds-model {
    text-align: center;
    padding: 8px;
    background: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    margin-bottom: 12px;
}

.ds-model span {
    font-size: 11pt;
    font-weight: bold;
    color: #000;
    letter-spacing: 0.5px;
}

/* DS Content Grid */
.ds-content {
    display: grid;
    grid-template-columns: 55% 45%;
    gap: 12px;
}

.ds-data-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* DS Sections */
.ds-section {
    background: #fafafa;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
}

.ds-section-title {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: white;
    padding: 4px 8px;
    font-size: 9pt;
    font-weight: bold;
    margin: 0;
}

.ds-section-title .zh {
    margin-right: 4px;
}

.ds-section-title .en {
    font-weight: normal;
    font-size: 8pt;
}

/* DS Tables */
.ds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt;
}

.ds-table tr {
    border-bottom: 1px solid #e8e8e8;
}

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

.ds-table td {
    padding: 3px 6px;
    vertical-align: middle;
}

.ds-table td.label {
    background: #f5f5f5;
    color: var(--color-paper-muted);
    width: 55%;
}

.ds-table td.label .zh {
    color: var(--color-paper-text);
    font-weight: 500;
}

.ds-table td.value {
    font-weight: 600;
    color: var(--color-paper-text);
    text-align: right;
    width: 25%;
}

.ds-table td.tolerance,
.ds-table td.ref {
    font-size: 7pt;
    color: var(--color-paper-muted);
    text-align: right;
    width: 20%;
}

/* Seal Data Table - colored rows */
.seal-data tr:nth-child(1) td.value,
.seal-data tr:nth-child(2) td.value,
.seal-data tr:nth-child(3) td.value,
.seal-data tr:nth-child(4) td.value,
.seal-data tr:nth-child(5) td.value,
.seal-data tr:nth-child(6) td.value {
    background: #fff8dc;
}

.seal-data tr:nth-child(7) td.value,
.seal-data tr:nth-child(8) td.value,
.seal-data tr:nth-child(9) td.value {
    background: #e8f5e9;
}

.seal-data tr:nth-child(10) td.value,
.seal-data tr:nth-child(11) td.value {
    background: #e3f2fd;
}

.seal-data tr:nth-child(12) td.value,
.seal-data tr:nth-child(13) td.value,
.seal-data tr:nth-child(14) td.value {
    background: #fce4ec;
}

/* Groove Data Table - colored rows */
.groove-data tr:nth-child(1) td.value,
.groove-data tr:nth-child(2) td.value,
.groove-data tr:nth-child(3) td.value,
.groove-data tr:nth-child(4) td.value,
.groove-data tr:nth-child(5) td.value {
    background: #fff3e0;
}

.groove-data tr:nth-child(6) td.value,
.groove-data tr:nth-child(7) td.value {
    background: #f3e5f5;
}

/* DS Images - Vertical Layout */
.ds-image-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
    justify-content: flex-start;
}

.ds-image-box {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 4px;
}

.ds-image-box img {
    width: 85%;
    height: auto;
    object-fit: contain;
}

/* Rendering images (Full and Cross Section) */
.ds-image-full {
    flex: 1.2;
    min-height: 70px;
}

.ds-image-section {
    flex: 0.5;
    min-height: 45px;
    margin-bottom: 8px;
    /* Gap between rendering and design images */
}

.ds-image-section img {
    width: 50% !important;
}

/* Design images (Product Design and Groove Design) */
.ds-image-design {
    flex: 0.9;
    min-height: 55px;
}

.ds-image-groove {
    flex: 0.9;
    min-height: 55px;
}

/* Inch Value Column */
.ds-table td.inch-value {
    font-size: 7pt;
    color: var(--color-paper-muted);
    text-align: right;
    width: 18%;
    font-style: italic;
}

/* Hide inch values by default */
.ds-table td.inch-value {
    display: none;
}

/* Show inch values when enabled */
body.show-inch .ds-table td.inch-value {
    display: table-cell;
}

body.show-inch .ds-table td.value {
    width: 20%;
}

/* DS Footer */
.ds-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
    font-size: 8pt;
    color: var(--color-paper-muted);
}

/* DS Note */
.ds-note {
    margin-top: 16px;
    font-size: 7pt;
    color: #333;
    text-align: center;
}

.ds-note strong {
    font-weight: 700;
}

/* DS Disclaimer */
.ds-disclaimer {
    margin-top: 4px;
    font-size: 6pt;
    color: #666;
    line-height: 1.4;
    text-align: center;
}

.ds-disclaimer a {
    color: #0066cc;
    text-decoration: none;
}

.ds-disclaimer a:hover {
    text-decoration: underline;
}

/* DS Copyright */
.ds-copyright {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
    font-size: 7pt;
    color: #888;
    text-align: center;
    line-height: 1.4;
}

.ds-footer-item {
    display: flex;
    gap: 4px;
}

.ds-footer-item .label {
    color: var(--color-paper-muted);
}

.ds-footer-item .value {
    color: var(--color-paper-text);
    font-weight: 500;
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    body {
        background: white;
    }

    .app-container {
        display: block;
    }

    .input-panel,
    .preview-header {
        display: none;
    }

    .preview-panel {
        padding: 0;
        background: white;
    }

    .preview-container {
        padding: 0;
        background: white;
        box-shadow: none;
    }

    .datasheet {
        box-shadow: none;
        margin: 0;
        padding: 10mm;
    }
}

/* ========================================
   Responsive Adjustments
   ======================================== */
@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .input-panel {
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .preview-panel {
        height: auto;
    }

    .datasheet {
        width: 100%;
        max-width: 210mm;
        min-height: auto;
    }
}

/* ========================================
   English Mode
   ======================================== */
body.lang-en .ds-title-zh,
body.lang-en .ds-company-zh,
body.lang-en .ds-section-title .zh,
body.lang-en .ds-table td.label .zh,
body.lang-en .ds-footer-item .label {
    display: none;
}

body.lang-en .ds-title-en {
    font-size: 14pt;
    font-weight: bold;
    color: var(--color-paper-text);
}

body.lang-en .ds-section-title .en {
    font-weight: bold;
    font-size: 9pt;
}

/* ========================================
   Loading State
   ======================================== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Error States
   ======================================== */
.input-field.error {
    border-color: #ef4444;
}

.error-message {
    color: #ef4444;
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ========================================
   Checkbox Styles
   ======================================== */
.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-card);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.checkbox-item input[type="checkbox"]:checked {
    border-color: var(--color-primary);
    background: var(--color-primary);
}

.checkbox-item input[type="checkbox"]:checked::after {
    content: '✓';
    display: block;
    text-align: center;
    color: white;
    font-size: 12px;
    line-height: 14px;
}

.checkbox-item span {
    font-size: 0.875rem;
    color: var(--color-text-light);
}

/* ========================================
   Editable Cell Styles
   ======================================== */
.ds-table td.editable-cell {
    cursor: text;
    transition: background-color 0.2s ease, outline 0.2s ease, filter 0.2s ease;
}

.ds-table td.editable-cell:hover {
    filter: brightness(0.93) contrast(1.05);
}

.ds-table td.editable-cell:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    background-color: #ffffff !important;
    filter: none;
    box-shadow: 0 0 4px rgba(196, 30, 58, 0.2);
}