:root {
    /* Brand Palette - nabytekmg.cz */
    --primary-color: #61B797;
    /* Brand Green */
    --primary-hover: #4CA383;
    /* Darker Green */
    --brand-dark: #012A24;
    /* Brand Dark Navy */

    --background-color: #F5F5F7;
    /* Apple Light Gray */
    --surface-color: #FFFFFF;
    --border-color: #D1D1D6;
    --border-focus: #61B797;
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --danger-color: #FF3B30;
    --radius: 10px;
    /* Softer corners */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

/* CSS Reset & Global Vars already defined above */

body {
    font-family: var(--font-stack);
    background-color: transparent;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    width: 100%;
    height: auto;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1350px;
    background: transparent;
    height: auto;
    overflow-y: visible;
    margin: 0 auto;
    padding: 20px 0;
}

#app-modal-container {
    position: fixed !important;
    top: 20px !important;
    height: calc(100vh - 40px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    /* Remove vertical centering */
    z-index: 10;
    margin: 0;
}

/* Scrollbar styling for container */
.container::-webkit-scrollbar {
    width: 8px;
}

.container::-webkit-scrollbar-track {
    background: transparent;
}

.container::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.close-app-btn {
    position: sticky;
    top: 0;
    float: right;
    margin-top: -20px;
    /* Pull up into padding area */
    margin-right: -20px;
    /* Pull right into padding area */
    background: #FF3B30;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 59, 48, 0.3);
    transition: all 0.2s;
    z-index: 100;
}

.close-app-btn:hover {
    transform: scale(1.1);
    background: #FF2D20;
}

header {
    margin-bottom: 50px;
    border-bottom: 1px solid #E5E5E5;
    padding-bottom: 30px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 15px;
    margin-left: 5px;
    /* Alignment with card padding visually */
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

/* Customer Info Grid via CSS Grid */
.customer-info-section {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 20px 20px;
    /* Row gap, Col gap */
    margin-bottom: 30px;
    background: #fff;
    padding: 30px;
    /* More breathing room */
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    border: 1px solid #E5E5E5;
    align-items: end;
    /* Aligns inputs to bottom if labels wrapped, but mainly ensures clean look */
}

/* Remove old flex row styles if they exist or just override/unused them. 
   We will treat direct children of .customer-info-section as grid items if we flattened the HTML.
   BUT currently index.html has .form-row wrappers. 
   We should probably FLATTEN the HTML or style .form-row to be display: contents; 
   Using display: contents on .form-row allows children to participate in the parent grid.
*/

.form-row {
    display: contents;
    /* MAGIC: Discards the row wrapper for layout purposes */
}

.input-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
}

/* Grid Spans */
/* Row 1 */
.form-row:nth-child(1) .input-group:nth-child(1) {
    grid-column: span 6;
}

/* Company */
.form-row:nth-child(1) .input-group:nth-child(2) {
    grid-column: span 3;
}

/* IČ */
.form-row:nth-child(1) .input-group:nth-child(3) {
    grid-column: span 3;
}

/* DIČ */

/* Row 2 */
.form-row:nth-child(2) .input-group:nth-child(1) {
    grid-column: span 4;
}

/* Name */
.form-row:nth-child(2) .input-group:nth-child(2) {
    grid-column: span 4;
}

/* Email */
.form-row:nth-child(2) .input-group:nth-child(3) {
    grid-column: span 4;
}

/* Phone */

/* Row 3 */
.form-row:nth-child(3) .input-group:nth-child(1) {
    grid-column: span 6;
}

/* Street */
.form-row:nth-child(3) .input-group:nth-child(2) {
    grid-column: span 4;
}

/* City */
.form-row:nth-child(3) .input-group:nth-child(3) {
    grid-column: span 2;
}

/* ZIP */

/* Order Details Section (Specific overrides) */
.customer-info-section.order-details {
    padding-left: 80px;
    /* 30px base + 50px alignment shift to match Product Header */
}

.customer-info-section.order-details .form-row:nth-child(1) .input-group:nth-child(1) {
    grid-column: span 5;
}

/* Job Name */
.customer-info-section.order-details .form-row:nth-child(1) .input-group:nth-child(2) {
    grid-column: span 7;
}

/* Supply Buttons */

@media (max-width: 768px) {
    .customer-info-section {
        display: flex;
        /* Fallback to flex column on mobile */
        flex-direction: column;
    }

    .form-row {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
}

.form-row .input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: 2px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-row .input-group input {
    width: 100%;
    /* Ensure input fills the column */
}

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
}

/* Supply Type Radio Buttons */
.supply-type {
    display: flex;
    gap: 15px;
    margin-top: 5px;
}

.radio-label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    background: #FAFAFA;
    position: relative;
    overflow: hidden;
}

