/* =====================================================================
   貨櫃管理系統 — 視覺主軸:港口作業 / 提櫃單
   海事藍綠(teal)為識別色;代碼欄位用等寬字,凸顯「機讀單據」質感
   ===================================================================== */

:root {
  --ink:        #14202b;   /* 深海軍藍 — 結構 */
  --ink-2:      #35505f;
  --muted:      #6d818c;
  --paper:      #eef1f2;   /* 冷調底 */
  --surface:    #ffffff;
  --surface-2:  #f7f9f9;
  --line:       #dbe3e5;
  --line-2:     #c7d2d5;

  --teal:       #0e7c7b;   /* 主色 — 海事藍綠 */
  --teal-dark:  #0a5c5b;
  --teal-soft:  #e2f0ef;

  --amber:      #c07a1e;   /* 待回填 */
  --amber-soft: #fbf0dd;
  --green:      #2e7d54;   /* 已完成 */
  --green-soft: #e2f1e8;
  --danger:     #b23c36;
  --danger-soft:#f7e6e5;

  --radius:     8px;
  --radius-sm:  5px;
  --shadow:     0 1px 2px rgba(20,32,43,.06), 0 8px 24px rgba(20,32,43,.08);
  --shadow-sm:  0 1px 2px rgba(20,32,43,.08);

  --font: "Noto Sans TC","PingFang TC","Microsoft JhengHei",-apple-system,
          BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
  --mono: ui-monospace,"SF Mono","JetBrains Mono","Cascadia Code",Menlo,Consolas,monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

/* ----------------------------------------------------------- 版面骨架 */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--ink);
  color: #c8d6dd;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 7px;
  background:
    linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 8px 6px;
  border: 1.6px solid rgba(255,255,255,.85);
  background-image:
    linear-gradient(rgba(255,255,255,.85) 0 0),
    linear-gradient(rgba(255,255,255,.85) 0 0);
  background-size: 1.6px 100%; background-repeat: no-repeat;
  background-position: 33% 0, 66% 0;
}
.brand-text strong { display: block; color: #fff; font-size: 15px; letter-spacing: .5px; }
.brand-text small { color: #7f97a1; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; }

.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  padding: 10px 12px;
  border: 0; background: transparent;
  color: #b3c4cc; border-radius: var(--radius-sm);
  font-size: 14px; letter-spacing: .3px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #eaf2f4; }
.nav-item.is-active { background: var(--teal); color: #fff; }
.nav-ico { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }

.sidebar-foot { margin-top: auto; padding: 18px 20px 22px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot p { margin: 0 0 10px; font-size: 11px; letter-spacing: 2px; color: #6f8791; text-transform: uppercase; }
.flow { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.flow li { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: #a9bcc4; }
.flow em {
  width: 19px; height: 19px; flex-shrink: 0;
  display: grid; place-items: center;
  font-style: normal; font-size: 11px; font-weight: 600;
  border-radius: 50%; background: rgba(14,124,123,.28);
  color: #7fd6cf; font-family: var(--mono);
}

.main { flex: 1; min-width: 0; padding: 28px 34px 60px; }

/* ----------------------------------------------------------- 頁首 */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; margin-bottom: 22px;
}
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.head-actions { display: flex; gap: 10px; align-items: center; }

/* ----------------------------------------------------------- 按鈕 */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  transition: all .15s;
}
.btn:hover { border-color: var(--muted); background: var(--surface-2); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); padding: 7px 10px; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ----------------------------------------------------------- 篩選列 */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-chip {
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink-2); font-size: 13px; font-weight: 500;
  transition: all .15s;
}
.filter-chip:hover { border-color: var(--muted); background: var(--surface-2); }
.filter-chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ----------------------------------------------------------- 搜尋 */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 0 11px;
}
.search input { border: 0; outline: 0; padding: 8px 0; font-size: 13.5px; width: 210px; background: transparent; font-family: inherit; }
.search svg { color: var(--muted); }

/* ----------------------------------------------------------- 表格 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted);
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap;
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background .12s; }
tbody tr.clickable:hover { background: var(--teal-soft); }

.code { font-family: var(--mono); font-size: 13px; letter-spacing: .3px; color: var(--ink); }
.cell-strong { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ----------------------------------------------------------- 狀態徽章 */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-amber { color: var(--amber); background: var(--amber-soft); }
.badge-green { color: var(--green); background: var(--green-soft); }
.badge-idle  { color: var(--muted); background: var(--surface-2); }

/* 進度小條 */
.progress { display: flex; align-items: center; gap: 8px; }
.progress-bar { width: 74px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--teal); border-radius: 3px; }
.progress-txt { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ----------------------------------------------------------- 空狀態 */
.empty { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty svg { opacity: .35; margin-bottom: 12px; }
.empty p { margin: 0 0 4px; font-size: 15px; color: var(--ink-2); }
.empty small { font-size: 13px; }

/* ===================================================== 主單明細頁 */
.detail-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.back-link { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); background: none; border: 0; font-size: 13.5px; padding: 4px 0; }
.back-link:hover { color: var(--teal); }

/* 提櫃單樣式的主單抬頭 */
.manifest { border-top: 3px solid var(--teal); }
.manifest-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; padding: 20px 22px 16px; border-bottom: 1px dashed var(--line-2);
}
.manifest-no { font-family: var(--mono); font-size: 20px; font-weight: 600; letter-spacing: 1px; color: var(--ink); }
.manifest-head .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.manifest-actions { display: flex; gap: 8px; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 2px 0;
  padding: 8px 0;
}
.field-group-title {
  grid-column: 1 / -1;
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--teal-dark); font-weight: 700;
  padding: 14px 22px 6px;
  display: flex; align-items: center; gap: 9px;
}
.field-group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.field { padding: 8px 22px; }
.field dt { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; letter-spacing: .3px; }
.field dd { margin: 0; font-size: 14px; color: var(--ink); word-break: break-word; }
.field dd.mono { font-family: var(--mono); }
.field dd.blank { color: var(--line-2); }

/* ----------------------------------------------------------- 派工區塊 */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 30px 0 14px;
}
.section-head h2 { margin: 0; font-size: 16px; letter-spacing: .5px; display: flex; align-items: center; gap: 9px; }
.section-head h2 .count { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 400; }

