/* --- Variables & Reset --- */
:root {
    --primary-color: #a6192e; /* Kraftwerk Red */
    --primary-hover: #8a1225;
    --text-color: #333;
    --bg-color: #f4f4f4;
    --card-bg: #ffffff;
    --border-color: #ddd;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 6px;
    --success-green: #28a745;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Utilities --- */
.hidden { display: none !important; }
.mt-20 { margin-top: 20px; }
.text-center { text-align: center; }
.error-msg { color: var(--primary-color); font-size: 0.9rem; margin-top: 10px; }

/* --- Loading Spinner --- */
.spinner-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e0e0e0;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Header --- */
.app-header {
    background: var(--card-bg);
    padding: 0 20px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    z-index: 100;
}

.logo { height: 40px; width: auto; }

.header-controls { display: flex; align-items: center; gap: 20px; }
.user-info { display: flex; align-items: center; gap: 10px; font-weight: 500; }

/* --- Language Switcher Fix --- */
.lang-switcher { 
    position: relative; 
    display: inline-block; 
    padding-bottom: 15px; /* Bridge gap */
    margin-bottom: -15px;
}

.current-lang { 
    background: #fff; 
    border: 1px solid #ddd; 
    padding: 6px 12px; 
    border-radius: 4px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    gap: 8px;
    font-size: 0.9rem;
}

.lang-dropdown {
    display: none; 
    position: absolute; 
    right: 0; 
    top: 100%;
    background: white; 
    border: 1px solid var(--border-color);
    border-radius: var(--radius); 
    box-shadow: var(--shadow);
    min-width: 160px; 
    z-index: 1000;
    margin-top: -5px;
}

/* Bridge the gap so menu doesn't close when moving mouse slowly */
.lang-switcher::after {
    content: "";
    position: absolute;
    top: 100%;
    right: 0;
    width: 100%;
    height: 20px;
}

.lang-switcher:hover .lang-dropdown { 
    display: block; 
}

.lang-option {
    display: flex; 
    align-items: center; 
    gap: 10px; 
    padding: 10px 15px;
    text-decoration: none; 
    color: var(--text-color); 
    font-size: 0.9rem;
    transition: background 0.2s;
}

.lang-option:hover { 
    background: #f9f9f9; 
    color: var(--primary-color); 
}

/* --- Buttons --- */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary:hover { background-color: var(--primary-hover); }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    padding: 5px;
    display: flex;
    align-items: center;
}
.btn-icon:hover { color: var(--primary-color); }

.btn-small {
    padding: 5px 10px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 5px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #ddd;
    background: white;
    color: #555;
}
.btn-small:hover {
    background: #f9f9f9;
    border-color: #bbb;
    color: var(--primary-color);
}

/* SVG Icon Buttons */
.btn-svg {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    color: #666;
}
.btn-svg:hover { background: #f0f0f0; color: var(--primary-color); }
.btn-svg.save { color: var(--success-green); }
.btn-svg.delete:hover { color: var(--primary-color); background: #fff0f0; }

/* --- Forms --- */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 0.9rem; }

input[type="text"], input[type="password"], input[type="number"], input[type="tel"], select, textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); }

/* --- Google Style Search Bar --- */
.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 30px auto;
}

.search-input {
    width: 100%;
    padding: 12px 50px 12px 20px; 
    border: 1px solid #dfe1e5;
    border-radius: 24px; 
    font-size: 1rem;
    box-shadow: 0 1px 6px rgba(32,33,36,0.28);
    transition: box-shadow 0.2s;
    outline: none;
}

.search-input:focus {
    box-shadow: 0 1px 6px rgba(32,33,36,0.28), 0 0 0 2px rgba(166, 25, 46, 0.1);
    border-color: transparent;
}