.radio-label:hover {
    background: #F0F0F0;
    border-color: #ccc;
}

.radio-label input[type="radio"] {
    margin-right: 8px;
    /* Custom radio styling or keep simple */
    accent-color: var(--primary-color);
}

/* Enhancing the checked state via JS or simple :has selector (modern browsers) */
.radio-label:has(input:checked) {
    background: #EBF5FF;
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 0 1px var(--primary-color);
}

/* Fallback for older browsers if needed, but :has is widely supported now in modern context */

/* Modern Input Styles */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-family: var(--font-stack);
    outline: none;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    background-color: #fff;
    color: var(--text-primary);
    appearance: none;
    /* Remove native UI */
    -webkit-appearance: none;
}

/* Add custom arrow for selects elsewhere via background-image if needed, 
   or keep it simple for now as native selects on Mac are decent */

input:focus,
select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
    /* Soft focus ring */
}

/* Custom Tooltip */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]:after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-5px);
    background-color: #1D1D1F;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-tooltip]:hover:after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-10px);
}

/* Card Improvements */
.product-card {
    position: relative;
    border: 1px solid #E5E5E5;
    /* Lighter border */
    border-radius: 16px;
    padding: 30px;
    margin-bottom: 40px;
    background-color: #fff;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.3s ease;
}

.product-index {
    position: absolute;
    top: 20px;
    left: 25px;
    font-size: 28px;
    font-weight: 700;
    color: #e0e0e0;
    line-height: 1;
    pointer-events: none;
}

.product-card:hover {
    box-shadow: var(--shadow-md);
}

.product-header {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    align-items: start;
    /* Align to top to fix floating */
    gap: 40px;
    margin-bottom: 30px;
    padding-left: 50px;
    /* Restore padding to clear the Index Number */
    width: 100%;
}

/* Specific section sizing */
.ph-section.ph-name {
    width: 100%;
    min-width: 0;
}

.ph-section.ph-name input {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
}

.ph-section.ph-material {
    width: 100%;
    min-width: 0;
}

.ph-section.ph-material .btn {
    width: 100% !important;
    justify-content: flex-start;
    text-align: left;
    max-width: none !important;
}

.ph-section.ph-preview {
    width: 100%;
    display: flex;
    justify-content: center;
}

.ph-section.ph-summary {
    width: 100%;
    min-width: 0;
}

.ph-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ph-label {
    font-size: 11px;
    font-weight: 700;
    color: #9CA3AF;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* .product-info removed */

/* .input-group and .input-group label removed (duplicates) */

.material-preview-container {
    width: 100%;
    max-width: 340px;
    height: 160px;
    border-radius: 12px;
    border: 1px solid #E5E5E5;
    background-color: #FAFAFA;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.material-preview-rect {
    width: 110px;
    height: 85px;
    margin: 0 auto;
    position: relative;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    background-size: cover;
    background-position: center;
    background-color: #ddd;
}

.edge-label {
    position: absolute;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.7);
    /* Readable background */
    padding: 2px 4px;
    border-radius: 4px;
    white-space: nowrap;
}

.edge-label.pos-a {
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
}

.edge-label.pos-b {
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
}

.edge-label.pos-c {
    right: 100%;
    margin-right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

.edge-label.pos-d {
    left: 100%;
    margin-left: 5px;
    top: 50%;
    transform: translateY(-50%);
}

/* D = Right */

/* Parts Table */
.parts-table-wrapper {
    overflow-x: auto;
}

/* Modern Table */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    /* Important for border-radius */
    font-size: 13px;
}

th {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid #E5E5E5;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 8px;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

.col-name input {
    width: 100%;
    min-width: 120px;
}

.col-dim input {
    width: 80px;
    /* Wider for 4 digits */
    text-align: center;
}

.col-qty input {
    width: 60px;
    text-align: center;
}

.col-grain {
    text-align: center;
}

.col-grain input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.col-edges {
    width: 260px;
    /* Fixed width for complex edges control */
}

/* Drastically reduced */

.edge-controls {
    display: flex;
    align-items: center;
}

.individual-edges {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 8px;
}

.edge-group {
    display: flex;
    flex-direction: row;
    /* Side by side Label + Select */
    align-items: center;
    gap: 2px;
}

.edge-group span {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 9px;
    width: 8px;
    /* Fixed width for alignment */
}

.edge-select {
    width: 65px;
    padding: 0;
    font-size: 10px;
    height: 18px;
    /* Even smaller */
    text-align: center;
}

/* Button Refinement */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 5px rgba(0, 102, 204, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.4);
}

