/* ═══════════════════════════════════════════════════════════════════════════
   Órdenes de Trabajo — Panel in-map + estilos de lista/detalle
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Panel principal (lista) ──────────────────────────────────────────────── */

#ordenes-panel {
    position: fixed;
    top: 0;
    left: calc(var(--sb-w) + 0px);
    right: 0;
    bottom: 0;
    width: auto;
    max-width: 1020px;
    max-height: none;
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: left var(--sb-transition);
}

body.sb-open #ordenes-panel {
    left: var(--sb-w-open);
}

#ordenes-panel-header {
    display: flex;
    align-items: center;
    padding: 10px 12px 10px 14px;
    background: #f0f4f8;
    border-bottom: 1px solid #d0dae6;
    flex-shrink: 0;
    gap: 8px;
}

#ordenes-panel-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a2635;
    flex: 1;
}

#ordenes-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* ── Formulario panel (crear/editar) ──────────────────────────────────────── */

#ordenes-form-panel {
    position: fixed;
    top: 0;
    left: min(calc(var(--sb-w) + 1028px), calc(100vw - 380px));
    bottom: 0;
    width: 380px;
    max-width: calc(100vw - var(--sb-w));
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    z-index: 1210;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: left var(--sb-transition);
}
body.sb-open #ordenes-form-panel {
    left: min(calc(var(--sb-w-open) + 1028px), calc(100vw - 380px));
}

#ordenes-form-header {
    display: flex;
    align-items: center;
    padding: 10px 12px 10px 14px;
    background: #f0f4f8;
    border-bottom: 1px solid #d0dae6;
    flex-shrink: 0;
    gap: 8px;
}

#ordenes-form-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a2635;
    flex: 1;
}

#ordenes-form-body {
    overflow-y: auto;
    flex: 1;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#ordenes-form-body .prod-field {
    position: relative;
}

/* ── Multi-asset selector ─────────────────────────────────────────────────── */
.om-assets-btn {
    width: 100%;
    text-align: left;
    padding: 6px 9px;
    border: 1px solid #cdd3da;
    border-radius: 5px;
    background: #fff;
    color: #263238;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.om-assets-btn:hover { border-color: #2a9d8f; }
.om-assets-badge {
    background: #2a9d8f;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
}
.om-assets-panel {
    position: absolute;
    z-index: 20;
    background: #fff;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    max-height: 240px;
    overflow-y: auto;
    padding: 6px 0;
    width: 100%;
}
.om-asset-group {
    padding: 2px 10px;
}
.om-asset-group + .om-asset-group {
    border-top: 1px solid #eef1f5;
    margin-top: 4px;
    padding-top: 6px;
}
.om-asset-campo {
    font-weight: 600;
}
.om-asset-lote {
    padding-left: 18px;
}

.prod-form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 4px;
}

/* ── Detalle panel ────────────────────────────────────────────────────────── */

#ordenes-detail-panel {
    position: fixed;
    top: 0;
    left: calc(var(--sb-w) + 0px);
    right: 0;
    bottom: 0;
    width: auto;
    max-width: 780px;
    max-height: none;
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: left var(--sb-transition);
}

body.sb-open #ordenes-detail-panel {
    left: var(--sb-w-open);
}

#ordenes-detail-header {
    display: flex;
    align-items: flex-start;
    padding: 10px 12px 10px 14px;
    background: #f0f4f8;
    border-bottom: 1px solid #d0dae6;
    flex-shrink: 0;
    gap: 8px;
}

#od-body {
    overflow-y: auto;
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── List wrap scrollable ─────────────────────────────────────────────────── */

#ordenes-list-wrap {
    overflow-y: auto;
    flex: 1;
}

/* ── Page layout ─────────────────────────────────────────────────────────── */

body.page-ordenes {
    background: #f0f4f8;
    min-height: 100vh;
}

body.page-ordenes #map { display: none; }

#ordenes-main {
    margin-left: var(--sb-w);
    transition: margin-left var(--sb-transition);
    padding: 24px 24px 40px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 0;
}