.search-icon-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #5f6368;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Data Summary & Editable Fields --- */
.data-summary {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 20px;
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.summary-item label {
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    display: block;
    margin-bottom: 4px;
}

.summary-item span {
    font-size: 1.05rem;
    font-weight: 500;
    color: #333;
    display: block;
    padding: 5px; 
}

.editable-input {
    width: 100%;
    padding: 5px;
    border: 1px solid transparent; 
    background: transparent;
    font-family: inherit;
    font-size: 1.05rem;
    color: #333;
    border-radius: 4px;
    transition: all 0.2s;
}
.editable-input:hover { border-color: #ccc; background: #fff; }
.editable-input:focus { border-color: var(--primary-color); background: #fff; outline: none; }

.editable-textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
    padding: 5px;
    border: 1px solid transparent;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    border-radius: 4px;
    line-height: 1.4;
}
.editable-textarea:hover, .editable-textarea:focus { border-color: #ccc; background: #fff; outline: none; }

/* --- Item Table --- */
.item-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    background: white;
    border: 1px solid #eee;
}
.item-table th { background: #eee; padding: 10px; text-align: left; font-size: 0.9rem; color: #555; }
.item-table td { padding: 10px; border-bottom: 1px solid #eee; font-size: 0.95rem; }

/* --- Dashboard --- */
.app-container { flex: 1; display: flex; justify-content: center; padding: 40px 20px; overflow-y: auto; }
.card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    height: fit-content;
}
.card h2 { margin-bottom: 20px; color: var(--primary-color); }

.dashboard { width: 100%; max-width: 1200px; padding-bottom: 50px; }

/* Tabs */
.tabs { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid #e0e0e0; }
.tab-btn {
    background: none; border: none; padding: 10px 20px; font-size: 1rem; cursor: pointer;
    color: #666; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); font-weight: bold; }

.tab-content {
    display: none; background: var(--card-bg); padding: 30px;
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.tab-content.active { display: block; }

/* Transporter Grid */
.transporter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 10px;
}
.transporter-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    text-align: center;
}
.transporter-btn:hover { border-color: var(--primary-color); color: var(--primary-color); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

/* --- Full Screen Modal --- */
.modal-overlay {
    display: none; 
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); 
    z-index: 1500;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: #fff;
    width: 95%;
    height: 95%;
    max-width: 1400px;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-body { flex: 1; padding: 20px; overflow-y: auto; background: #fff; }

/* --- PACKING SYSTEM SPECIFIC --- */

.packing-layout { display: flex; flex-direction: column; gap: 25px; }
.level-section { background: #fdfdfd; border: 1px solid #eee; border-radius: 8px; padding: 15px; transition: all 0.3s; }

/* Collapsible Logic */
.level-section.collapsed { padding: 5px 15px; }
.level-section.collapsed .drop-zone { min-height: 0; height: 0; overflow: hidden; padding: 0; }

.level-header { display: flex; align-items: center; gap: 15px; margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.level-header h3 { font-size: 0.85rem; text-transform: uppercase; color: #888; letter-spacing: 1px; }

.drop-zone { display: flex; flex-wrap: wrap; gap: 15px; min-height: 100px; padding: 10px; border-radius: 6px; transition: background 0.2s; }
.drop-zone.drag-over { background: rgba(166, 25, 46, 0.05); outline: 2px dashed var(--primary-color); }

/* Unit Boxes */
.unit-box {
    background: white;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 12px;
    width: 200px;
    min-height: 80px;
    cursor: grab;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.unit-box.item-box { border-left: 4px solid #3498db; }
.unit-box.packet-box { border-left: 4px solid #f39c12; width: 220px; }
.unit-box.pallet-box { border-left: 4px solid #27ae60; width: 100%; max-width: 100%; }

.unit-box .title { font-weight: bold; font-size: 0.85rem; margin-bottom: 4px; display: block; }
.unit-box .info { 
    font-size: 0.75rem; color: #666; display: block; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

/* Nested Packets in Pallets (Horizontal Row) */
.pallet-packet-row {
    display: flex;
    flex-direction: row;
    gap: 12px;
    overflow-x: auto;
    padding: 10px 0;
    border-top: 1px solid #eee;
    margin-top: 10px;
}
.pallet-packet-row .packet-box { width: 180px; min-width: 180px; min-height: 60px; }

/* Content List */
.unit-content { margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee; max-height: 150px; overflow-y: auto; }
.content-item {
    font-size: 0.7rem; background: #f9f9f9; margin-bottom: 3px;
    padding: 4px 8px; border-radius: 4px; display: flex; justify-content: space-between; align-items: center;
}
.remove-btn { color: #ccc; cursor: pointer; font-weight: bold; }
.remove-btn:hover { color: var(--primary-color); }

/* Small Modal (Popups) */
.small-modal {
    background: white; padding: 25px; border-radius: 12px;
    width: 90%; max-width: 400px; position: relative;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}
.close-x {
    position: absolute; top: 12px; right: 12px;
    background: none; border: none; cursor: pointer; color: #999;
}
.close-x:hover { color: var(--primary-color); }

/* Add Button */
.btn-add-unit {
    width: 36px; height: 36px; border-radius: 50%;
    border: 2px dashed #ccc; background: none; color: #aaa;
    font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-add-unit:hover { border-color: var(--primary-color); color: var(--primary-color); background: #fff; }

/* Saving Indicator */
#saveTick {
    position: fixed; bottom: 20px; right: 20px;
    background: var(--success-green); color: white;
    padding: 8px 15px; border-radius: 20px; font-size: 0.8rem;
    display: flex; align-items: center; gap: 8px;
    opacity: 0; transition: opacity 0.5s; z-index: 3000;
}
#saveTick.show { opacity: 1; }

/* Toggle Switch */
.toggle-switch { position: relative; display: inline-block; width: 50px; height: 24px; vertical-align: middle; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 24px;
}
.slider:before {
    position: absolute; content: ""; height: 16px; width: 16px;
    left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(26px); }