* {
    box-sizing: border-box;
}

:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --success: #27ae60;
    --bg: #f4f7f6;
    --white: #ffffff;
    --empty: #ecf0f1;
    --occupied: #3498db;
    --cell-size: clamp(28px, 3.2vw, 48px);
}

.hidden {
    display: none !important;
}

.auth-gate {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, rgba(44, 62, 80, 0.94), rgba(23, 32, 42, 0.92));
    z-index: 5000;
}

.auth-card {
    width: min(100%, 420px);
    background: #ffffff;
    border-radius: 18px;
    padding: 32px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-brand {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

.auth-card h2 {
    margin: 0;
    color: var(--primary);
}

.auth-card p {
    margin: 0 0 8px 0;
    color: #64748b;
}

.auth-card label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
}

.auth-card input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
}

.auth-card input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.18);
}

.auth-error {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #be123c;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.auth-submit {
    margin-top: 8px;
    width: 100%;
}

.out-of-stock {
    outline: 2px solid #e74c3c !important;
    outline-offset: -2px;
}

/* Modal Listado Total */
.modal-full {
    width: 90% !important;
    max-width: 1000px !important;
}

.refs-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.refs-table th, .refs-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.refs-table th {
    background: #f8fafc;
    color: #64748b;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.qty-pill {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: bold;
}

.qty-pill.zero { background: #fee2e2; color: #b91c1c; }
.qty-pill.ok { background: #dcfce7; color: #15803d; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background-color: var(--bg);
    color: var(--primary);
}

header {
    background-color: var(--primary);
    color: white;
    padding: 0.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    min-height: 60px;
}

.header-logo h1 {
    margin: 0;
    font-size: 1.2rem;
    letter-spacing: 1px;
}

.header-logo span {
    color: var(--accent);
    font-weight: bold;
}

.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 600px;
    margin: 0 2rem;
}

.search-container {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.search-container:focus-within {
    background: white;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.3);
    border-color: var(--accent);
}

.search-icon {
    margin-right: 10px;
    font-size: 1.1rem;
    opacity: 0.7;
}

#searchInput {
    background: transparent;
    border: none;
    color: inherit;
    width: 100%;
    font-size: 1rem;
    outline: none;
    padding: 0.2rem 0;
}

.search-container:focus-within #searchInput {
    color: #333;
}

.search-shortcut {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.7rem;
    margin-left: 10px;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
}

.search-container:focus-within .search-shortcut {
    color: #888;
    border-color: #ddd;
}

.icon-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

.search-results-panel {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    background: white;
    color: #333;
    border: 1px solid #ddd;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    z-index: 1000;
    max-height: 500px;
    overflow-y: auto;
    border-radius: 8px;
}

.search-result-item {
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.search-result-item:hover {
    background-color: #f8fbff;
}

.search-result-item strong {
    color: var(--accent);
    font-size: 1.05rem;
}

.search-result-info {
    flex: 1;
}

.search-result-specs {
    color: #7f8c8d;
    font-size: 0.8rem;
    display: block;
    margin-top: 2px;
}

.search-result-location {
    font-size: 0.75rem;
    color: #95a5a6;
    background: #f1f2f6;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 4px;
    display: inline-block;
}

.search-result-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.locate-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: transform 0.1s;
}

.locate-btn:hover {
    background: #2980b9;
    transform: scale(1.05);
}

/* Modal Details Styles */
.component-list-mini {
    list-style: none;
    padding: 0;
    margin: 0;
}

.component-list-mini li {
    padding: 8px 12px;
    border: 1px solid #edf2f7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    margin-bottom: 5px;
    border-radius: 6px;
    gap: 8px;
}

.mini-comp-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.mini-comp-name {
    font-weight: 600;
    color: var(--primary);
    flex: 1;
}

.mini-comp-meta {
    font-size: 0.75rem;
    color: #718096;
    background: #f7fafc;
    padding: 2px 6px;
    border-radius: 4px;
}

.mini-comp-qty {
    font-weight: bold;
    color: var(--accent);
    min-width: 50px;
    text-align: right;
}

.mini-comp-actions {
    display: flex;
    gap: 5px;
}