.sub-list { display: flex; flex-direction: column; gap: 12px; }

.sub-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.sub-card-head {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.sub-seq {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 6px;
  background: var(--ink); color: #fff; font-family: var(--mono);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.sub-driver { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.sub-driver .name { font-weight: 600; font-size: 14.5px; }
.sub-driver .veh { font-family: var(--mono); font-size: 12.5px; color: var(--teal-dark); background: var(--teal-soft); padding: 1px 7px; border-radius: 4px; }

/* 派車類別標籤 */
.type-chip { display: inline-flex; align-items: center; flex-shrink: 0; font-size: 12.5px; font-weight: 700; padding: 3px 11px; border-radius: 6px; letter-spacing: 2px; }
.tp-pick    { color: var(--teal-dark); background: var(--teal-soft); }
.tp-send    { color: #2c6394; background: #e6eff8; }
.tp-collect { color: var(--amber); background: var(--amber-soft); }
.tp-return  { color: var(--green); background: var(--green-soft); }
.dash { color: var(--line-2); }
.stage-frac { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.stage-done { color: var(--green); font-size: 12.5px; font-weight: 600; }

/* 領送收交流程進度軸 */
.pipeline-card { margin-top: 14px; padding: 18px 22px 20px; }
.pipeline-title { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--teal-dark); font-weight: 700; margin-bottom: 16px; }
.pipeline { display: flex; align-items: flex-start; overflow-x: auto; padding-bottom: 2px; }
.pl-line { flex: 1 1 30px; min-width: 24px; height: 2px; background: var(--line-2); margin-top: 18px; border-radius: 2px; transition: background .2s; }
.pl-line.is-done { background: var(--green); }
.pl-node { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; width: 72px; text-align: center; }
.pl-dot {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  border: 2px solid var(--line-2); color: var(--muted); background: var(--surface);
  transition: all .2s;
}
.pl-name { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.pl-frac { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.pl-done .pl-dot   { background: var(--green); border-color: var(--green); color: #fff; }
.pl-done .pl-name  { color: var(--green); }
.pl-active .pl-dot { background: var(--teal); border-color: var(--teal); color: #fff; box-shadow: 0 0 0 4px var(--teal-soft); }
.pl-active .pl-name{ color: var(--teal-dark); }
.pl-active .pl-frac{ color: var(--teal-dark); }
.pl-pending .pl-dot{ border-style: dashed; }
.pl-none .pl-dot   { border-style: dashed; opacity: .5; }
.pl-none .pl-name, .pl-none .pl-frac { opacity: .5; }
.manifest-no .badge { vertical-align: middle; margin-left: 8px; font-size: 12.5px; }
.sub-driver .ph { color: var(--muted); font-size: 12.5px; }
.sub-card-head .spacer { flex: 1; }
.sub-card-actions { display: flex; gap: 4px; }

.sub-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
@media (max-width: 780px) { .sub-body { grid-template-columns: 1fr; } }
.sub-col { padding: 15px 18px; }
.sub-col + .sub-col { border-left: 1px solid var(--line); }
@media (max-width: 780px) { .sub-col + .sub-col { border-left: 0; border-top: 1px solid var(--line); } }
.sub-col h4 {
  margin: 0 0 11px; font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: 7px;
}
.sub-col h4 .dot { width: 7px; height: 7px; border-radius: 50%; }
.sub-col h4 .dot.teal { background: var(--teal); }
.sub-col h4 .dot.amber { background: var(--amber); }
.sub-col h4 .dot.green { background: var(--green); }

.mini-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.mini { min-width: 0; }
.mini dt { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.mini dd { margin: 0; font-size: 13.5px; word-break: break-word; }
.mini dd.mono { font-family: var(--mono); }
.mini dd.blank { color: var(--line-2); }
.mini.wide { grid-column: 1 / -1; }

.fillback-empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  color: var(--muted); font-size: 13px;
}

/* ===================================================== 彈窗 */
.modal-host { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto; }
.modal-host[hidden] { display: none; }   /* 讓 hidden 屬性確實隱藏,避免遮罩關不掉 */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,32,43,.42); backdrop-filter: blur(1.5px); animation: fade .18s ease; }
.modal {
  position: relative; width: 100%; max-width: 720px;
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  animation: pop .2s cubic-bezier(.2,.8,.3,1);
}
.modal.narrow { max-width: 460px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.99); } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; letter-spacing: .4px; }
.modal-head h3 small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; letter-spacing: 0; }
.modal-close { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { padding: 20px 22px; max-height: 64vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 15px 22px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 12px 12px; }

/* 表單 */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-section-title {
  grid-column: 1 / -1; font-size: 11px; letter-spacing: 1.3px; text-transform: uppercase;
  color: var(--teal-dark); font-weight: 700; margin-top: 6px;
  display: flex; align-items: center; gap: 9px;
}
.form-section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.form-section-title:first-child { margin-top: 0; }

.field-ctl label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
.field-ctl label .req { color: var(--danger); margin-left: 3px; }
.field-ctl input, .field-ctl select, .field-ctl textarea {
  width: 100%; padding: 9px 11px; font-size: 13.5px; font-family: inherit;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); outline: 0; transition: border .15s, box-shadow .15s;
}
.field-ctl input.mono, .field-ctl textarea.mono { font-family: var(--mono); }
.field-ctl input:focus, .field-ctl select:focus, .field-ctl textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,124,123,.14);
}
.field-ctl textarea { resize: vertical; min-height: 62px; }
.field-ctl input::placeholder { color: #aab8bd; }

@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ===================================================== Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 8px;
  font-size: 13.5px; box-shadow: var(--shadow); z-index: 80;
  animation: toastIn .25s cubic-bezier(.2,.8,.3,1);
}
.toast.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ===================================================== RWD */
@media (max-width: 720px) {
  .sidebar { width: 66px; }
  .brand-text, .nav-item span:not(.nav-ico):last-child, .sidebar-foot { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .main { padding: 20px 16px 50px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .search input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
