:root {
    --primary: #d35400;
    --primary-hover: #e67e22;
    --primary-light: rgba(211, 84, 0, 0.15);
    --bg: #1a1d23;
    --card-bg: #252b32;
    --text: #edf2f7;
    --text-muted: #94a3b8;
    --border: #3f4750;
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.15);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.15);
    --cut-bg: #e2e8f0;
    --cut-border: #2d3436;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.15);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.35);
    --transition: 150ms ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 16px;
}

.container {
    width: 100%;
    max-width: 900px;
}

button {
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    line-height: 1.4;
}
button:active {
    transform: scale(0.97);
}

button:not(.secondary):not(.danger) {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(211, 84, 0, 0.35);
}
button:not(.secondary):not(.danger):hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 6px rgba(211, 84, 0, 0.45);
}

button.secondary {
    background: var(--border);
    color: var(--text);
}
button.secondary:hover {
    background: #4b5563;
}

button.danger {
    background: var(--danger);
    color: #fff;
    width: auto;
    padding: 8px 12px;
}
button.danger:hover {
    background: #dc2626;
}

.action-btn {
    background: transparent !important;
    color: var(--text) !important;
    box-shadow: none !important;
    padding: 8px 14px !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 0.82rem;
    font-weight: 500;
}
.action-btn:hover {
    background: rgba(255,255,255,0.06) !important;
    border-color: var(--text-muted) !important;
}

input, select {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #1a1d23;
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
    outline: none;
}
input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
select {
    cursor: pointer;
    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='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}
select option {
    background: var(--card-bg);
    color: var(--text);
}
label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

header {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 2px solid var(--border);
    position: relative;
}
header::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
}

header div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
}

h1 {
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--primary);
}

h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
    letter-spacing: -0.01em;
}

.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

#inputs-card > button {
    margin-top: 12px;
}
#inputs-card > button:last-of-type {
    margin-top: 18px;
    font-size: 1.15rem;
    padding: 14px 28px;
    width: 100%;
}

.input-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1.5fr 0.5fr;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.input-header {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin-bottom: 10px;
    padding: 0 4px;
}

#inputs-container .input-row {
    padding: 8px 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    margin-bottom: 4px;
}
#inputs-container .input-row:hover {
    background: rgba(255,255,255,0.03);
}

@media (max-width: 600px) {
    .input-row {
        grid-template-columns: 1fr;
        background: rgba(0,0,0,0.2);
        padding: 12px;
        border-radius: var(--radius-sm);
        gap: 8px;
    }
    .input-header {
        display: none;
    }
    #inputs-container .input-row {
        padding: 12px;
    }
}

#results-section {
    border: 1px solid var(--border);
}

.result-group {
    margin-bottom: 2rem;
    border-left: 4px solid var(--primary);
    padding-left: 1.25rem;
}

.summary-item {
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.cut-diagram {
    display: flex;
    width: 100%;
    height: 38px;
    background: #374151;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 10px 0 20px 0;
    position: relative;
    border: 1px solid #4b5563;
}

.cut-piece {
    background: var(--cut-bg);
    color: #1a1d23;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    border-right: 2px solid var(--cut-border);
    white-space: nowrap;
    overflow: hidden;
    min-width: 0;
}

.cut-waste {
    background: var(--danger);
    opacity: 0.55;
    height: 100%;
}

.bar-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.hidden {
    display: none;
}

dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    background: var(--card-bg);
    color: var(--text);
}
dialog::backdrop {
    background: rgba(0, 0, 0, 0.65);
}
dialog h3 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
}
dialog > p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

dialog > div:last-child {
    margin-top: 20px;
    text-align: right;
}
#stock-config-container > :first-child {
    margin-top: 4px;
}
#stock-config-container > p {
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    margin: 8px 0;
    font-size: 0.9rem;
}
.stock-option {
    margin-bottom: 10px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}
.stock-option strong {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.stock-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.stock-checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}
.stock-checkboxes label:hover {
    background: rgba(255,255,255,0.05);
}
.stock-checkboxes input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

#toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.25s ease;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}

@media print {
    body {
        background-color: white;
        color: black;
        display: block;
        padding: 0;
    }
    .container {
        max-width: 100%;
        width: 100%;
    }
    #login-screen,
    header button,
    .card button,
    .input-row button,
    .toolbar,
    #inputs-card,
    dialog,
    #toast {
        display: none !important;
    }
    header {
        border-bottom: 2px solid black;
        margin-bottom: 1rem;
    }
    header::after {
        display: none;
    }
    h1 {
        color: black;
    }
    h2 {
        color: #333;
        border-bottom: 1px solid #ccc;
        padding-bottom: 5px;
    }
    .card {
        background: white;
        box-shadow: none;
        padding: 0;
        margin-bottom: 1rem;
        border: none;
    }
    .result-group {
        border-left: 4px solid black;
        page-break-inside: avoid;
    }
    .cut-diagram {
        background: white;
        border: 1px solid black;
        height: 30px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .cut-piece {
        background: #eee !important;
        border-right: 1px solid black;
        color: black;
    }
    .cut-waste {
        background: #ccc !important;
        opacity: 1;
        color: black;
    }
    .bar-label {
        color: black;
        font-weight: bold;
    }
    #print-summary {
        display: block !important;
        margin-bottom: 20px;
    }
}

#print-summary {
    display: none;
}

.footer {
    text-align: center;
    padding: 8px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.footer a:hover {
    text-decoration: underline;
}

.lang-btn {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1000;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: background var(--transition), color var(--transition);
    line-height: 1;
}
.lang-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