.icon-btn-small {
    background: none;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.icon-btn-small:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

.icon-btn-small.delete-btn {
    color: #e53e3e;
}

.icon-btn-small.delete-btn:hover {
    background: #fff5f5;
}

.mini-comp-name {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-comp-meta {
    font-size: 0.75rem;
    color: #7f8c8d;
    background: #f8f9fa;
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid #eee;
    text-align: center;
    display: block;
}

.mini-comp-qty {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-align: right;
}

.mini-comp-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.small-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    background: #f1f2f6;
    color: #2c3e50;
    border: 1px solid #dcdde1;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    min-width: 65px;
}

.small-btn:hover {
    background: #e1e2e6;
}

.delete-btn {
    background: white;
    color: #e74c3c;
    border: 1px solid #fab1a0;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
}

.delete-btn:hover {
    background: #ff7675;
    color: white;
    border-color: #ff7675;
}

main {
    display: flex;
    height: calc(100vh - 60px);
    overflow: hidden; /* Evita que el body scrollee */
}

#sidebar {
    width: 260px;
    background: white;
    padding: 1rem;
    border-right: 1px solid #e2e8f0;
    flex-shrink: 0;
    overflow-y: auto;
}

.collapsible-section {
    margin-bottom: 5px;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 8px 0;
    margin: 0;
    user-select: none;
    color: var(--text);
    font-size: 1.1rem;
}

.collapsible-header:hover {
    color: var(--primary);
}

.toggle-icon {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.collapsible-content {
    display: block; /* Abierto por defecto */
    padding-top: 10px;
}

.sidebar-group-header {
    font-size: 0.85rem;
    font-weight: 700;
    color: #7f8c8d;
    margin: 15px 0 5px 0;
    padding-bottom: 3px;
    border-bottom: 1px solid #eee;
}

#viewArea {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    background-color: #f8fafc;
}

#currentContainerTitle {
    position: absolute;
    top: 15px;
    left: 20px;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.details-panel {
    flex: 0 0 33%;
    min-width: 320px;
    background: white;
    border-left: 1px solid #e2e8f0;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.details-placeholder {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: center;
    color: #95a5a6;
    text-align: center;
    font-style: italic;
}

.cell.selected, .large-drawer-full-width.selected, .occupied-large.selected {
    outline: 4px solid var(--accent);
    outline-offset: -2px;
    z-index: 100 !important;
    position: relative;
    box-shadow: 0 0 15px rgba(211, 84, 0, 0.5);
}

.grid-container {
    display: grid;
    gap: 4px;
    margin-top: 1rem;
    background: #ffffff;
    padding: 8px;
    border-radius: 8px;
    width: fit-content;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.large-drawer-full-width {
    grid-column: 1 / -1;
    height: calc(var(--cell-size) * 0.7);
    margin-top: 6px;
    background: white;
    border: 1px dashed #dee2e6;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.large-drawer-full-width:hover {
    background: #f1f2f6;
    border-color: var(--accent);
}

.occupied-large {
    background: var(--occupied);
    color: white;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px dashed rgba(255,255,255,0.3);
}

.fold-container {
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: center;
}

.fold-container h3 {
    display: none;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.7rem, 0.8vw, 0.9rem);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    color: #94a3b8;
}

.cell:hover {
    filter: brightness(0.9);
    cursor: pointer;
}

.cell.selected, .large-drawer-full-width.selected {
    outline: 3px solid #e67e22 !important;
    background-color: rgba(230, 126, 34, 0.1) !important;
    box-shadow: 0 0 15px rgba(230, 126, 34, 0.4);
    z-index: 10;
}

.large-drawer {
    width: 200px;
    height: 100px;
    background: var(--empty);
    border: 2px dashed #999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
    margin-top: 10px;
}

.occupied-large {
    background: var(--occupied);
    color: white;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px dashed rgba(255,255,255,0.3);
}

.multi-occupied-large {
    background: #2980b9; /* Azul para indicar múltiples referencias */
    box-shadow: 0 4px 12px rgba(41, 128, 185, 0.3);
}

.occupied-large:hover {
    transform: scale(1.02);
    filter: brightness(1.1);
}

