/* ==================== CSS 變數 ==================== */
:root {
  --primary-color: #4a90d9;
  --primary-dark: #357abd;
  --success-color: #28a745;
  --warning-color: #ffc107;
  --danger-color: #dc3545;
  --info-color: #17a2b8;
  --light-color: #f8f9fa;
  --dark-color: #343a40;
  --gray-color: #6c757d;
  --border-color: #dee2e6;
  --shadow: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.15);
  --border-radius: 8px;
}

/* ==================== 重置與基礎 ==================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--dark-color);
  background-color: #f5f7fa;
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ==================== 導航列 ==================== */
.navbar {
  background-color: var(--primary-color);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.navbar-brand {
  color: white;
  font-size: 1.25rem;
  font-weight: bold;
  padding: 15px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-nav {
  display: flex;
  list-style: none;
  gap: 5px;
}

.navbar-nav a {
  color: rgba(255,255,255,0.85);
  padding: 15px 15px;
  display: block;
  transition: background-color 0.2s;
}

.navbar-nav a:hover,
.navbar-nav a.active {
  color: white;
  background-color: rgba(255,255,255,0.1);
  text-decoration: none;
}

.navbar-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 10px;
}

.navbar.hide {
  display: none;
}

/* 僅在管理員模式下顯示的選單項目 */
body:not(.admin-mode) .nav-admin-only {
  display: none;
}

@media (max-width: 768px) {
  .navbar {
    flex-wrap: wrap;
  }
  
  .navbar-toggle {
    display: block;
  }
  
  .navbar-nav {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 0;
  }
  
  .navbar-nav.show {
    display: flex;
  }
  
  .navbar-nav a {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
}

/* ==================== 主要容器 ==================== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 100px; /* 確保手機上能滑到最底部 */
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 100px; /* 確保手機上能滑到最底部 */
}

.container-fluid {
  padding: 20px;
  padding-bottom: 100px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

/* iOS 安全區域支援 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .container,
  .page-container,
  .container-fluid {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
}

/* ==================== 卡片 ==================== */
.card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.card-header {
  background-color: var(--light-color);
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.card-body {
  padding: 20px;
}

.card-footer {
  background-color: var(--light-color);
  padding: 15px 20px;
  border-top: 1px solid var(--border-color);
}

/* ==================== 按鈕 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover {
  background-color: #218838;
}

.btn-danger {
  background-color: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background-color: #c82333;
}

.btn-secondary {
  background-color: var(--gray-color);
  color: white;
}

.btn-secondary:hover {
  background-color: #5a6268;
}

.btn-outline {
  background-color: transparent;
  border: 2px solid var(--primary-color);
  color: var(--primary-color);
}

.btn-outline:hover {
  background-color: var(--primary-color);
  color: white;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 15px 30px;
  font-size: 1.25rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ==================== 表單 ==================== */
.form-group {
  margin-bottom: 15px;
}

.form-label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--dark-color);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.2);
}

.form-control:disabled {
  background-color: var(--light-color);
  cursor: not-allowed;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px 12px;
  padding-right: 35px;
}

.form-row {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 200px;
}

/* ==================== 表格 ==================== */
.table-container {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.table th {
  background-color: var(--light-color);
  font-weight: 600;
  white-space: nowrap;
}

.table tbody tr:hover {
  background-color: #f8f9fa;
}

.table-actions {
  display: flex;
  gap: 8px;
}

/* ==================== 頁籤 ==================== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  font-size: 1rem;
  font-weight: 500;
  color: var(--gray-color);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--primary-color);
}

.tab-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ==================== 狀態標籤 ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 20px;
}

.badge-pending {
  background-color: #ffeeba;
  color: #856404;
}

.badge-in-progress {
  background-color: #b8daff;
  color: #004085;
}

.badge-completed {
  background-color: #c3e6cb;
  color: #155724;
}

/* ==================== 時間差異顯示 ==================== */
.time-diff {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

.time-diff.late {
  color: var(--danger-color);
}

.time-diff.early {
  color: var(--success-color);
}

.time-diff.on-time {
  color: var(--gray-color);
}

/* ==================== 彈窗 ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: white;
  border-radius: var(--border-radius);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-color);
  line-height: 1;
}

.modal-close:hover {
  color: var(--dark-color);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ==================== 拖曳排序 ==================== */
.sortable-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sortable-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  margin-bottom: 8px;
  cursor: grab;
  transition: box-shadow 0.2s;
}

.sortable-item:hover {
  box-shadow: var(--shadow);
}

.sortable-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.sortable-item .drag-handle {
  color: var(--gray-color);
  cursor: grab;
}

.sortable-item .item-content {
  flex: 1;
}

.sortable-item .item-actions {
  display: flex;
  gap: 5px;
}

/* ==================== 載入中 ==================== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--gray-color);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== 空狀態 ==================== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-color);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 15px;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--dark-color);
}

/* ==================== Toast 通知 ==================== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 15px 20px;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast-success {
  border-left: 4px solid var(--success-color);
}

.toast-error {
  border-left: 4px solid var(--danger-color);
}

.toast-warning {
  border-left: 4px solid var(--warning-color);
}

/* ==================== 路線視覺化 ==================== */
.route-node {
  display: flex;
  align-items: flex-start;
  position: relative;
}

.route-node:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 15px;
  top: 35px;
  bottom: -15px;
  width: 3px;
  background: var(--border-color);
}

