:root {
    --primary: #0a3d62;
    --primary-light: #3c6382;
    --accent: #f39c12;
    --success: #27ae60;
    --danger: #e74c3c;
    --dark: #2c3e50;
    --light: #ecf0f1;
    --gray: #95a5a6;
    --white: #ffffff;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    color: var(--dark);
    line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

header {
    text-align: center;
    padding: 40px 0;
    background: var(--white);
    box-shadow: var(--shadow);
    margin-bottom: 40px;
}

h1 { color: var(--primary); font-size: 2.5em; margin-bottom: 10px; }
.tagline { color: var(--gray); font-size: 1.2em; }

.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .main-grid { grid-template-columns: 1fr; }
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.card h2 {
    color: var(--primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon { width: 24px; height: 24px; }
.form-group { margin-bottom: 20px; }

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: var(--dark);
}

input[type="text"], input[type="number"] {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius);
    font-size: 16px;
    transition: border-color 0.3s;
}

input:focus { outline: none; border-color: var(--primary-light); }
.help-text { font-size: 0.9em; color: var(--gray); margin-top: 5px; }

.input-preview {
    background: #f0f8ff;
    border: 1px solid #d0e0f0;
    border-radius: var(--radius);
    padding: 8px 12px;
    margin-top: 8px;
    font-size: 0.9em;
    color: var(--primary);
}

.input-preview.error {
    background: #fff0f0;
    border-color: #f0d0d0;
    color: var(--danger);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--white);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 500px;
    width: 90%;
    position: relative;
}

.modal-content h4 { color: var(--primary); margin-bottom: 20px; font-size: 1.3em; }

.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--gray);
    transition: color 0.3s;
}

.modal-close-btn:hover { color: var(--dark); }

.example-table { width: 100%; }

.example-row {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.example-row:last-child { border-bottom: none; }

.example-input {
    flex: 1;
    font-family: 'Courier New', monospace;
    text-align: right;
    padding-right: 15px;
}

.example-arrow { color: var(--gray); padding: 0 10px; }

.example-output {
    flex: 1;
    color: var(--success);
    font-weight: 600;
    padding-left: 15px;
}

.help-icon {
    cursor: pointer;
    color: var(--gray);
    margin-left: 5px;
    font-weight: bold;
    font-size: 1.1em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid var(--gray);
    border-radius: 50%;
    transition: all 0.3s;
}

.help-icon:hover { color: var(--primary); border-color: var(--primary); }

.cuts-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 10px;
}

.cut-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: var(--radius);
    margin-bottom: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.cut-length { flex: 1; font-weight: 600; }

.cut-quantity {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9em;
}

.remove-cut {
    background: var(--danger);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.3s;
}

.remove-cut:hover { background: #c0392b; }
.add-cut-form { display: flex; gap: 10px; margin-top: 20px; }
.add-cut-form input { flex: 1; }

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(10, 61, 98, 0.3);
}

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #229954; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #e67e22; }
.btn-full { width: 100%; margin-top: auto; }

.loading { text-align: center; padding: 40px; }

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.results {
    margin-top: 40px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 30px;
}

.results h2 {
    color: var(--primary);
    margin: 30px 0 15px;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 5px;
}

.results h3 { color: var(--primary); margin: 30px 0 15px; }

.report-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.report-header h1 { font-size: 1.8em; margin: 0; color: var(--primary); }
.report-header p { margin: 0; text-align: right; font-size: 0.9em; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-value { font-size: 2em; font-weight: bold; margin-bottom: 5px; }
.stat-label { font-size: 0.9em; opacity: 0.9; }

.required-cuts-list { display: flex; flex-direction: column; gap: 15px; margin-top: 15px; }

.required-cut-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 10px 15px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.required-cut-qty {
    font-weight: bold;
    color: var(--primary);
    flex-shrink: 0;
    width: 40px;
    text-align: center;
}

.required-cut-bar {
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
    padding: 0 8px;
}

.pattern-visual {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: var(--radius);
    height: 50px;
    display: flex;
    overflow: hidden;
    margin: 10px 0;
}

.cut-segment, .waste-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 0.9em;
    border-right: 2px solid white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pattern-visual .cut-segment:last-child { border-right: none; }

.waste-segment {
    background: repeating-linear-gradient(45deg, #e0e0e0, #e0e0e0 10px, #d0d0d0 10px, #d0d0d0 20px);
    color: #666;
    font-size: 0.8em;
    text-shadow: none;
}

.color-1, .required-cut-bar.color-1 { background: #1f77b4; }
.color-2, .required-cut-bar.color-2 { background: #ff7f0e; }
.color-3, .required-cut-bar.color-3 { background: #2ca02c; }
.color-4, .required-cut-bar.color-4 { background: #d62728; }
.color-5, .required-cut-bar.color-5 { background: #9467bd; }
.color-6, .required-cut-bar.color-6 { background: #8c564b; }

.error {
    background: #fee;
    color: var(--danger);
    padding: 15px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

footer { text-align: center; padding: 40px 0; color: var(--gray); }

@media print {
    @page { margin: 0.5in; }

    body {
        background: white;
        font-size: 10pt;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    header, .main-grid, footer, .btn, .error, .loading,
    .help-text, .add-cut-form, .remove-cut, .cuts-container,
    .input-preview, .modal-overlay { display: none !important; }

    .container, .results, .card {
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        background: white !important;
    }

    h1, h2, h3 {
        color: black !important;
        border-bottom: 1px solid #ccc !important;
        padding-bottom: 5px;
        margin-top: 15px !important;
        page-break-after: avoid;
    }

    .report-header {
        border-bottom: 3px solid black;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    .report-header h1 { border-bottom: none !important; }

    .summary-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
        page-break-inside: avoid;
    }

    .stat-card {
        background: #f0f0f0 !important;
        color: #333 !important;
        border: 1px solid #ddd;
        padding: 10px;
    }

    .stat-value { font-size: 1.5em; }
    .stat-label { font-size: 0.8em; }

    .required-cuts-list { gap: 8px; page-break-inside: avoid; }
    .required-cut-item { background: white; border: 1px solid #eee; padding: 6px 8px; }
    .required-cut-qty { width: 35px; font-size: 0.8em; }
    .required-cut-bar { height: 25px; font-size: 0.65em; padding: 0 5px; }

    .pattern-visual { height: 30px; margin: 5px 0; }
    .cut-segment, .waste-segment { font-size: 0.7em; border-right: 1px solid white; }
}
