/* ============================================================
   Sanimax Schedule Monitor —— 全局样式(纯手写,无框架)
   ============================================================ */

:root {
  --bg: #f4f7fa;
  --panel: #ffffff;
  --line: #dde5ec;
  --line-soft: #e9eff4;
  --ink: #1c2b36;
  --muted: #5d7285;
  --primary: #0b3d66;
  --accent: #1779c4;
  --accent-soft: #e3f0fa;
  --danger: #d9534f;
  --danger-soft: #fbe9e8;
  --ok: #2e8b57;
  --ok-soft: #e6f3ec;
  --warn: #c77405;
  --warn-soft: #fbf1e2;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 42, 67, 0.08), 0 4px 14px rgba(16, 42, 67, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.noscript { padding: 24px; text-align: center; color: var(--danger); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: var(--primary); color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.16); font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  color: rgba(255, 255, 255, 0.78); padding: 7px 14px; border-radius: 8px;
  font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.10); }
.nav a.active { color: #fff; background: rgba(255, 255, 255, 0.18); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
}
.topbar-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.sync { color: rgba(255, 255, 255, 0.72); font-size: 12.5px; }
.tag {
  padding: 2px 8px; border-radius: 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.5px; background: var(--warn); color: #fff;
}

/* ---------- 视图容器 ---------- */
.view { max-width: 1280px; margin: 0 auto; padding: 20px 20px 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h2 { font-size: 19px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- 工具栏与表单控件 ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.input, select.input {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 121, 196, 0.14); }
input.input[type="search"] { width: 230px; }
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1267ab; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- 表格 ---------- */
.table-wrap { overflow: hidden; }
.table-meta { padding: 10px 14px; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line-soft); }
.table-scroll { overflow: auto; max-height: calc(100vh - 220px); }
table.sched-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.sched-table th, .sched-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
.sched-table thead th {
  position: sticky; top: 0; z-index: 2; background: #f7fafc;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted);
  cursor: pointer; user-select: none; border-bottom: 1px solid var(--line);
}
.sched-table thead th:hover { color: var(--accent); }
.sched-table thead th.sorted { color: var(--accent); background: var(--accent-soft); }
.sort-ind { font-size: 10px; margin-left: 2px; }
.sched-table tbody tr { cursor: pointer; }
.sched-table tbody tr:hover { background: #f2f7fb; }
.sched-table tbody tr:last-child td { border-bottom: none; }

/* ---------- 状态徽章 ---------- */
.chip {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--line-soft); color: var(--muted);
}
.chip.status-confirmed { background: var(--accent-soft); color: var(--accent); }
.chip.status-on-schedule { background: var(--ok-soft); color: var(--ok); }
.chip.status-delayed { background: var(--danger-soft); color: var(--danger); }
.chip.status-rolled { background: var(--warn-soft); color: var(--warn); }
.chip.type-web { background: var(--accent-soft); color: var(--accent); }
.chip.type-pdf { background: var(--warn-soft); color: var(--warn); }
.chip.type-service { background: #e9f7ef; color: #1f7a4d; }

/* ---------- 列显隐弹层 ---------- */
.colpick { position: relative; }
.colpop {
  position: absolute; right: 0; top: 40px; z-index: 30; min-width: 190px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px;
}
.colopt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.colopt:hover { background: var(--line-soft); }
.colpop-actions { border-top: 1px solid var(--line-soft); margin-top: 6px; padding-top: 6px; text-align: right; }

/* ---------- 日历视图 ---------- */
.cal-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-month { font-size: 17px; font-weight: 600; min-width: 170px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); overflow: hidden; }
.cal-dow {
  padding: 9px 6px; text-align: center; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
  background: #f7fafc; border-bottom: 1px solid var(--line);
}
.cal-cell {
  min-height: 96px; padding: 6px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
  background: #fff; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell.other { background: #fafcfd; color: var(--muted); }
.cal-cell.today .cal-num { background: var(--accent); color: #fff; }
.cal-cell.has-events { background: #f7fbfe; }
/* 订舱窗口高亮:日期格落在某行的 ERD → LRD 区间内 */
.cal-cell.cal-win { background: #eaf5ec; }
.cal-cell.cal-win.cal-win { background: #eaf5ec; }
.cal-num {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.cal-chip {
  border: none; border-left: 3px solid var(--cc, #5d7285);
  /* 整个 chip 染上船司色:浅色底 + 同色系深字,多船重叠时一眼区分 */
  background: color-mix(in srgb, var(--cc, #5d7285) 16%, #ffffff);
  color: color-mix(in srgb, var(--cc, #5d7285) 72%, #1c2b36);
  font-weight: 600;
  font-size: 11.5px; text-align: left; cursor: pointer;
  padding: 3px 6px; border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-chip:hover { background: color-mix(in srgb, var(--cc, #5d7285) 30%, #ffffff); }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }

/* ---------- 可编辑单元格与内联编辑器 ---------- */
.editable {
  cursor: pointer; border-bottom: 1px dashed var(--muted); padding-bottom: 1px;
}
.editable:hover { color: var(--accent); border-bottom-color: var(--accent); }
.edit-mark {
  display: inline-block; margin-left: 4px; font-size: 10px; opacity: 0; color: var(--muted);
}
.editable:hover .edit-mark { opacity: 1; }
/* Status 绿色高亮:BKG 已填 + LRD 为铁路 PDF 实际值(无括号) */
.editable-booked {
  background: var(--ok-soft); color: var(--ok); font-weight: 600;
  border-radius: 5px; padding: 2px 7px; border-bottom: none;
}
.editable-booked:hover { color: var(--ok); border-bottom-color: var(--ok); }
.cell-editor {
  position: fixed; z-index: 70; background: #fff; border: 1px solid var(--line);
  border-radius: 9px; box-shadow: var(--shadow); padding: 10px; width: 230px;
  display: flex; flex-direction: column; gap: 8px;
}
.cell-editor .input { width: 100%; }
.cell-editor-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- 自定义下拉筛选(Excel 自动筛选风格:紧凑按钮 + 紧贴等宽菜单) ---------- */
.dd { position: relative; display: inline-block; }
.dd-btn { gap: 8px; color: var(--ink); }
.dd-arrow { font-size: 10px; color: var(--muted); }
.dd.open .dd-btn {
  border-color: var(--accent); color: var(--accent);
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
}
.dd.open .dd-arrow { color: var(--accent); }
.dd-pop {
  position: absolute; left: 0; top: calc(100% - 1px); z-index: 30;
  width: max-content; min-width: 100%;
  max-height: 300px; overflow-y: auto; background: #fff;
  border: 1px solid var(--accent); border-top: 1px solid var(--line);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 6px 14px rgba(16, 42, 67, 0.12); padding: 5px;
}
.dd-opt { padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13.5px; color: var(--ink); white-space: nowrap; }
.dd-opt:hover { background: var(--accent-soft); }
.dd-opt.selected { color: var(--accent); font-weight: 600; }

/* ---------- 可编辑单元格:点击就地变输入框 ---------- */
.cell-input {
  width: 100%; min-width: 90px; border: 2px solid var(--accent); border-radius: 6px;
  padding: 3px 8px; font: inherit; font-size: 13.5px; outline: none; background: #fffde9;
  box-shadow: 0 0 0 3px rgba(23, 121, 196, 0.12);
}

/* ---------- 变更中心 ---------- */
.change-day { margin: 18px 0 8px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.change-item {
  display: flex; align-items: baseline; gap: 12px; padding: 11px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.change-item:last-child { border-bottom: none; }
.change-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; position: relative; top: -1px; }
.change-item.unread .change-dot { background: var(--accent); }
.change-time { color: var(--muted); font-size: 12.5px; flex: none; width: 44px; }
.change-vessel { font-weight: 600; flex: none; }
.change-text { color: var(--ink); }
.change-item.unread .change-text { font-weight: 600; }
.change-arrow { color: var(--danger); font-weight: 600; }
.change-src { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }

/* ---------- 抽屉 ---------- */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(15, 34, 51, 0.35);
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(440px, 94vw); height: 100%; background: #fff; box-shadow: -6px 0 24px rgba(16, 42, 67, 0.18);
  display: flex; flex-direction: column; transform: translateX(30px); opacity: 0.4; transition: transform 0.2s ease, opacity 0.2s ease;
}
.drawer-overlay.open .drawer { transform: none; opacity: 1; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { font-size: 15.5px; }
.drawer-body { padding: 16px 18px; overflow-y: auto; flex: 1; }

/* ---------- 详情 ---------- */
.detail-vessel { display: flex; align-items: center; gap: 9px; font-size: 16px; margin-bottom: 14px; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0; }
.detail-row { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.detail-row dt { color: var(--muted); flex: none; }
.detail-row dd { margin: 0; text-align: right; word-break: break-word; }

/* ---------- 设置页 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: none; background: none; font: inherit; font-weight: 500; color: var(--muted);
  padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.settings-section { margin-bottom: 20px; }
.settings-section h3 { font-size: 14.5px; margin-bottom: 10px; }
.src-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.src-table th, .src-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.src-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.src-url { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
.src-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.src-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.src-status .dot { width: 9px; height: 9px; }
.dot-ok { background: var(--ok); }
.dot-error { background: var(--danger); }
.dot-idle { background: var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form-field textarea {
  font: 12.5px/1.5 ui-monospace, Consolas, monospace; min-height: 96px; resize: vertical;
}
.form-hint { font-size: 11.5px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.check-row { display: flex; align-items: center; gap: 8px; }

/* ---------- 连接/令牌卡片 ---------- */
.conn-card { max-width: 520px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.conn-row { display: flex; gap: 8px; align-items: center; }
.conn-row .input { flex: 1; }
.info-box { background: var(--accent-soft); border: 1px solid #cbe3f4; color: #20536f; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #22384a; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13.5px;
  box-shadow: var(--shadow); max-width: 360px; opacity: 1; transition: opacity 0.3s, transform 0.3s;
}
.toast-success { background: var(--ok); }
.toast-error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- 令牌门 ---------- */
.gate { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-card {
  width: 360px; max-width: 92vw; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 30px 28px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.gate-logo {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; letter-spacing: 1px;
}
.gate-card h1 { font-size: 17px; }
.gate-sub { color: var(--muted); font-size: 13px; margin: 0; }
.gate-card input {
  height: 40px; border: 1px solid var(--line); border-radius: 9px; padding: 0 12px;
  text-align: center; font: inherit; outline: none;
}
.gate-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 121, 196, 0.14); }
.gate-error { color: var(--danger); font-size: 12.5px; margin: 0; }

/* ---------- 空状态 ---------- */
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .nav { order: 3; width: 100%; }
  .view { padding: 14px 12px 50px; }
  input.input[type="search"] { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .cal-cell { min-height: 64px; }
  .table-scroll { max-height: none; }
  .change-src { display: none; }
}