body.sb-open #ordenes-main {
    margin-left: var(--sb-w-open);
}

/* ── Page header ─────────────────────────────────────────────────────────── */

#ordenes-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

#ordenes-page-title h1 {
    font-size: 20px;
    font-weight: 700;
    color: #1a2635;
    margin: 0;
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */

.ordenes-tabs {
    display: flex;
    border-bottom: 2px solid #dce4ee;
    background: #fff;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    flex-shrink: 0;
}

.ordenes-tab {
    padding: 10px 22px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 600;
    color: #78909c;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    font-family: inherit;
}

.ordenes-tab:hover { color: #37474f; }

.ordenes-tab.active {
    color: #2a9d8f;
    border-bottom-color: #2a9d8f;
    background: #f7fffe;
}

/* ── Filters bar ─────────────────────────────────────────────────────────── */

.ordenes-filters {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #fff;
    border-bottom: 1px solid #f0f4f8;
    flex-wrap: wrap;
}

/* Search wrap — igual al de produccion pero con flex: none para no crecer demasiado */
.ord-search-wrap {
    flex-shrink: 0;
}

#filter-q {
    border: none;
    outline: none;
    font-size: 11px;
    color: #37474f;
    background: transparent;
    width: 130px;
    font-family: inherit;
}
#filter-q::placeholder { color: #b0bec5; }

/* X para limpiar búsqueda */
.ord-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: #90a4ae;
    font-size: 12px;
    padding: 0 1px;
    line-height: 1;
    flex-shrink: 0;
    visibility: hidden;
    pointer-events: none;
}
.ord-search-clear:hover { color: #546e7a; }
#filter-q:not(:placeholder-shown) ~ .ord-search-clear {
    visibility: visible;
    pointer-events: auto;
}


/* ── List wrap ───────────────────────────────────────────────────────────── */

#ordenes-list-wrap {
    background: #fff;
    border-radius: 0 0 8px 8px;
    border: 1px solid #dce4ee;
    border-top: none;
    flex: 1;
    min-height: 200px;
}

.ordenes-loading {
    padding: 32px;
    text-align: center;
    color: #90a4ae;
    font-size: 13px;
}

.ordenes-empty {
    padding: 48px 16px;
    text-align: center;
    color: #90a4ae;
    font-size: 13px;
}

/* ── Orden row ───────────────────────────────────────────────────────────── */

/*
  Grid columns:
  info(flex) | fecha(76px) | estado(88px) | prioridad(72px) | usuario(112px) | actions(52px)
*/
.orden-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px 76px 72px 112px 52px;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f4f8;
    cursor: pointer;
    transition: background 0.12s;
}