.sidebar-group-header {
    background: #f1f2f6;
    padding: 8px 15px;
    font-size: 0.7rem;
    font-weight: 800;
    color: #7f8c8d;
    margin-top: 15px;
    margin-bottom: 5px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.container-item {
    margin-bottom: 4px;
}

.container-item button {
    width: 100%;
    text-align: left;
    padding: 10px 15px;
    background: white;
    border: 1px solid #eee;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.container-item button:hover {
    background: #f8fbff;
    border-color: var(--accent);
    color: var(--accent);
    padding-left: 20px;
}

.pending-list {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.85rem;
    background: #fff9e6;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #ffeeba;
}

.compact-list {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.8rem;
    background: #fff5f5;
    padding: 0.5rem;
    border-radius: 4px;
    border: 1px solid #feb2b2;
}

.compact-item {
    padding: 4px 8px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    cursor: pointer;
}

.compact-item:hover {
    background: rgba(0,0,0,0.02);
}

.compact-item .name { font-weight: 600; color: #c53030; }
.compact-item .loc { color: #718096; font-size: 0.7rem; }

.secondary-btn {
    background: #edf2f7;
    color: #4a5568;
    border: 1px solid #cbd5e0;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
    margin-top: 10px;
}

.secondary-btn:hover {
    background: #e2e8f0;
}

.pending-item {
    padding: 0.3rem;
    border-bottom: 1px solid #ddd;
    cursor: grab;
    user-select: none;
}

.pending-item:hover {
    background: #f0e4b8;
}

.pending-item:active {
    cursor: grabbing;
}

.cell.dragging-over {
    background: #bdc3c7 !important;
    outline: 2px dashed var(--accent);
}

.cell.occupied {
    background: var(--occupied);
    color: white;
    font-weight: bold;
    border: none;
}

.cell.multi-occupied {
    background: var(--occupied); /* Ambos en azul según petición */
    position: relative;
}

.cell.multi-occupied::after {
    content: '+';
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: 0.7rem;
    font-weight: bold;
    color: rgba(255,255,255,0.9);
}

.component-list-mini {
    list-style: none;
    padding: 0;
    margin: 5px 0;
    font-size: 0.8rem;
    border-top: 1px solid #eee;
}

.component-list-mini li {
    padding: 3px 0;
    border-bottom: 1px solid #eee;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: var(--white);
    margin: 2% auto;
    padding: 40px 30px 30px 30px;
    width: 90%;
    max-width: 650px;
    max-height: 90vh;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
}

#compForm {
    overflow-y: auto;
    padding-right: 10px;
    display: flex;
    flex-direction: column;
}

/* Estilizar la barra de desplazamiento interna del formulario */
#compForm::-webkit-scrollbar {
    width: 6px;
}

#compForm::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 10px;
}

.success-btn {
    margin-top: 15px;
    flex-shrink: 0;
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #666;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
}

.close:hover {
    color: #e74c3c;
}

.form-group {
    margin-bottom: 0.7rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: #555;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px; /* Aumentado para mayor comodidad */
    box-sizing: border-box;
    border: 1px solid #dce1e5;
    border-radius: 6px;
    font-size: 1rem; /* Aumentado a 1rem para mejor legibilidad */
    background-color: #ffffff;
    transition: all 0.2s;
    color: #333;
}

/* Evitar que campos readonly parezcan bloqueados visualmente si queremos editarlos */
.form-group input[readonly] {
    background-color: #f8fafc;
    cursor: default;
}

/* Caso específico para Cantidad y Ubicación que el usuario quiere editar */
#compQty, #compPos {
    background-color: #ffffff !important;
    cursor: text !important;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

#dynamicFields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 15px;
    border-top: 1px solid #eee;
    padding-top: 1rem;
    margin-top: 0.5rem;
}

/* El primer campo dinámico (suele ser función o valor) ocupa todo el ancho */
#dynamicFields .form-group:first-child {
    grid-column: span 2;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.7rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
}

.secondary-btn {
    background: #7f8c8d;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    margin-top: 5px;
}

.dialog-content {
    max-width: 400px;
    text-align: center;
    padding: 30px;
}

.dialog-content h3 {
    margin-top: 0;
    color: var(--primary);
}

.dialog-content p {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
}

.dialog-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.dialog-actions button {
    min-width: 100px;
    margin: 0;
}

#dialogCancelBtn {
    background: #f1f2f6;
    color: #2c3e50;
    border: 1px solid #dcdde1;
}

#dialogCancelBtn:hover {
    background: #e1e2e6;
}

/* Ajustes para el modal si es un alert (solo un botón) */
.dialog-actions.alert-mode #dialogCancelBtn {
    display: none;
}

.danger-btn {
    background: transparent;
    border: 1px solid #ff7675;
    color: #d63031;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.danger-btn:hover {
    background: #ff7675;
    color: white;
}

.danger-btn { background-color: transparent; border: 1px solid #ff7675; color: #d63031; padding: 10px; border-radius: 8px; cursor: pointer; font-weight: 600; transition: all 0.2s; }
.danger-btn:hover { background-color: #ff7675; color: white; }
