/**
 * Planning Timeline - Styles
 * Follows Dolibarr theme (like Board)
 */

/* Page layout - transparent background, inherit Dolibarr colors */
.pl-timeline-page {
  margin-top: 10px;
  padding: 10px;
  background: transparent;
  color: var(--colortext, #333);
  /* Constrain to viewport: 100vh - Dolibarr top menu (~50px) - margins (~70px) */
  height: calc(100vh - 130px);
  max-height: calc(100vh - 130px);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* NO scrollbars on page wrapper */
  overflow-x: hidden; /* Explicit: no horizontal scroll on page */
  box-sizing: border-box;
}

/* Header - fixed height, no shrink */
.pl-timeline-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.pl-timeline-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  flex: 0 0 auto;
  color: inherit;
}

/* Tabs */
.pl-timeline-tabs {
  display: flex;
  gap: 4px;
}

.pl-tab {
  padding: 8px 20px;
  border-radius: 8px 8px 0 0;
  background: rgba(0,0,0,0.05);
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.15s;
}

.pl-tab:hover {
  background: rgba(0,0,0,0.08);
  text-decoration: none;
}

.pl-tab-active {
  background: #19a87a;
  color: #fff;
}

.pl-tab-active:hover {
  background: #15956c;
}

/* Controls */
.pl-timeline-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pl-timeline-controls label {
  font-weight: 600;
}

.pl-timeline-controls select {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.15);
}

/* Two-panel container - fills remaining height */
.pl-timeline-container {
  display: flex;
  gap: 16px;
  flex: 1 1 0;
  min-height: 0; /* Critical: allow flex child to shrink below content */
  overflow: hidden;
  overflow-x: hidden; /* Explicit: no horizontal scroll on container */
}

/* Left panel - Job card */
.pl-timeline-left {
  flex: 0 0 280px;
  overflow-y: auto;
  overflow-x: hidden; /* No horizontal scroll on left panel */
  min-height: 0;
}