.btn-secondary {
    background-color: #F5F5F7;
    color: var(--text-primary);
    border: 1px solid transparent;
}

.btn-secondary:hover {
    background-color: #E5E5E5;
}

.btn-danger {
    color: var(--text-secondary);
    background: white;
    padding: 6px;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-danger:hover {
    color: var(--danger-color);
    background-color: #FFF0F0;
    border-color: #FFD4D4;
}

.btn-danger svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.btn-outline {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.actions {
    margin-top: 30px;
    display: flex;
    justify-content: flex-start;
}

footer {
    margin-top: 60px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

#submit-order-btn {
    white-space: normal;
    /* Allow text wrapping */
    max-width: 100%;
    height: auto;
    padding: 12px 24px;
    line-height: 1.4;
}

/* Custom Supply Toggle */
.supply-type {
    display: flex;
    background: #F5F5F7;
    padding: 4px;
    border-radius: 12px;
    border: 1px solid #E5E5E5;
    gap: 4px;
    width: fit-content;
}

.radio-label {
    flex: 1;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.radio-label:has(input:checked) {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.radio-label input {
    display: none;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    overflow-x: auto;
    padding-bottom: 10px; /* Větší prostor pro scrollbar */
    -webkit-overflow-scrolling: touch;
    /* scrollbar-width: none; */
}

/* Zobrazení elegantního scrollbaru */
.category-tabs::-webkit-scrollbar {
    height: 6px;
}
.category-tabs::-webkit-scrollbar-track {
    background: #f1f1f1; 
    border-radius: 10px;
}
.category-tabs::-webkit-scrollbar-thumb {
    background: #c1c1c1; 
    border-radius: 10px;
}
.category-tabs::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8; 
}

.cat-tab {
    padding: 8px 16px;
    background: #F5F5F7;
    border: 1px solid #E5E5E5;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.cat-tab:hover {
    background: #E5E5E5;
}

.cat-tab.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: flex-start;
    /* Fixes top cutoff */
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
    padding: 40px 20px;
    overflow-y: auto;
    transform: translateZ(0);
    /* Force layer */
}

.modal.hidden {
    display: none !important;
    opacity: 0;
}

.modal-content {
    background-color: white;
    width: 95%;
    max-width: 900px;
    height: 85vh;
    max-height: 90vh;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    border-bottom: 1px solid #F5F5F7;
    background: white;
    flex-shrink: 0;
}

.modal-body {
    padding: 20px 30px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* Added gap */
}

.modal-header h2 {
    font-size: 24px;
    font-weight: 600;
}

.close-modal {
    background: #F5F5F7;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--text-secondary);
}

.close-modal:hover {
    background-color: #E5E5E5;
    color: var(--text-primary);
}



#material-search {
    width: 100%;
    padding: 16px;
    /* Larger touch area */
    font-size: 16px;
    border-radius: 12px;
    background-color: #F5F5F7;
    border: 1px solid transparent;
}

#material-search:focus {
    background-color: white;
    border-color: var(--primary-color);
}

.material-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

.material-item {
    border: 1px solid #E5E5E5;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    background: white;
}

.material-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.material-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.material-info {
    padding: 8px;
    text-align: center;
}

.material-code {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 4px;
}

.material-name {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Custom Confirmation Modal */
.confirm-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 4000;
    /* Highest priority */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.confirm-modal.visible {
    opacity: 1;
    visibility: visible;
}

.confirm-box {
    background: white;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confirm-modal.visible .confirm-box {
    transform: scale(1);
}

.confirm-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

/* Hide Number Input Spinners */
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
input[type=number] {
    -moz-appearance: textfield;
}

#app-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 9;
    display: none;
}

/* Edge Visualization Rules */
.edge-label.active-edge {
    background-color: var(--primary-color) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(97, 183, 151, 0.4) !important;
    border-color: white !important;
    font-weight: 700 !important;
}

.edge-label.highlight {
    background-color: var(--brand-dark) !important;
    color: white !important;
    z-index: 20 !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3) !important;
    border: 2px solid white !important;
    font-weight: 800 !important;
    font-size: 13px !important;
    padding: 4px 8px !important;
    /* No transform to avoid jump */
}
/* Custom Toast Notification */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: #fff;
    border-left: 4px solid #e74c3c;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 16px 20px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: #333;
    max-width: 350px;
    animation: slideIn 0.3s ease-out forwards;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.toast.success {
    border-left-color: #2ecc71;
}

.toast.info {
    border-left-color: #3498db;
}

.toast-msg {
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: #999;
    font-size: 16px;
    cursor: pointer;
    margin-left: 10px;
    padding: 0;
}
.toast-close:hover {
    color: #333;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}
