:root {
    --bg: #f5f5f3; --surface: #ffffff; --border: #dcdad3; --border-strong: #c4c1b8;
    --text: #1a1a18; --text-2: #6b6862; --text-muted: #99968d;
    --accent: #2f5233; --accent-bg: #eaf1e8; --danger: #a23b2e; --radius: 6px;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  }
  * { box-sizing: border-box; }
  body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
  .wrap { max-width: none; margin: 0; padding: 24px 32px; }
  h1 { font-size: 20px; font-weight: 600; margin: 0 0 10px; }
  .page-head { margin-bottom: 18px; }
  .app-nav { display: flex; gap: 4px; background: #eeece5; border-radius: 8px; padding: 3px; width: fit-content; }
  .app-nav-item { display: inline-block; text-decoration: none; padding: 7px 16px; font-size: 13px; font-weight: 500; color: var(--text-2); border-radius: 6px; }
  .app-nav-item:hover { color: var(--text); }
  .app-nav-item.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
  .filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }
  .field { display: flex; flex-direction: column; gap: 4px; position: relative; min-width: 0; }
  .field.span-2 { grid-column: span 2; }
  .field-dates { display: flex; gap: 6px; min-width: 0; }
  .field-dates input[type="date"] { flex: 1 1 0; min-width: 0; width: auto; }
  @media (max-width: 520px) {
    .field.span-2 { grid-column: auto; }
    .field-dates { flex-direction: column; }
  }
  .field label { font-size: 12px; color: var(--text-2); font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
  .field .remove-x { cursor: pointer; color: var(--text-muted); font-size: 14px; padding: 0 2px; }
  .field .remove-x:hover { color: var(--danger); }
  .field input, .field select { height: 32px; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0 8px; font-size: 13px; background: var(--surface); color: var(--text); width: 100%; }
  .field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
  .ms { position: relative; }
  .ms-trigger { width: 100%; height: 32px; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0 28px 0 8px; font-size: 13px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ms-trigger:hover { background: #fafaf8; }
  .ms.open .ms-trigger { outline: 2px solid var(--accent); outline-offset: -1px; }
  .ms-caret { position: absolute; right: 8px; top: 8px; color: var(--text-2); pointer-events: none; font-size: 11px; }
  .ms-drop { display: none; position: absolute; top: 34px; left: 0; right: 0; z-index: 30; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 280px; overflow: hidden; }
  .ms.open .ms-drop { display: flex; flex-direction: column; }
  .ms-search { width: 100%; height: 30px; border: 0; border-bottom: 1px solid var(--border); padding: 0 8px; font-size: 13px; border-radius: 0; }
  .ms-search:focus { outline: none; }
  .ms-opts { overflow-y: auto; max-height: 200px; padding: 4px 0; }
  .ms-opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--text); }
  .ms-opt span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .ms-opt:hover { background: var(--accent-bg); }
  .ms-opt:has(input:checked) { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
  .ms-opt.hidden { display: none; }
  .ms-opt input {
    appearance: none; -webkit-appearance: none;
    width: 16px; height: 16px; margin: 0; flex-shrink: 0;
    border: 1.5px solid var(--border-strong); border-radius: 4px;
    background: var(--surface); cursor: pointer;
  }
  .ms-opt input:checked {
    background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.4l3 3.1 6-6.2'/%3E%3C/svg%3E") center / 12px 12px no-repeat;
    border-color: var(--accent);
  }
  .ms-empty { padding: 10px; font-size: 12px; color: var(--text-muted); }
  .ms-foot { padding: 6px 8px; border-top: 1px solid var(--border); }
  .ms-foot button { height: 24px; padding: 0 8px; font-size: 12px; }
  .field.pinned label { color: var(--accent); }
  .filters-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); flex-wrap: wrap; gap: 10px; }
  .add-field-wrap { position: relative; }
  .btn { height: 32px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text); }
  .btn:hover { background: #f0efeb; }
  .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .btn-primary:hover { background: #274529; }
  .btn-ghost { border-color: transparent; color: var(--text-2); }
  .btn-dashed { border: 1px dashed var(--border-strong); color: var(--text-2); background: none; }
  .btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
  .field-picker { display: none; position: absolute; top: 36px; left: 0; z-index: 20; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,.12); width: 280px; max-height: 320px; overflow-y: auto; }
  .field-picker.show { display: block; }
  .field-picker-search { padding: 8px; border-bottom: 1px solid var(--border); }
  .field-picker-search input { width: 100%; height: 30px; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 0 8px; font-size: 13px; }
  .field-picker-group { padding: 6px 10px 2px; font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: .03em; }
  .field-picker-item { padding: 7px 12px; font-size: 13px; cursor: pointer; }
  .field-picker-item:hover { background: var(--accent-bg); }
  .field-picker-item.disabled { color: var(--text-muted); cursor: default; background: none; }
  .toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
  .toolbar-left { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-2); }
  .toolbar-left b { color: var(--text); }
  .table-scroll { position: relative; width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
  .table-scroll.is-loading { min-height: 180px; }
  .table-loading {
    position: absolute; inset: 0; z-index: 2;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    background: rgba(255,255,255,.78); color: var(--text-muted); font-size: 13px;
  }
  .table-loading[hidden] { display: none; }
  .page-spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: page-spin .7s linear infinite;
  }
  @keyframes page-spin { to { transform: rotate(360deg); } }
  table { border-collapse: collapse; background: var(--surface); table-layout: fixed; width: max-content; min-width: 100%; }
  thead th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .02em; padding: 10px 12px; background: #f0efeb; border-bottom: 1px solid var(--border); white-space: nowrap; position: relative; overflow: hidden; }
  thead th.th-drag { cursor: grab; user-select: none; }
  thead th.th-drag:active { cursor: grabbing; }
  .th-label { display: block; overflow: hidden; text-overflow: ellipsis; }
  .th-resize { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
  .th-resize:hover, body.col-resizing .th-resize { background: rgba(47, 82, 51, 0.22); }
  body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-select: none !important; }
  body.col-moving, body.col-moving * { cursor: grabbing !important; user-select: none !important; }
  #table-head-row th.col-origin, #table-body td.col-origin { opacity: 0.2; }
  .col-ghost {
    position: fixed; z-index: 80; pointer-events: none; overflow: hidden;
    background: var(--surface); box-shadow: 0 10px 28px rgba(0,0,0,.22);
    border: 1px solid var(--border-strong); border-radius: 2px;
  }
  .col-ghost table { table-layout: fixed; width: 100%; border-collapse: collapse; background: var(--surface); }
  .col-ghost thead th { overflow: hidden; }
  .col-ghost .th-resize { display: none; }
  tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  tbody tr:last-child td { border-bottom: none; }
  tbody tr:hover { background: #fafaf8; }
  tbody tr.clickable { cursor: pointer; }
  .chk { width: 32px; text-align: center; }
  .chk input[type="checkbox"] {
    appearance: none; -webkit-appearance: none;
    width: 16px; height: 16px; margin: 0; vertical-align: middle;
    border: 1.5px solid var(--border-strong); border-radius: 4px;
    background: var(--surface); cursor: pointer;
  }
  .chk input[type="checkbox"]:hover { border-color: var(--accent); }
  .chk input[type="checkbox"]:checked {
    background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.4l3 3.1 6-6.2'/%3E%3C/svg%3E") center / 12px 12px no-repeat;
    border-color: var(--accent);
  }
  .chk input[type="checkbox"]:indeterminate {
    background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' d='M3.5 8h9'/%3E%3C/svg%3E") center / 12px 12px no-repeat;
    border-color: var(--accent);
  }
  .uuid-link { color: #2f6fa8; text-decoration: none; font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
  .uuid-link:hover { text-decoration: underline; color: #1a4d7a; }
  .badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; }
  .badge-clean { background: #e6f1e6; color: #2f5233; }
  .badge-dup { background: #fbeee6; color: #a23b2e; }
  .badge-err { background: #f0efeb; color: var(--text-2); }
  .stage { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
  .dot { width: 6px; height: 6px; border-radius: 50%; background: #99968d; }
  .dot-1 { background: #8a8680; }
  .dot-2 { background: #b58a2b; }
  .dot-3 { background: #2f6fa8; }
  .dot-4 { background: #2f5233; }
  .dot-5 { background: #6b3fa0; }
  .dot-6 { background: #a23b2e; }
  .dot-7 { background: #6b6862; }
  .empty { text-align: center; padding: 40px; color: var(--text-muted); }
  .pager { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
  .pager-left { font-size: 13px; color: var(--text-2); }
  .pager-right { display: flex; align-items: center; gap: 6px; }
  .page-btn { min-width: 30px; height: 30px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); font-size: 13px; cursor: pointer; color: var(--text); }
  .page-btn:hover:not(:disabled) { background: #f0efeb; }
  .page-btn:disabled { opacity: .4; cursor: default; }
  .page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .export-toast { margin-top: 10px; padding: 10px 14px; background: var(--accent-bg); border: 1px solid #c3d9c3; border-radius: var(--radius); font-size: 13px; color: var(--accent); display: none; }
  .export-toast.show { display: block; }
  .filter-chip { display:inline-flex; align-items:center; gap:6px; padding: 4px 6px 4px 12px; background: var(--accent-bg); border: 1px solid #c3d9c3; border-radius: 20px; font-size: 12px; color: var(--accent); cursor: pointer; }
  .filter-chip:hover { background: #dcecdc; }
  .filter-chip .chip-x { width:16px; height:16px; border-radius:50%; display:flex; align-items:center; justify-content:center; color: var(--accent); font-size: 13px; line-height:1; }
  .filter-chip .chip-x:hover { background: #c3d9c3; }
  .overlay { display: none; position: fixed; inset: 0; z-index: 40; margin: 0; padding: 40px 16px; background: rgba(20,20,18,0.45); overflow-y: auto; align-items: flex-start; justify-content: center; }
  .overlay.show { display: flex; }
  .card { width: 720px; max-width: 92%; background: var(--surface); border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }
  .card-head { display:flex; justify-content:space-between; align-items:flex-start; padding: 18px 22px; border-bottom: 1px solid var(--border); background: #f8f7f4; }
  .card-title { font-size: 17px; font-weight: 600; margin: 0 0 4px; }
  .card-sub { font-size: 13px; color: var(--text-2); }
  .card-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text-2); line-height: 1; padding: 4px 8px; }
  .card-close:hover { color: var(--text); }
  .card-body { padding: 18px 22px; max-height: 70vh; overflow-y: auto; }
  .card-section { margin-bottom: 16px; }
  .card-section:last-child { margin-bottom: 0; }
  .card-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); margin: 0 0 10px; font-weight: 600; }
  .kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; }
  .kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
  .kv .k { color: var(--text-2); }
  .kv .v { font-weight: 500; text-align: right; }
  .kv-drag { cursor: grab; }
  .kv-drag:active { cursor: grabbing; }
  .kv-drag .drag-handle { color: var(--text-muted); margin-right: 6px; font-size: 12px; }
  .kv-drag.dragging { opacity: .4; }
  .kv-drag.drop-target { box-shadow: inset 0 2px 0 var(--accent); }
  .timeline { position: relative; padding-left: 18px; }
  .timeline::before { content:''; position:absolute; left:4px; top:4px; bottom:4px; width:1px; background: var(--border-strong); }
  .tl-item { position: relative; padding-bottom: 16px; font-size: 13px; }
  .tl-item:last-child { padding-bottom: 0; }
  .tl-item::before { content:''; position:absolute; left:-18px; top:3px; width:9px; height:9px; border-radius:50%; background: var(--accent); border: 2px solid var(--surface); }
  .tl-item.tl-dispatch::before { background: #2f6fa8; }
  .tl-item.tl-queue::before { background: #b0892e; }
  .tl-badge.wait { background: #f4efe3; color: #7a5b1e; }
  .tl-time { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
  .tl-label { font-weight: 500; }
  .tl-detail { color: var(--text-2); font-size: 12.5px; margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .tl-chevron { border: none; background: none; color: var(--text-2); cursor: pointer; padding: 0 2px; font-size: 12px; line-height: 1; }
  .tl-chevron:hover { color: var(--text); }
  .tl-resend { margin-left: auto; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 4px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-2); flex-shrink: 0; padding: 0; }
  .tl-resend svg { pointer-events: none; }
  .tl-resend:hover { background: #f0efeb; color: var(--text); }
  .tl-resend:disabled { opacity: .5; cursor: default; }
  .tl-body { margin: 8px 0 0; padding: 8px 10px; background: #f7f6f2; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
  .tl-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; margin-left: 6px; vertical-align: middle; }
  .tl-badge.ok { background: #e6f1e6; color: #2f5233; }
  .tl-badge.fail { background: #fbeee6; color: #a23b2e; }
  .raw-link { display:inline-block; margin-top:8px; font-size: 13px; color: var(--accent); cursor: pointer; text-decoration: underline; }
  .call-player { display: flex; flex-direction: column; gap: 8px; }
  .call-player-audio { width: 100%; height: 40px; accent-color: var(--accent); }
  .call-player-error { margin: 0; font-size: 12px; color: var(--danger); }
  .dispatch-row { display:flex; justify-content:space-between; align-items:center; gap:12px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
  .dispatch-row:last-child { border-bottom: none; }

  .col-picker-wrap { position: relative; }
  .col-picker { display: none; position: fixed; z-index: 999; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0,0,0,.12); width: 260px; }
  .col-picker.show { display: block; }
  .col-picker-head { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
  .col-picker-list { max-height: 320px; overflow-y: auto; padding: 4px 0; }
  .col-picker-item { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 13px; cursor: grab; }
  .col-picker-item:hover { background: var(--accent-bg); }
  .col-picker-item.dragging { opacity: .4; }
  .col-picker-item .drag-handle { color: var(--text-muted); cursor: grab; }
  .col-picker-item label { flex: 1; cursor: pointer; }
  .col-picker-foot { padding: 8px 12px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; }