:root {
  --primary: #1f6feb;
  --primary-weak: #eff4ff;
  --primary-grad: linear-gradient(135deg, #2563eb, #4f46e5);
  --accent-grad: linear-gradient(135deg, #7c3aed, #6d28d9);
  --topbar-grad: linear-gradient(115deg, #0b1220 0%, #16294d 100%);
  --bg: #f4f6fb;
  --surface: #ffffff;
  --white: #fff;
  --border: #e6e8ee;
  --danger: #d92d20;
  --text: #1a1f36;
  --text-2: #667085;
  --text-3: #98a2b3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-hover: 0 8px 24px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.view-section { display: none; gap: 20px; align-items: flex-start; }
.view-section.active { display: flex; }

.list-panel {
  flex: 1; background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; min-width: 0;
}

.form-panel {
  width: var(--panel-w); background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px; box-shadow: var(--shadow);
  position: sticky; top: 20px; max-height: 90vh; overflow-y: auto;
}

.table-responsive { overflow-x: auto; width: 100%; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { background: #f8fafc; text-align: left; padding: 11px 16px; font-size: 12.5px; color: var(--text-2); font-weight: 600; border-bottom: 1px solid var(--border); }
td { padding: 11px 16px; border-bottom: 1px solid #f2f4f7; font-size: 14px; vertical-align: middle; }

h2, h3 { margin: 0 0 16px 0; font-size: 17px; color: var(--text); font-weight: 700; }
h4 { margin: 16px 0 8px 0; font-size: 13.5px; color: var(--text-2); border-bottom: 1px solid var(--border); padding-bottom: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-full { grid-column: span 2; }
.form-group { margin-bottom: 0; }
label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
input, select, textarea { width: 100%; padding: 8px 12px; border: 1px solid #d5dae1; border-radius: 10px; font-size: 14px; background: var(--surface); color: var(--text); font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12); }

.btn { padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); font-weight: 600; cursor: pointer; font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: all 0.15s; font-family: inherit; }
.btn-primary { background: var(--primary-grad); color: var(--white); border: none; box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45); }
.btn-danger { background: #fef3f2; color: var(--danger); border-color: rgba(217, 45, 32, 0.2); }
.btn-danger:hover { background: #fee4e2; }
.btn-outline { background: var(--surface); color: var(--text); }
.btn-outline:hover { border-color: #cbd2dc; background: #f9fafb; }
.btn-block { width: 100%; margin-top: 16px; }

.btn-icon { padding: 4px 8px; font-size: 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.btn-icon:hover { background: #f9fafb; border-color: #cbd2dc; }

.tag { padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; }
.tag-blue { background: #ddf4ff; color: #0969da; }
.tag-gray { background: #f2f4f7; color: var(--text-2); }

/* 彈窗樣式 */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 9999; justify-content: center; align-items: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal-content { position: relative; max-width: 900px; width: 100%; height: 85vh; background: #fff; padding: 20px; border-radius: 16px; display: flex; justify-content: center; align-items: center; flex-direction: column; }
.modal-content img { max-width: 100%; max-height: 100%; display: none; object-fit: contain; border: 1px solid #ddd; }
.modal-content iframe { width: 100%; height: 100%; display: none; border: 1px solid #ddd; }
.modal-close { position: absolute; top: -15px; right: -15px; background: var(--danger); color: #fff; width: 30px; height: 30px; border-radius: 50%; text-align: center; line-height: 30px; cursor: pointer; font-weight: bold; border: 2px solid #fff; z-index: 10; }

@media (max-width: 1000px) {
  .app-container { padding: 10px; }
  .view-section { flex-direction: column; }
  .list-panel, .form-panel { width: 100%; }
  .form-panel { position: static; max-height: none; overflow-y: visible; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-full { grid-column: span 1; }
  .header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header>div { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
  .btn { padding: 10px 14px; font-size: 14px; }
  th:nth-child(1), td:nth-child(1) { position: sticky; left: 0; z-index: 1; background: var(--white); border-right: 1px solid #eee; }
  th:nth-child(2), td:nth-child(2) { position: sticky; left: 60px; z-index: 1; background: var(--white); border-right: 2px solid var(--primary); }
  th:nth-child(1), th:nth-child(2) { background: #f6f8fa; z-index: 2; }
}
/* 訂單列表雙層排版專用 */
.cell-main { 
    font-weight: 600; 
    font-size: 14px; 
    color: #1f2328; 
    margin-bottom: 4px; 
    display: flex; 
    align-items: center; 
    gap: 6px; 
}
.cell-sub { 
    font-size: 12px; 
    color: #656d76; 
}

/* === 全站頂部工具列（深色漸層，各頁共用）=== */
.topbar {
  background: var(--topbar-grad);
  border-bottom: none;
  padding: 10px 24px;
  min-height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 500;
  box-shadow: 0 2px 12px rgba(11, 18, 32, 0.25);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; color: #fff; }
.topbar-logo {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12);
  font-size: 17px;
  display: flex; align-items: center; justify-content: center;
}
.topbar-back {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.85); font-size: 16px; text-decoration: none;
  transition: all .15s;
}
.topbar-back:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-link {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 12px; border-radius: 9px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.85); font-size: 13px; font-weight: 600;
  text-decoration: none; cursor: pointer; transition: all .15s;
}
.topbar-link:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.topbar-date { color: rgba(255, 255, 255, 0.65); font-size: 13.5px; }
.btn-logout {
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 9px;
  color: rgba(255, 255, 255, 0.85); font-size: 13.5px; padding: 7px 16px; cursor: pointer;
  transition: all .15s;
}
.btn-logout:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
@media (max-width: 560px) {
  .topbar { padding: 8px 12px; }
  .topbar-brand { font-size: 15.5px; }
}

/* === 📆 老闆本週行程（大廳行程卡與各頁 topbar 小視窗共用）=== */
.dash-empty { color: var(--text-3); font-size: 13.5px; padding: 8px 0; }
.sched-day { padding: 6px 0; border-bottom: 1px solid #f2f4f7; }
.sched-day:last-child { border-bottom: none; }
.sched-day-hd { font-size: 12.5px; color: var(--text-3); font-weight: 600; margin-bottom: 2px; }
.sched-day.sched-today .sched-day-hd { color: #1f6feb; }
.sched-evt { font-size: 13px; padding: 2px 4px; margin: 0 -4px; border-radius: 6px; cursor: pointer; }
.sched-evt:hover { background: #f6f8fc; }
.sched-evt-row { display: flex; gap: 10px; }
.sched-time { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* 點行程展開的詳細區（時間／來源／地點／說明） */
.sched-arrow { margin-left: auto; color: var(--text-3); font-size: 11px; align-self: center; transition: transform 0.15s; }
.sched-evt.open .sched-arrow { transform: rotate(90deg); }
.sched-evt-detail { display: none; margin: 4px 0 4px 2px; padding: 2px 0 2px 10px; border-left: 2px solid #e3e8f0; color: var(--text-2); font-size: 12.5px; line-height: 1.55; }
.sched-evt.open .sched-evt-detail { display: block; }
.sched-desc { margin-top: 2px; word-break: break-word; }
/* 行程來源標籤（老闆／工廠／老闆娘／辦公室） */
.sched-cal {
  font-size: 11px; font-weight: 600; line-height: 18px; padding: 0 7px;
  border-radius: 999px; white-space: nowrap; align-self: flex-start; margin-top: 1px;
}
.sched-cal-boss    { background: #e8f0fe; color: #1a56c5; }
.sched-cal-factory { background: #fff1e0; color: #b45309; }
.sched-cal-wife    { background: #fde8ef; color: #be2f63; }
.sched-cal-office  { background: #e6f6ec; color: #1a7f4b; }
.sched-cal-other   { background: #eef1f5; color: #5b6472; }

/* 行程小視窗 */
.sched-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(11, 18, 32, 0.5);
  z-index: 2000;
  align-items: flex-start; justify-content: center;
  padding: 80px 16px 16px;
}
.sched-modal-overlay.active { display: flex; }
.sched-modal {
  background: var(--surface); border-radius: 16px;
  width: 420px; max-width: 94vw; max-height: 70vh;
  display: flex; flex-direction: column;
  box-shadow: 0 16px 48px rgba(16, 24, 40, 0.25);
}
.sched-modal-hd {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px 10px;
  font-size: 15.5px; font-weight: 700;
}
.sched-modal-close {
  background: none; border: none; font-size: 16px;
  color: var(--text-3); cursor: pointer;
  padding: 4px 8px; border-radius: 6px;
}
.sched-modal-close:hover { background: #f2f4f7; color: var(--text); }
.sched-modal-body { padding: 0 18px 16px; overflow-y: auto; }
/* 小視窗週切換（‹ 本週 ›）與週期間標示 */
.sched-nav { display: flex; gap: 4px; margin-left: auto; margin-right: 6px; }
.sched-nav-btn {
  background: #fff; border: 1px solid #d8dee9; border-radius: 8px;
  padding: 2px 10px; font-size: 13px; color: var(--text-2); cursor: pointer;
}
.sched-nav-btn:hover { background: #f2f4f7; color: var(--text); }
.sched-week-label { padding: 0 18px 6px; font-size: 12.5px; color: var(--text-3); }
.sched-note {
  margin-top: 10px; padding: 8px 10px; border-radius: 8px;
  font-size: 12px; background: #fff7ed; color: #b45309;
}