/* ============================================================
   style.css  –  Sistema de Despacho Marítimo (Gantt)
   ============================================================ */

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3248;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --accent:    #6366F1;
  --accent-h:  #4f52d8;
  --success:   #10B981;
  --warning:   #F59E0B;
  --danger:    #EF4444;
  --label-w:   185px;
  --day-w:     38px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── HEADER ──────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 22px; }
.brand-title { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.2; }
.brand-sub   { font-size: 10px; color: var(--muted); }

.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }

.week-badge, .user-badge, .readonly-badge {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn-primary, .btn-ghost, .btn-danger {
  border: none; cursor: pointer; border-radius: 7px;
  font-size: 12px; font-weight: 600;
  padding: 7px 14px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: #3b1010; color: var(--danger); border: 1px solid #5b2020; }
.btn-danger:hover { background: #5b2020; }
.btn-ghost.icon-only { padding: 7px 10px; }

/* ── GANTT WRAP ──────────────────────────────────────────── */
.gantt-wrap {
  height: calc(100vh - 52px);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.gantt-scroll {
  flex: 1;
  overflow: auto;
}

.gantt-inner {
  display: inline-block;
  min-width: 100%;
  position: relative;
}

/* ── GANTT HEADER (timeline) ─────────────────────────────── */
.gantt-header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}

.gantt-header-label {
  width: var(--label-w);
  min-width: var(--label-w);
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.gantt-days { display: flex; flex: 1; }

.gantt-week-group {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.gantt-week-label {
  font-size: 9px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  padding: 3px 0 2px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .08em;
  background: rgba(99,102,241,.06);
}

.gantt-day-cells { display: flex; }

.gantt-day-cell {
  width: var(--day-w);
  min-width: var(--day-w);
  font-size: 9px;
  color: var(--muted);
  text-align: center;
  padding: 3px 0;
  border-right: 1px solid rgba(46,50,72,.5);
  cursor: default;
  line-height: 1.3;
}
.gantt-day-cell:last-child { border-right: none; }
.gantt-day-cell.is-weekend { color: #7c7fff; opacity: .7; }
.gantt-day-cell.is-today {
  background: rgba(99,102,241,.12);
  font-weight: 700;
}

.day-today-badge {
  display: block;
  font-size: 8px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: .06em;
}

/* ── GANTT ROWS ──────────────────────────────────────────── */
.gantt-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}
.gantt-row:hover { background: rgba(255,255,255,.015); }

.gantt-row-label {
  width: var(--label-w);
  min-width: var(--label-w);
  flex-shrink: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2px;
}

.row-nave {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-naviera {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.row-fruta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  background: #2d1a06;
  color: #f97316;
  border: 1px solid #4a2d0a;
  border-radius: 20px;
  padding: 2px 7px;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row-zarpe-date {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.row-urgency {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 2px;
  width: fit-content;
}
.zarpe-ok      { background: #0d2f20; color: #10B981; border: 1px solid #0d4a2a; }
.zarpe-soon    { background: #2a1f00; color: #F59E0B; border: 1px solid #4a3800; }
.zarpe-urgent  { background: #2e1106; color: #f97316; border: 1px solid #4a2008; }
.zarpe-overdue { background: #2e0606; color: var(--danger); border: 1px solid #4a0808; }

.row-edit-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 10px;
  padding: 0; margin-top: 4px;
  opacity: 0; transition: opacity .15s;
  display: flex; align-items: center; gap: 3px;
  width: fit-content;
}
.gantt-row:hover .row-edit-btn { opacity: 1; }
.row-edit-btn:hover { color: var(--accent); }

/* ── GANTT TIMELINE AREA ─────────────────────────────────── */
.gantt-row-timeline {
  flex: 1;
  position: relative;
  min-height: 185px;
}

/* vertical day grid lines */
.gantt-grid-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: rgba(46,50,72,.6);
  pointer-events: none;
  z-index: 1;
}
.gantt-grid-line.is-today-line {
  background: var(--accent);
  opacity: .5;
  width: 2px;
  z-index: 2;
}

/* ── STAGE BARS ──────────────────────────────────────────── */
.stage-bar {
  position: absolute;
  top: 10px;
  height: 34px;
  border-radius: 7px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 7px;
  transition: filter .15s, top .15s;
  user-select: none;
  border: 1.5px solid rgba(255,255,255,.12);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  z-index: 3;
}
.stage-bar:hover {
  filter: brightness(1.2);
  top: 8px;
  z-index: 10;
  border-color: rgba(255,255,255,.3);
}

.bar-top-row {
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}
.bar-active-arrow {
  font-size: 9px;
  flex-shrink: 0;
  color: rgba(255,255,255,.9);
}
.bar-icon {
  font-size: 11px;
  flex-shrink: 0;
  line-height: 1;
}
.bar-name {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,.95);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-progress-track {
  height: 3px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  margin-top: 3px;
  overflow: hidden;
}
.bar-progress-fill {
  height: 100%;
  background: rgba(255,255,255,.7);
  border-radius: 2px;
}

.stage-bar.is-active {
  border-color: rgba(255,255,255,.3);
  box-shadow: 0 0 0 2px rgba(255,255,255,.12), 0 3px 12px rgba(0,0,0,.5);
}

/* ── TASK PANELS (inline below bar) ─────────────────────── */
.stage-task-panel {
  position: absolute;
  top: 52px;
  padding: 0 5px;
  overflow: hidden;
  z-index: 2;
}

.mini-task-ver {
  font-size: 9px;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 3px;
  text-decoration: underline;
  white-space: nowrap;
}
.mini-task-ver:hover { color: var(--accent); }

.mini-task-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 0;
  cursor: pointer;
}
.mini-task-item:hover .mini-task-name { color: var(--text); }

.mini-task-check {
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--surface2);
  display: inline-block;
  position: relative;
}
.mini-task-check.checked {
  background: var(--success);
  border-color: var(--success);
}
.mini-task-check.checked::after {
  content: '✓';
  position: absolute;
  color: #fff;
  font-size: 7px;
  font-weight: 900;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
}

.mini-task-name {
  font-size: 10px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-task-name.done {
  color: var(--muted);
  text-decoration: line-through;
}

.mini-task-more {
  font-size: 9px;
  color: var(--accent);
  cursor: pointer;
  margin-top: 2px;
  white-space: nowrap;
  padding: 0;
  background: none;
  border: none;
  text-align: left;
  font-family: inherit;
}
.mini-task-more:hover { text-decoration: underline; }

/* ── HOY LABEL ───────────────────────────────────────────── */
.hoy-label {
  position: absolute;
  top: 2px;
  font-size: 8px;
  font-weight: 900;
  color: var(--accent);
  text-align: center;
  width: var(--day-w);
  pointer-events: none;
  z-index: 4;
  letter-spacing: .08em;
}

/* ── ZARPE MARKER ────────────────────────────────────────── */
.zarpe-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 3;
}
.zarpe-marker-line {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 0;
  border-left: 1px dashed var(--success);
  opacity: .6;
}
.zarpe-marker-label {
  position: absolute;
  top: 6px;
  left: 3px;
  font-size: 9px;
  font-weight: 700;
  color: var(--success);
  white-space: nowrap;
  background: rgba(15,17,23,.85);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--success);
  opacity: .85;
}

/* ── GANTT FOOTER ────────────────────────────────────────── */
.gantt-footer {
  flex-shrink: 0;
  height: 32px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-size: 11px;
  color: var(--muted);
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
}
.footer-ciclo { font-weight: 700; color: var(--text); margin-right: 4px; }
.footer-stage { color: var(--text); }
.footer-arrow { color: var(--muted); }
.footer-days  { color: var(--accent); font-weight: 600; }

/* ── EMPTY STATE ─────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}
.empty-state i { font-size: 48px; opacity: .3; }
.empty-state p { font-size: 14px; }

/* ── MODALS ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: modal-in .18s ease;
}
.modal-box-wide { max-width: 680px; }

@keyframes modal-in {
  from { opacity:0; transform: scale(.95) translateY(6px); }
  to   { opacity:1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-icon  { font-size: 20px; }
.modal-title { font-size: 15px; font-weight: 700; flex: 1; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 16px;
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── FORMS ───────────────────────────────────────────────── */
.form-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.form-col       { flex: 1 1 100%; }
.form-col-half  { flex: 1 1 calc(50% - 6px); min-width: 120px; }
.form-divider   { flex: 1 1 100%; height: 1px; background: var(--border); margin: 2px 0; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 11px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  display: block;
  min-height: 36px;
}
.form-input:focus { border-color: var(--accent); }
textarea.form-input { resize: vertical; }

/* ── SETTINGS TABS ───────────────────────────────────────── */
.settings-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.stab {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 8px 14px; border-radius: 7px 7px 0 0;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.stab:hover { color: var(--text); }
.stab.active { color: var(--accent); border-bottom-color: var(--accent); }

.settings-hint {
  font-size: 12px; color: var(--muted);
  margin-bottom: 14px; line-height: 1.5;
}

.dur-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.dur-row:last-child { border-bottom: none; }
.dur-icon { font-size: 16px; width: 24px; text-align: center; flex-shrink: 0; }
.dur-name { font-size: 13px; font-weight: 600; flex: 1; color: var(--text); }
.dur-input {
  width: 64px;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 8px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.dur-input:focus { border-color: var(--accent); }
.dur-unit { font-size: 11px; color: var(--muted); }

.etapa-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.etapa-row:last-child { border-bottom: none; }
/* nueva fila vacía (recién agregada) no tiene border por el botón de abajo */
#settings-etapas-list .etapa-row:last-of-type { border-bottom: 1px solid var(--border); }
.etapa-color-pill {
  width: 14px; height: 14px; border-radius: 50%;
  flex-shrink: 0; border: 1px solid rgba(255,255,255,.2);
}

.plantilla-etapa { margin-bottom: 16px; }
.plantilla-etapa-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 7px 7px 0 0;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}
.plantilla-tasks { border: 1px solid var(--border); border-top: none; border-radius: 0 0 7px 7px; }
.ptask-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.ptask-row:last-child { border-bottom: none; }
.ptask-name {
  flex: 1;
  background: none; border: none; color: var(--text);
  font-size: 12px; font-family: inherit;
  outline: none; padding: 2px 4px;
}
.ptask-name:focus { background: var(--surface2); border-radius: 4px; }

/* ── TASK MODAL ──────────────────────────────────────────── */
.task-list { list-style: none; }
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  border-radius: 6px;
}
.task-item:last-child { border-bottom: none; }
.task-item:hover { background: var(--surface2); }

.task-check {
  width: 18px; height: 18px;
  appearance: none;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all .15s;
  background: var(--surface2);
}
.task-check:checked { background: var(--success); border-color: var(--success); }
.task-check:checked::after {
  content: '✓';
  position: absolute;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
}

.task-name { flex: 1; font-size: 13px; color: var(--text); }
.task-name.done { text-decoration: line-through; color: var(--muted); }

.task-del-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 13px;
  padding: 3px 6px; border-radius: 5px;
  opacity: 0; transition: opacity .12s, color .12s;
}
.task-item:hover .task-del-btn { opacity: 1; }
.task-del-btn:hover { color: var(--danger); }

.task-add-row { display: flex; gap: 8px; margin-top: 12px; }
.task-add-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 11px;
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.task-add-input:focus { border-color: var(--accent); }

.task-progress-bar-wrap {
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 14px;
}
.task-progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--success);
  transition: width .3s;
}

.advance-etapa-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
}

/* ── TOAST ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 48px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  animation: toast-in .2s ease;
  max-width: 280px;
}
.toast.toast-success { border-color: var(--success); }
.toast.toast-error   { border-color: var(--danger); }
@keyframes toast-in {
  from { opacity:0; transform: translateX(20px); }
  to   { opacity:1; transform: translateX(0); }
}