.orden-row:last-child { border-bottom: none; }
.orden-row:hover { background: #f5f9ff; }

.orden-row-info {
    min-width: 0;
}

.orden-row-titulo {
    font-size: 13px;
    font-weight: 600;
    color: #263238;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.orden-row-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 3px;
    font-size: 11px;
    color: #78909c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.orden-meta-sep {
    color: #c8d6e0;
    flex-shrink: 0;
}

.orden-tarea-label {
    font-style: italic;
}

.orden-meta-vacio {
    color: #b0bec5;
    font-style: italic;
}

.orden-row-cultivo {
    margin-top: 2px;
    font-size: 11px;
    color: #546e7a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.orden-row-fecha-plan {
    font-size: 11px;
    color: #546e7a;
    white-space: nowrap;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.orden-fecha-prefix {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #90a4ae;
    line-height: 1;
}

.prioridad-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    align-self: flex-start;
}
.prioridad-badge-urgente { background: #ffebee; color: #c62828; }
.prioridad-badge-normal  { background: #f0f4f8; color: #78909c; }
.prioridad-badge-baja    { background: #e3f2fd; color: #1565c0; }

.orden-row-usuario {
    overflow: hidden;
}

.orden-row-actions {
    display: flex;
    gap: 2px;
    justify-content: flex-end;
}

.btn-ord-edit, .btn-ord-archivar, .btn-ord-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 5px;
    border-radius: 4px;
    opacity: 0.45;
    line-height: 1;
}
.btn-od-rx-map {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    opacity: 0.6;
    vertical-align: middle;
}
.btn-od-rx-map:hover { opacity: 1; }
.od-rx-loading { color: #90a4ae; font-style: italic; }
.btn-ord-edit:hover      { background: #e3f0fb; opacity: 1; }
.btn-ord-delete:hover    { background: #ffebee; opacity: 1; }
.btn-ord-archivar:hover  { background: #eceff1; opacity: 1; }

.orden-usuario-chip {
    display: block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #e3f0fb;
    color: #1565c0;
}


/* ── Prioridad dot ───────────────────────────────────────────────────────── */

.prioridad-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(0,0,0,0.1);
}

.prioridad-urgente { background: #e53935; border-color: #c62828; }
.prioridad-normal  { background: #b0bec5; border-color: #90a4ae; }
.prioridad-baja    { background: #42a5f5; border-color: #1e88e5; }

/* ── Estado badge ────────────────────────────────────────────────────────── */

.estado-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.estado-abierto    { background: #1e88e5; }
.estado-en_proceso { background: #f57c00; }
.estado-finalizado { background: #2e7d32; }
.estado-cancelado  { background: #e53935; }

/* ── Tipo badge ──────────────────────────────────────────────────────────── */

.orden-tipo-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tipo-orden  { background: #e3f0fb; color: #1565c0; }
.tipo-evento { background: #f3e8ff; color: #7b1fa2; }

/* ── Modal overlay ───────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* ── Modal panel ─────────────────────────────────────────────────────────── */

.modal-panel {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-panel-wide {
    max-width: 680px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 16px 12px;
    background: #f0f4f8;
    border-bottom: 1px solid #d0dae6;
    flex-shrink: 0;
    gap: 8px;
}

.modal-title {
    font-size: 14px;
    font-weight: 700;
    color: #1a2635;
}

.modal-body {
    overflow-y: auto;
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 4px;
}

/* ── Detail panel header ─────────────────────────────────────────────────── */

#od-header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.od-panel-title {
    font-size: 14px;
    font-weight: 700;
    color: #1a2635;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* ── Datos generales: 2 columnas ─────────────────────────────────────────── */

.od-datos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
    background: #f7fafd;
    border: 1px solid #e0e7ef;
    border-radius: 8px;
    padding: 12px 14px;
}

.od-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.od-field {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.od-reassign-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.od-reassign-wrap select {
    flex: 1;
    padding: 4px 6px;
    font-size: 12px;
    border: 1px solid #cdd3da;
    border-radius: 4px;
    background: #fff;
    color: #263238;
}

.od-label {
    font-size: 10px;
    font-weight: 700;
    color: #90a4ae;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.od-value {
    font-size: 12px;
    color: #263238;
    font-weight: 500;
}

.od-field-meta {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid #e8edf3;
}

.od-label-meta {
    font-size: 10px;
    font-weight: 600;
    color: #b0bec5;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.od-value-meta {
    font-size: 11px;
    color: #90a4ae;
}

/* ── Section titles ──────────────────────────────────────────────────────── */

.od-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #78909c;
    margin-bottom: 8px;
}

/* ── Description section ─────────────────────────────────────────────────── */

#od-descripcion-section {
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid #e8ecf0;
    border-radius: 6px;
    margin-bottom: 4px;
}

.od-descripcion-text {
    font-size: 13px;
    color: #37474f;
    white-space: pre-wrap;
    line-height: 1.5;
}

.od-descripcion-archivos {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Acción section (cambio estado + nota + archivo) ────────────────────── */

.od-action-section {
    background: #f7fafd;
    border: 1px solid #e0e7ef;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.od-action-section .od-section-title {
    margin-bottom: 0;
}

.od-transition-btns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-trans {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s, transform 0.1s;
}
.btn-trans:hover { opacity: 0.85; transform: translateY(-1px); }

.btn-trans-proceso    { background: #f57c00; color: #fff; }
.btn-trans-finalizar  { background: #2e7d32; color: #fff; }
.btn-trans-cancelar   { background: #e53935; color: #fff; }
.btn-trans-archivar   { background: #78909c; color: #fff; }
.btn-trans-reasignar    { background: #5c6bc0; color: #fff; }
.btn-trans-comentar    { background: #fff; color: #546e7a; border: 1px solid #cdd3da; }
.btn-trans-comentar:hover { background: #f0f4f8; }
.btn-trans-archivo     { background: #fff; color: #546e7a; border: 1px solid #cdd3da; }
.btn-trans-archivo:hover { background: #f0f4f8; }

/* ── Log timeline ────────────────────────────────────────────────────────── */

.log-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
    padding-left: 20px;
    border-left: 2px solid #e0e7ef;
    margin-left: 6px;
    margin-bottom: 8px;
}

.log-entry {
    position: relative;
    padding: 0 0 16px 16px;
}

.log-entry:last-child {
    padding-bottom: 4px;
}

.log-entry-dot {
    position: absolute;
    left: -8px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #2a9d8f;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #e0e7ef;
    flex-shrink: 0;
}

.log-entry-body {
    background: #f7fafd;
    border: 1px solid #e8edf3;
    border-radius: 7px;
    padding: 8px 12px;
}

.log-entry-fecha {
    font-size: 11px;
    font-weight: 600;
    color: #546e7a;
    margin-bottom: 3px;
}

.log-entry-header {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.log-entry-autor {
    font-size: 12px;
    font-weight: 700;
    color: #263238;
}

.log-entry-sep {
    font-size: 11px;
    color: #b0bec5;
}

.log-entry-accion {
    font-size: 11px;
    color: #546e7a;
}

.log-entry-nota {
    font-size: 12px;
    color: #37474f;
    margin-bottom: 6px;
    white-space: pre-wrap;
    line-height: 1.5;
}

.log-entry-archivos {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.log-archivo-link {
    font-size: 11px;
    color: #1565c0;
    text-decoration: none;
    background: #e3f0fb;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
}
.log-archivo-link:hover { background: #bbdefb; }


.od-log-empty {
    font-size: 12px;
    color: #90a4ae;
    padding: 8px 0;
    margin: 0;
}

/* ── Add log form ────────────────────────────────────────────────────────── */

.od-log-nota-input {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    font-size: 12px;
    color: #263238;
    font-family: inherit;
    resize: vertical;
}
.od-log-nota-input:focus {
    outline: none;
    border-color: #2a9d8f;
    box-shadow: 0 0 0 2px rgba(42,157,143,0.15);
}


/* ── Lote picker in form ─────────────────────────────────────────────────── */

.om-lotes-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #cdd3da;
    border-radius: 6px;
    background: #fff;
    padding: 4px 0;
}

.om-lotes-empty {
    padding: 8px 12px;
    font-size: 12px;
    color: #90a4ae;
    margin: 0;
}

/* ── File upload in form ─────────────────────────────────────────────────── */

.om-files-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.om-file-btn {
    display: inline-block;
    cursor: pointer;
    align-self: flex-start;
}

.om-files-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.om-file-chip {
    display: inline-block;
    font-size: 11px;
    background: #e3f0fb;
    color: #1565c0;
    border-radius: 4px;
    padding: 2px 8px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    #ordenes-main {
        padding: 12px 10px 32px;
        margin-left: 0;
    }

    body.sb-open #ordenes-main {
        margin-left: 0;
    }

    .od-meta-grid {
        grid-template-columns: 1fr;
    }

    .modal-panel {
        max-width: 100%;
        max-height: 90vh;
    }

    .ordenes-filters {
        gap: 6px;
    }

    .ord-search-wrap {
        flex: 1;
    }
    #filter-q { width: 100%; }
}