.route-node.completed:not(:last-child)::after {
  background: var(--success-color);
}

.route-node.current:not(:last-child)::after {
  background: linear-gradient(to bottom, var(--primary-color) 0%, var(--border-color) 100%);
}

.route-node-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
  flex-shrink: 0;
  z-index: 1;
  border: 3px solid;
}

.route-node.completed .route-node-dot {
  background: var(--success-color);
  border-color: var(--success-color);
  color: white;
}

.route-node.current .route-node-dot {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
  animation: pulse 1.5s infinite;
}

.route-node.pending .route-node-dot {
  background: white;
  border-color: var(--border-color);
  color: var(--gray-color);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.route-node-content {
  flex: 1;
  margin-left: 15px;
  padding-bottom: 25px;
}

.route-node:last-child .route-node-content {
  padding-bottom: 0;
}

.route-node-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.route-node-name {
  font-weight: 600;
  font-size: 1rem;
}

.route-node-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e3f2fd;
  color: #1976d2;
}

.route-node-tag.end {
  background: #e8f5e9;
  color: #388e3c;
}

.route-node-times {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
  font-size: 0.85rem;
}

.time-item {
  display: flex;
  flex-direction: column;
}

.time-item .label {
  color: var(--gray-color);
  font-size: 0.75rem;
}

.time-item .value {
  font-weight: 500;
}

.time-item .value.actual {
  color: var(--dark-color);
}

.time-item .value.planned {
  color: var(--gray-color);
}

.route-segment-info {
  margin: -10px 0 15px 47px;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 6px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.route-segment-info .segment-label {
  color: var(--gray-color);
}

/* ==================== 司機端樣式 ==================== */
.driver-page {
  min-height: 100vh;
  background-color: #f0f2f5;
}

.driver-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 20px;
  text-align: center;
}

.driver-header-top {
  text-align: left;
  margin-bottom: 10px;
}

.back-to-system {
  color: rgba(255,255,255,0.9);
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.back-to-system:hover {
  color: white;
  text-decoration: none;
}

.driver-header h1 {
  font-size: 1.5rem;
  margin-bottom: 5px;
}

.driver-header .subtitle {
  opacity: 0.9;
  font-size: 0.9rem;
}

/* 人員資訊換行 */
.trip-card-meta .crew-info {
  flex-basis: 100%;
  margin-top: 5px;
}

@media (min-width: 768px) {
  .trip-card-meta .crew-info {
    flex-basis: auto;
    margin-top: 0;
  }
}

.driver-container {
  padding: 15px;
  max-width: 500px;
  margin: 0 auto;
}

.trip-select-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 15px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 2px solid transparent;
}

.trip-select-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.trip-select-card .trip-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.trip-select-card .trip-info {
  font-size: 0.9rem;
  color: var(--gray-color);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.driver-action-area {
  background: white;
  border-radius: 12px;
  padding: 25px 20px;
  margin-bottom: 15px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  text-align: center;
}

.current-status {
  margin-bottom: 20px;
}

.current-status .label {
  font-size: 0.9rem;
  color: var(--gray-color);
  margin-bottom: 5px;
}

.current-status .value {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--dark-color);
}

