/* ============================================
   TRACT TOOL - Minimalist Design System
   ============================================ */

:root {
    /* Colors - Clean Minimalist */
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;

    /* Border & Lines */
    --border-light: #e5e5e5;
    --border-medium: #d4d4d4;

    /* Text Colors */
    --text-primary: #171717;
    --text-secondary: #525252;
    --text-muted: #a3a3a3;

    /* Accent */
    --accent: #171717;
    --accent-hover: #404040;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

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

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;

    /* Transitions */
    --transition-fast: 100ms ease;
    --transition-base: 200ms ease;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* ============================================
   Layout
   ============================================ */

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-lg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    padding: var(--space-xl) 0;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-xl);
}

.header h1 {
    font-size: var(--font-size-2xl);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-xs);
}

.tagline {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-weight: 400;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 280px 1fr;
    gap: var(--space-xl);
    flex: 1;
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
}

.panel h2 {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
}

/* ============================================
   Text Input Panel
   ============================================ */

.text-panel {
    min-height: 400px;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* Zone List Section */
.zone-list-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h2 {
    margin-bottom: 0;
}

.add-zone-btn {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
}

.add-zone-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.zone-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    max-height: 150px;
    overflow-y: auto;
    padding: var(--space-xs);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.zone-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-base);
}

.zone-item:hover {
    border-color: var(--border-medium);
}

.zone-item.selected {
    border-color: var(--accent);
    background: var(--bg-secondary);
    box-shadow: 0 0 0 1px var(--accent);
}

.zone-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.zone-item-name {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.zone-item-preview {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.zone-item-size {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

/* Zone Editor */
.zone-editor {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.zone-editor.disabled {
    opacity: 0.5;
    pointer-events: none;
}

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

.panel-header h2 {
    margin-bottom: 0;
}

.text-stats {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.text-stats .divider {
    color: var(--border-medium);
}

.text-input {
    flex: 1;
    width: 100%;
    min-height: 150px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    resize: none;
    transition: border-color var(--transition-base);
}

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

.text-input:focus {
    outline: none;
    border-color: var(--accent);
}

.text-input:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

/* ============================================
   Controls Panel
   ============================================ */

.controls-panel {
    gap: var(--space-lg);
}

/* Dimension Controls */
.dimension-controls {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.dimension-group {
    flex: 1;
}

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

.input-with-unit {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color var(--transition-base);
}

.input-with-unit:focus-within {
    border-color: var(--accent);
}

.dimension-input {
    flex: 1;
    width: 100%;
    padding: var(--space-sm) var(--space-sm);
    border: none;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--text-primary);
    background: transparent;
    text-align: center;
}

.dimension-input:focus {
    outline: none;
}

.unit {
    padding: var(--space-sm);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    background: var(--bg-tertiary);
    border-left: 1px solid var(--border-light);
}

.dimension-separator {
    font-size: var(--font-size-lg);
    color: var(--text-muted);
    padding-bottom: var(--space-sm);
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.control-group>label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

/* Slider */
.slider-container {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.control-slider {
    flex: 1;
    appearance: none;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    cursor: pointer;
}

.control-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.control-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider-value {
    min-width: 40px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Font Select */
.font-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23525252' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.font-select:hover {
    border-color: var(--border-medium);
}

.font-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Alignment Toggle */
.align-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 2px;
    border-radius: var(--radius-sm);
}

.align-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.align-btn:hover {
    color: var(--text-secondary);
}

.align-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Delete Zone Button */
.delete-zone-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    width: 100%;
    padding: var(--space-sm);
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-base);
}

.delete-zone-btn:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* Controls Divider */
.controls-divider {
    height: 1px;
    background: var(--border-light);
    margin: var(--space-sm) 0;
}

/* Print Button */
.print-button {
    width: 100%;
    padding: var(--space-md);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-base);
}

.print-button:hover {
    background: var(--accent-hover);
}

.print-hint {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-align: center;
    margin-top: var(--space-sm);
}

#dimensionDisplay {
    font-weight: 500;
    color: var(--text-secondary);
}

/* ============================================
   Preview Panel
   ============================================ */

.preview-panel {
    min-height: 400px;
}

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

.preview-header h2 {
    margin-bottom: 0;
}

.expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-base);
}

.expand-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-medium);
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
}

/* Expanded Preview Modal */
.preview-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
}

.preview-overlay.active {
    display: flex;
}

.preview-overlay .preview-modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    position: relative;
}

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

.preview-modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
    transition: all var(--transition-base);
}

.close-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.preview-modal .expanded-paper {
    /* Larger A4 for expanded view (210:297 = 500:707) */
    width: 500px;
    height: 707px;
    background: white;
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.preview-paper {
    /* A4 aspect ratio scaled (210:297 = 300:424) */
    width: 300px;
    height: 424px;
    background: white;
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
}

.preview-zone {
    position: absolute;
    border: 1px dashed var(--border-medium);
    background: rgba(255, 255, 255, 0.95);
    overflow: hidden;
    cursor: move;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    user-select: none;
}

.preview-zone:hover {
    border-color: var(--accent);
}

.preview-zone.selected {
    border-color: #3b82f6;
    outline: 2px solid #3b82f6;
    outline-offset: -1px;
}

.preview-text {
    font-size: 6px;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    pointer-events: none;
}

/* ============================================
   Footer
   ============================================ */

.footer {
    text-align: center;
    padding: var(--space-xl) 0 var(--space-md);
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-xl);
}

/* ============================================
   Print Area (Hidden on Screen)
   ============================================ */

.print-area {
    display: none;
    position: relative;
    width: 210mm;
    height: 297mm;
}

.print-zone {
    position: absolute;
    border: 1px solid #ccc;
    overflow: hidden;
    box-sizing: border-box;
}

.print-content {
    font-family: var(--font-family);
    color: black;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.5;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }

    .controls-panel {
        order: -1;
    }

    .text-panel,
    .preview-panel {
        min-height: 300px;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    body * {
        visibility: hidden;
    }

    .print-area,
    .print-area * {
        visibility: visible;
    }

    .print-area {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 210mm;
        height: 297mm;
    }

    .print-zone {
        position: absolute !important;
    }
}