.pl-job-card {
  background: var(--colorbackbody, #ffffff);
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  padding: 14px;
  min-height: 180px;
  color: var(--colortext, #333);
}

.pl-job-card-placeholder {
  color: #888;
  font-style: italic;
  text-align: center;
  padding: 40px 10px;
}

.pl-job-card-header {
  border-bottom: 1px solid rgba(0,0,0,0.08);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.pl-job-card-title {
  font-size: 15px;
  font-weight: 700;
  color: inherit;
  margin-bottom: 2px;
}

.pl-job-card-machine {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}

.pl-job-card-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Stats row */
.pl-job-card-row {
  display: flex;
  gap: 8px;
}

.pl-job-card-stat {
  flex: 1;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  padding: 8px 6px;
  text-align: center;
}

.pl-job-card-stat-value {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--colortext, #333);
}

.pl-job-card-stat-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  color: #888;
  margin-top: 2px;
}

.pl-job-card-notice {
  background: rgba(182,146,26,0.1);
  color: #8a6d00;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 4px;
  text-align: center;
}

.pl-job-card-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pl-job-card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.3px;
}

.pl-job-card-segments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pl-job-card-seg {
  background: rgba(25,168,122,0.12);
  color: #148a62;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.pl-job-card-seg-overflow {
  background: rgba(188,0,0,0.1);
  color: #bc0000;
}

/* Collapsible details */
.pl-job-card-details {
  border-top: 1px solid rgba(0,0,0,0.06);
  padding-top: 10px;
  margin-top: 4px;
}

.pl-job-card-details summary {
  font-size: 12px;
  color: #666;
  cursor: pointer;
  user-select: none;
}

.pl-job-card-details summary:hover {
  color: #333;
}

.pl-job-card-details-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pl-job-card-detail {
  font-size: 12px;
  color: #555;
}

.pl-job-card-detail span {
  color: #888;
}

/* Right panel - Timeline (ONLY scroll container for horizontal) */
.pl-timeline-right {
  flex: 1 1 0;
  width: 0; /* Force flex to control width, enables overflow */
  overflow: auto; /* Both X and Y scroll here only */
  min-height: 0; /* Critical: allow shrinking */
  min-width: 0;  /* Critical: allow shrinking */
}

.pl-timeline-grid {
  display: flex;
  flex-direction: column;
  /* CSS variables set by JS: dayWidth = clamp(55, availableWidth/days, 110) */
  --pl-day-count: 14;
  --pl-day-width: 80px;
  --pl-machine-width: 140px;
  /* Exact width from CSS vars */
  width: calc(var(--pl-machine-width) + (var(--pl-day-count) * var(--pl-day-width)));
  min-width: calc(var(--pl-machine-width) + (var(--pl-day-count) * var(--pl-day-width)));
  position: relative; /* Anchor for toggle button positioning */
}

/* Compact mode adjustments for narrow day columns */
.pl-timeline-grid.pl-compact .pl-tl-day-cell {
  padding: 4px 2px;
}
.pl-timeline-grid.pl-compact .pl-tl-day-label {
  font-size: 10px;
}
.pl-timeline-grid.pl-compact .pl-tl-day-date {
  font-size: 9px;
}
.pl-timeline-grid.pl-compact .pl-tl-job-block {
  padding: 2px 3px;
  font-size: 9px;
}
.pl-timeline-grid.pl-compact .pl-tl-job-hours {
  display: none;
}
.pl-timeline-grid.pl-compact .pl-tl-job-ref {
  font-size: 8px;
}

.pl-timeline-loading,
.pl-timeline-error,
.pl-tl-empty {
  padding: 40px;
  text-align: center;
  color: #666;
  font-style: italic;
}

.pl-timeline-error {
  color: #bc0000;
}

/* Timeline rows */
.pl-tl-row {
  display: flex;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.pl-tl-header-row {
  background: var(--colorbackbody, #ffffff);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 2px solid rgba(0,0,0,0.1);
}

.pl-tl-machine-row {
  transition: background 0.1s;
}

.pl-tl-machine-row:nth-child(even) {
  background: rgba(0,0,0,0.015);
}

.pl-tl-machine-row:hover {
  background: rgba(25,168,122,0.04);
}

/* Machine cell - sticky on horizontal scroll */
.pl-tl-machine-cell {
  flex: 0 0 var(--pl-machine-width, 140px);
  padding: 10px 12px;
  border-right: 2px solid rgba(0,0,0,0.08);
  background: var(--colorbackbody, #ffffff);
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-sizing: border-box;
  position: sticky;
  left: 0;
  z-index: 2;
}

.pl-tl-header-machine {
  font-weight: 700;
  font-size: 12px;
  color: #666;
  z-index: 11; /* Above header row and machine cells */
}

.pl-tl-machine-ref {
  font-weight: 700;
  font-size: 13px;
  color: var(--colortext, #333);
}

.pl-tl-machine-label {
  font-size: 10px;
  color: #888;
  margin-top: 2px;
}

/* Day cells */
.pl-tl-day-cell {
  flex: 0 0 var(--pl-day-width, 80px);
  min-height: 54px;
  padding: 6px 4px;
  border-right: 1px solid rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  background: transparent;
  box-sizing: border-box;
}

.pl-tl-header-day {
  text-align: center;
  min-height: auto;
  padding: 8px 6px;
  background: var(--colorbackbody, #ffffff);
  border-bottom: 2px solid rgba(0,0,0,0.08);
}

.pl-tl-day-label {
  font-weight: 700;
  font-size: 12px;
  color: var(--colortext, #333);
}

.pl-tl-day-date {
  font-size: 10px;
  color: #888;
}

/* Job blocks - consistent green (like Board in-progress) */
.pl-tl-job-block {
  background: linear-gradient(135deg, #19a87a 0%, #148a62 100%);
  color: #fff;
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2px;
  box-sizing: border-box;
  overflow: hidden;
}

.pl-tl-job-block:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

/* Gantt mode: container for job bars */
.pl-tl-gantt-row {
  position: relative;
}

.pl-tl-gantt-bars-container {
  position: absolute;
  top: 0;
  left: 140px; /* Match machine cell width */
  right: 0;
  height: 100%;
  pointer-events: none; /* Allow clicks to pass through to day cells */
}

/* Gantt mode: job bars (absolutely positioned) */
.pl-tl-job-gantt-bar {
  position: absolute;
  top: 4px;
  height: 22px;
  background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
  border: 1px solid #2566b2;
  border-radius: 3px;
  padding: 2px 4px;
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: auto;
  transition: box-shadow 0.1s, transform 0.1s;
  z-index: 5;
}

.pl-tl-job-gantt-bar:hover {
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

.pl-tl-gantt-day-cell {
  border-right: 1px solid rgba(0,0,0,0.05);
}

.pl-tl-job-selected {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #19a87a;
}

.pl-tl-job-ref {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.pl-tl-job-hours {
  font-size: 9px;
  opacity: 0.85;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Available capacity indicator */
.pl-tl-available {
  height: 3px;
  background: rgba(25,168,122,0.15);
  border-radius: 2px;
  margin-top: auto;
}

/* Responsive - keep constrained layout */
@media (max-width: 900px) {
  .pl-timeline-page {
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
  }

  .pl-timeline-container {
    flex-direction: column;
  }

  .pl-timeline-left {
    flex: 0 0 auto;
    max-height: 200px;
    min-height: 0;
  }

  .pl-timeline-right {
    flex: 1 1 0;
    min-height: 0;
  }
}

/* Very small screens */
@media (max-height: 600px) {
  .pl-timeline-page {
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px);
  }

  .pl-timeline-left {
    display: none;
  }
}

/* ========== ADD JOB BUTTON ========== */
.pl-btn-add-job {
  background: linear-gradient(135deg, #19a87a 0%, #148a62 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.pl-btn-add-job:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(25,168,122,0.3);
}

.pl-btn-add-job:active {
  transform: translateY(0);
}


.pl-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.pl-modal-overlay.pl-modal-open {
  display: flex;
}

/* ========== MODAL BOX ========== */
.pl-modal {
  background: var(--colorbackbody, #ffffff);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 450px;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--colortext, #333);
}

.pl-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

.pl-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.pl-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #888;
  padding: 0;
  line-height: 1;
}

.pl-modal-close:hover {
  color: #333;
}

.pl-modal-body {
  padding: 20px;
}

.pl-modal-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(0,0,0,0.1);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ========== FORM ELEMENTS ========== */
.pl-form-group {
  margin-bottom: 16px;
}

.pl-form-group:last-child {
  margin-bottom: 0;
}

.pl-form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.pl-form-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  background: var(--colorbackbody, #fff);
  color: var(--colortext, #333);
  box-sizing: border-box;
}

.pl-form-input:focus {
  outline: none;
  border-color: #19a87a;
  box-shadow: 0 0 0 3px rgba(25,168,122,0.15);
}

.pl-form-readonly {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(0,0,0,0.03);
  color: var(--colortext, #333);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 6px;
  box-sizing: border-box;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.pl-form-error {
  color: #bc0000;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* ========== MODAL BUTTONS ========== */
.pl-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.pl-btn-cancel {
  background: rgba(0,0,0,0.08);
  color: #666;
}

.pl-btn-cancel:hover {
  background: rgba(0,0,0,0.12);
}

.pl-btn-submit {
  background: linear-gradient(135deg, #19a87a 0%, #148a62 100%);
  color: #fff;
}

.pl-btn-submit:hover {
  box-shadow: 0 2px 8px rgba(25,168,122,0.3);
}

.pl-btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ========== CLICKABLE DAY CELLS ========== */
.pl-tl-machine-row .pl-tl-day-cell {
  cursor: pointer;
  transition: background 0.1s;
}

.pl-tl-machine-row .pl-tl-day-cell:hover {
  background: rgba(25,168,122,0.08);
}

/* ========== JOB CARD EDIT MODE ========== */

/* Header with actions */
.pl-job-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.pl-job-card-header-actions {
  flex-shrink: 0;
}

.pl-btn-edit-job {
  background: rgba(0,0,0,0.06);
  color: #666;
  border: none;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.pl-btn-edit-job:hover {
  background: rgba(25,168,122,0.15);
  color: #148a62;
}

.pl-btn-delete-job {
  background: rgba(220,53,69,0.08);
  color: #c33;
  border: none;
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-left: 4px;
}

.pl-btn-delete-job:hover {
  background: rgba(220,53,69,0.15);
  color: #d32f2f;
}

/* Edit mode header */
.pl-job-card-edit-header {
  background: rgba(25,168,122,0.08);
  border-bottom-color: rgba(25,168,122,0.2);
}

/* Edit form */
.pl-job-card-edit-form {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.pl-job-card-edit-form .pl-job-card-body {
  flex: 1;
  overflow-y: auto;
}

.pl-job-card-edit-form .pl-form-group {
  margin-bottom: 12px;
}

.pl-job-card-edit-form .pl-form-label {
  font-size: 11px;
  margin-bottom: 4px;
}

.pl-job-card-edit-form .pl-form-input {
  padding: 8px 10px;
  font-size: 13px;
}

.pl-job-card-edit-form textarea.pl-form-input {
  resize: vertical;
  min-height: 50px;
}

/* Edit form footer */
.pl-job-card-edit-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(0,0,0,0.08);
  margin-top: 12px;
}

.pl-job-card-edit-footer .pl-btn {
  padding: 8px 16px;
  font-size: 13px;
}

/* Scheduled time display in view mode */
.pl-job-card-dates {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pl-job-card-date {
  font-size: 12px;
  color: #555;
}

.pl-job-card-date span {
  color: #888;
}

/* Notes display in view mode */
.pl-job-card-notes {
  font-size: 12px;
  color: #555;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Product autocomplete */
.pl-autocomplete-container {
  position: relative;
  width: 100%;
}

.pl-autocomplete-results {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  list-style: none;
  margin: 0;
  padding: 0;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: none;
}

.pl-autocomplete-results:not(:empty) {
  display: block;
}

.pl-autocomplete-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.15s;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-autocomplete-item:hover {
  background-color: #f9f9f9;
}

.pl-autocomplete-item:last-child {
  border-bottom: none;
}

.pl-autocomplete-no-results {
  padding: 10px 12px;
  color: #999;
  font-size: 13px;
  text-align: center;
}