.current-status .location {
  font-size: 1.2rem;
  color: var(--primary-color);
  margin-top: 5px;
}

.action-btn {
  width: 100%;
  padding: 25px;
  font-size: 1.5rem;
  font-weight: bold;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: white;
}

.action-btn:active {
  transform: scale(0.98);
}

.action-btn.depart {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.action-btn.arrive {
  background: linear-gradient(135deg, #007bff 0%, #17a2b8 100%);
}

.action-btn.leave {
  background: linear-gradient(135deg, #fd7e14 0%, #ffc107 100%);
}

.action-btn:disabled {
  background: #e9ecef;
  color: #adb5bd;
  cursor: not-allowed;
  transform: none;
}

/* 按鈕下方電話區塊 */
.next-stop-phone {
  margin-top: 15px;
  text-align: center;
  padding: 12px;
  background: rgba(255,255,255,0.9);
  border-radius: 10px;
}

.next-stop-label {
  font-size: 0.9rem;
  color: var(--gray-color);
  margin-bottom: 8px;
}

.phone-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.phone-link {
  display: inline-block;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
  text-decoration: none;
  padding: 10px 16px;
  background: #e3f2fd;
  border-radius: 8px;
  transition: background-color 0.2s;
}

.phone-link:hover {
  background: #bbdefb;
  text-decoration: none;
}

.phone-link:active {
  background: #90caf9;
}

.phone-link.extension-link {
  color: #388e3c;
  background: #e8f5e9;
}

.phone-link.extension-link:hover {
  background: #c8e6c9;
}

.phone-link.extension-link:active {
  background: #a5d6a7;
}

.phone-not-set {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--gray-color);
  padding: 10px 16px;
}

/* 路線進度中的電話 */
.progress-phone-link {
  font-size: 0.8rem;
  color: var(--primary-color);
  text-decoration: none;
  padding: 2px 8px;
  background: #e3f2fd;
  border-radius: 4px;
  margin-right: 6px;
}

.progress-phone-link:hover {
  background: #bbdefb;
  text-decoration: none;
}

.progress-phone-link.extension {
  color: #388e3c;
  background: #e8f5e9;
}

.progress-phone-link.extension:hover {
  background: #c8e6c9;
}

.progress-phone-not-set {
  font-size: 0.8rem;
  color: #adb5bd;
  margin-right: 6px;
}

.progress-item .phone {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.route-progress {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.route-progress-title {
  font-weight: 600;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.progress-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #f0f2f5;
}

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

.progress-item .icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.progress-item.completed .icon {
  background: var(--success-color);
  color: white;
}

.progress-item.current .icon {
  background: var(--primary-color);
  color: white;
  animation: pulse 1.5s infinite;
}

.progress-item.pending .icon {
  background: #e9ecef;
  color: #adb5bd;
}

.progress-item .content {
  flex: 1;
}

.progress-item .name {
  font-weight: 500;
}

.progress-item .time {
  font-size: 0.85rem;
  color: var(--gray-color);
  margin-top: 2px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: white;
  opacity: 0.9;
  font-size: 0.9rem;
  margin-bottom: 10px;
  cursor: pointer;
}

.back-btn:hover {
  opacity: 1;
}

/* ==================== 儀表板樣式 ==================== */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.dashboard-date {
  font-size: 1.1rem;
  color: var(--gray-color);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
  margin-bottom: 20px;
}

.summary-card {
  background: white;
  border-radius: var(--border-radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.summary-card .number {
  font-size: 2rem;
  font-weight: bold;
  color: var(--primary-color);
}

.summary-card .label {
  font-size: 0.9rem;
  color: var(--gray-color);
  margin-top: 5px;
}

.summary-card.pending .number { color: #856404; }
.summary-card.in-progress .number { color: #004085; }
.summary-card.completed .number { color: #155724; }

.trip-card {
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 15px;
  overflow: hidden;
}

.trip-card-header {
  padding: 15px 20px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.trip-card-header.in-progress {
  background: linear-gradient(135deg, #007bff 0%, #17a2b8 100%);
}

.trip-card-header.completed {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.trip-card-header.pending {
  background: linear-gradient(135deg, #6c757d 0%, #868e96 100%);
}

.trip-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-icon {
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.trip-card-header.clickable {
  cursor: pointer;
  transition: filter 0.2s;
}

.trip-card-header.clickable:hover {
  filter: brightness(1.1);
}

.route-preview-collapsed {
  flex: 1;
  font-size: 0.85rem;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip-card-actions-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.trip-card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.trip-card-actions .btn {
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
}

.btn-danger-outline:hover {
  background: rgba(220, 53, 69, 0.8);
  border-color: transparent;
}

.trip-card-meta {
  display: flex;
  gap: 15px;
  font-size: 0.9rem;
  opacity: 0.9;
  flex-wrap: wrap;
}

.trip-card-body {
  padding: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.trip-card-body.collapsed {
  max-height: 0;
}

.trip-card-body:not(.collapsed) {
  max-height: 2000px;
}

.route-visual {
  padding: 20px;
}

/* 行程摘要區塊 */
.trip-card-summary {
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid var(--border-color);
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.summary-row:last-child {
  margin-bottom: 0;
}

.summary-item {
  font-size: 0.9rem;
  color: var(--dark-color);
}

.progress-bar-mini {
  flex: 1;
  max-width: 150px;
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-mini .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #28a745, #20c997);
  border-radius: 4px;
  transition: width 0.3s;
}

/* 路線預覽區塊 */
.trip-card-preview {
  padding: 15px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border-color);
}

.route-preview-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 5px;
  line-height: 1.8;
}

.route-stop {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 8px;
  background: white;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  min-width: 70px;
}

.route-stop.completed {
  background: #d4edda;
  border-color: #28a745;
}

.route-stop.current {
  background: #cce5ff;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.3);
}

.route-stop.pending {
  background: #f8f9fa;
  border-color: #dee2e6;
}

.route-stop-icon {
  font-size: 1rem;
  margin-bottom: 2px;
}

.route-stop.completed .route-stop-icon {
  color: #28a745;
}

.route-stop.current .route-stop-icon {
  font-size: 1.2rem;
}

.route-stop-name {
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
}

.route-stop-time {
  font-size: 0.8rem;
  color: var(--gray-color);
}

.route-stop.completed .route-stop-time {
  color: #155724;
}

.route-arrow {
  display: inline-flex;
  align-items: center;
  padding: 0 5px;
  color: var(--gray-color);
  font-size: 0.9rem;
  align-self: center;
  height: 50px;
}

.route-arrow.with-truck {
  color: #007bff;
  font-weight: bold;
}

.completed-trip-summary {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px 20px;
  background: #f8f9fa;
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  font-size: 0.9rem;
  flex-wrap: wrap;
  cursor: pointer;
}

.completed-trip-summary .icon {
  font-size: 1.2rem;
}

.completed-trip-summary .info {
  flex: 1;
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.completed-trip-summary .trip-name {
  font-weight: 600;
}

.completed-trip-summary .expand-btn {
  color: var(--primary-color);
}

.completed-trip-detail {
  display: none;
  margin-top: 10px;
}

.completed-trip-detail.show {
  display: block;
}

/* ==================== 響應式 ==================== */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .form-row {
    flex-direction: column;
  }
  
  .form-row .form-group {
    min-width: 100%;
  }
  
  .table th,
  .table td {
    padding: 10px;
    font-size: 0.875rem;
  }
  
  .btn {
    padding: 8px 16px;
  }
  
  .route-node-times {
    grid-template-columns: 1fr;
  }
  
  .trip-card-actions-row {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .trip-card-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
  }
  
  .route-preview-collapsed {
    width: 100%;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .page-header .btn {
    width: 100%;
  }
}

/* ==================== 已完成卡片收折 ==================== */
.trip-card-header.clickable {
  cursor: pointer;
  transition: background-color 0.2s;
}

.trip-card-header.clickable:hover {
  filter: brightness(0.95);
}

.trip-card-header .expand-icon {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.8);
  transition: transform 0.2s;
}

.completed-card {
  margin-bottom: 15px;
}

/* ==================== 編輯和補打卡按鈕 ==================== */
.edit-btn {
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.edit-btn:hover {
  opacity: 1;
}

.add-log-btn {
  color: var(--primary-color);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
  border: 1px dashed var(--primary-color);
  border-radius: 4px;
  transition: all 0.2s;
}

.add-log-btn:hover {
  background-color: var(--primary-color);
  color: white;
}

/* ==================== 出車計畫頁面 ==================== */

/* 出車計畫卡片列表 */
.trip-plan-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 15px;
  overflow: hidden;
}

.trip-plan-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: linear-gradient(135deg, #6c757d 0%, #868e96 100%);
  color: white;
  flex-wrap: wrap;
  gap: 10px;
}

.trip-plan-card-header.in-progress {
  background: linear-gradient(135deg, #007bff 0%, #17a2b8 100%);
}

.trip-plan-card-header.completed {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.trip-plan-card-header.pending {
  background: linear-gradient(135deg, #6c757d 0%, #868e96 100%);
}

.trip-plan-card-left {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.trip-plan-time {
  font-size: 1.3rem;
  font-weight: 700;
}

.trip-plan-vehicle {
  font-size: 1rem;
  opacity: 0.95;
}

.trip-plan-card-actions {
  display: flex;
  gap: 8px;
}

.trip-plan-card-body {
  padding: 15px 20px;
}

.trip-plan-info-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.trip-plan-info-row:last-child {
  margin-bottom: 0;
}

.trip-plan-info-row .info-icon {
  margin-right: 8px;
}

.trip-plan-info-row .info-label {
  color: var(--gray-color);
  margin-right: 5px;
  white-space: nowrap;
}

.trip-plan-info-row .info-value {
  color: var(--dark-color);
}

.trip-plan-info-row .route-text {
  line-height: 1.5;
  word-break: break-all;
}

.btn-light {
  background: rgba(255,255,255,0.9);
  color: var(--dark-color);
  border: none;
}

.btn-light:hover {
  background: white;
}

/* 彈窗分區塊設計 */
.form-section {
  background: #f8f9fa;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
}

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

.form-section-title {
  background: #e9ecef;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--dark-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-section-content {
  padding: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.template-select {
  font-size: 0.85rem;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: white;
}

/* 隨車人員選擇 */
.crew-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.crew-checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.crew-checkbox-item:hover {
  border-color: var(--primary-color);
}

.crew-checkbox-item:has(input:checked) {
  background: #e3f2fd;
  border-color: var(--primary-color);
}

.crew-checkbox-item input {
  margin: 0;
}

/* 站點列表 - 拖曳排序 */
.stops-sortable-list {
  min-height: 60px;
}

.empty-stops-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--gray-color);
  gap: 10px;
}

.empty-stops-hint span:first-child {
  font-size: 2rem;
}

.stop-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.stop-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.stop-card-main {
  display: flex;
  align-items: center;
  padding: 12px 15px;
  gap: 12px;
}

.drag-handle {
  cursor: grab;
  font-size: 1.2rem;
  color: var(--gray-color);
  padding: 5px;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.stop-card-order {
  width: 28px;
  height: 28px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.stop-card-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stop-card-name {
  font-weight: 500;
  font-size: 1rem;
}

.stop-role-tag {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.stop-role-tag.start {
  background: #e3f2fd;
  color: #1976d2;
}

.stop-role-tag.end {
  background: #fff3e0;
  color: #f57c00;
}

.stop-card-remove {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--gray-color);
  cursor: pointer;
  border-radius: 4px;
  font-size: 1rem;
  transition: all 0.2s;
}

.stop-card-remove:hover {
  background: #fee;
  color: var(--danger-color);
}

.stop-card-operation {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  padding-left: 70px;
  background: #f8f9fa;
  border-top: 1px solid var(--border-color);
  gap: 10px;
  flex-wrap: wrap;
}

.operation-label {
  color: var(--gray-color);
  font-size: 0.9rem;
  white-space: nowrap;
}

.operation-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-op {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  padding: 4px 8px;
}

.btn-op-decrease {
  background: linear-gradient(135deg, #5a9fd4 0%, #4a8bc2 100%);
  color: white;
}

.btn-op-decrease:hover {
  background: linear-gradient(135deg, #4a8bc2 0%, #3a7bb2 100%);
  transform: scale(1.05);
}

.btn-op-increase {
  background: linear-gradient(135deg, #5a9fd4 0%, #4a8bc2 100%);
  color: white;
}

.btn-op-increase:hover {
  background: linear-gradient(135deg, #4a8bc2 0%, #3a7bb2 100%);
  transform: scale(1.05);
}

.btn-op:active {
  transform: scale(0.95);
}

.btn-op-icon {
  font-size: 0.75rem;
  line-height: 1;
  letter-spacing: -2px;
}

.btn-op-text {
  font-size: 0.7rem;
  font-weight: 600;
  margin-top: 2px;
}

.operation-value-box {
  display: flex;
  align-items: center;
  background: white;
  border: 2px solid var(--primary-color);
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(74, 139, 194, 0.15);
}

.operation-input {
  width: 50px;
  height: 32px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--dark-color);
}

.operation-input:focus {
  outline: none;
}

.operation-unit {
  color: var(--gray-color);
  font-size: 0.85rem;
  margin-left: 2px;
}

/* SortableJS 拖曳樣式 */
.stop-card-ghost {
  opacity: 0.4;
  background: #f0f2f5;
}

.stop-card-chosen {
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.stop-card-drag {
  opacity: 1;
}

/* 新增站點區域 */
.add-stop-section {
  display: flex;
  gap: 10px;
  padding: 15px;
  background: #e9ecef;
  border-radius: 8px;
  margin-top: 10px;
}

.add-stop-section select {
  flex: 1;
}

.stops-actions {
  margin-top: 15px;
  display: flex;
  justify-content: flex-end;
}

/* 其他共用樣式 */
.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.modal-lg {
  max-width: 700px;
  width: 95%;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--dark-color);
}

.btn-outline:hover {
  background: var(--light-gray);
}

@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .trip-plan-card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .trip-plan-card-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .stop-card-operation {
    padding-left: 15px;
    justify-content: center;
  }
  
  .operation-controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  
  .btn-op {
    min-width: 40px;
    height: 40px;
  }
  
  .operation-value-box {
    order: -1;
    width: 100%;
    justify-content: center;
    margin-bottom: 8px;
  }
  
  .add-stop-section {
    flex-direction: column;
  }
}

/* ==================== 歷史查詢篩選樣式 ==================== */
.filter-section {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

.filter-group {
  min-width: 150px;
}

.filter-group-wide {
  flex: 1;
  min-width: 300px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.checkbox-item:hover {
  border-color: var(--primary-color);
}

.checkbox-item.select-all {
  background: var(--primary-color);
  color: white;
  font-weight: 500;
}

.checkbox-item.select-all:hover {
  background: var(--primary-dark);
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.filter-actions {
  display: flex;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

/* ==================== 統計分析樣式 ==================== */
.analysis-filter-section {
  background: #f8f9fa;
  padding: 15px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
}

.analysis-filter-section h4 {
  margin: 0 0 10px 0;
  font-size: 0.95rem;
  color: var(--gray-color);
}

.filter-method-options {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 10px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.radio-item input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.filter-params {
  padding: 10px;
  background: white;
  border-radius: 4px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.small-input {
  width: 60px;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  text-align: center;
}

.analysis-section {
  margin-bottom: 25px;
}

.analysis-section h4 {
  margin: 0 0 15px 0;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-color);
  color: var(--dark-color);
}

.analysis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.analysis-table th,
.analysis-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.analysis-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: var(--gray-color);
}

.analysis-table tbody tr:hover {
  background: #f8f9fa;
}

.no-data {
  color: var(--gray-color);
  font-style: italic;
  padding: 20px;
  text-align: center;
}

.no-standard {
  color: var(--gray-color);
  font-style: italic;
}

.diff-zero {
  color: var(--gray-color);
}

.diff-slow {
  color: var(--danger-color);
}

.diff-fast {
  color: var(--success-color);
}

.btn-update-all {
  margin-top: 15px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* 確認更新表格 */
.confirm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.confirm-table th,
.confirm-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.confirm-table th {
  background: #f8f9fa;
  font-weight: 600;
}

.table-responsive {
  overflow-x: auto;
}

/* 響應式調整 */
@media (max-width: 768px) {
  .filter-group-wide {
    min-width: 100%;
  }
  
  .checkbox-group {
    max-height: 150px;
    overflow-y: auto;
  }
  
  .filter-method-options {
    flex-direction: column;
    gap: 8px;
  }
  
  .analysis-table {
    font-size: 0.8rem;
  }
  
  .analysis-table th,
  .analysis-table td {
    padding: 8px;
  }
}
