:root {
      --bg: #f5f7f9;
      --panel: #ffffff;
      --ink: #17212b;
      --muted: #667586;
      --line: #dce3ea;
      --soft: #eef3f7;
      --blue: #1967d2;
      --green: #13795b;
      --red: #c24136;
      --yellow: #9a6700;
      --teal: #0f766e;
      --shadow: 0 16px 42px rgba(22, 35, 50, .08);
      --radius: 8px;
    }

    * { box-sizing: border-box; }
    body {
      margin: 0;
      color: var(--ink);
      background: var(--bg);
      font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
      letter-spacing: 0;
      overflow-x: hidden;
    }

    button, input, select, textarea { font: inherit; }
    button {
      border: 1px solid var(--line);
      background: var(--panel);
      color: var(--ink);
      border-radius: 7px;
      padding: 8px 11px;
      cursor: pointer;
      transition: .16s ease;
      white-space: nowrap;
    }
    button:hover { border-color: #aab7c4; box-shadow: 0 4px 12px rgba(22,35,50,.08); }
    button:disabled, select:disabled, input:disabled, textarea:disabled {
      cursor: not-allowed;
      opacity: .55;
      box-shadow: none;
    }
    button.primary { color: white; background: var(--blue); border-color: var(--blue); }
    button.danger { color: var(--red); }
    button.ghost { background: transparent; }
    button.icon { width: 36px; height: 36px; display: grid; place-items: center; padding: 0; }
    button.link {
      border: 0;
      background: transparent;
      padding: 4px 6px;
      color: var(--blue);
      box-shadow: none;
    }

    input, select, textarea {
      border: 1px solid var(--line);
      background: white;
      border-radius: 7px;
      padding: 8px 10px;
      color: var(--ink);
      min-width: 0;
      width: 100%;
    }
    textarea { min-height: 74px; resize: vertical; }
    label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
    label span { color: var(--ink); font-size: 13px; font-weight: 700; }

    .app { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
    .topbar {
      height: 68px;
      display: grid;
      grid-template-columns: 300px 1fr auto;
      align-items: center;
      gap: 18px;
      padding: 0 22px;
      background: rgba(255,255,255,.94);
      border-bottom: 1px solid var(--line);
      position: sticky;
      top: 0;
      z-index: 10;
      backdrop-filter: blur(10px);
    }
    .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
    .mark {
      width: 38px;
      height: 38px;
      border-radius: 8px;
      background: linear-gradient(135deg, #1967d2, #0f766e);
      display: grid;
      place-items: center;
      color: white;
      font-weight: 800;
    }
    .brand h1 { margin: 0; font-size: 18px; line-height: 1.1; }
    .brand span, .toolbar-note, .muted { color: var(--muted); font-size: 12px; }
    .week-nav { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
    .week-title { min-width: 222px; text-align: center; font-weight: 700; white-space: nowrap; }
    .actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
    .role-select { width: 132px; }
    .top-scope {
      display: flex;
      gap: 8px;
      align-items: center;
      padding-right: 4px;
      border-right: 1px solid var(--line);
    }
    .global-workplace { width: 120px; }
    .readonly-note { color: var(--yellow); font-size: 12px; font-weight: 700; }
    .is-hidden { display: none !important; }
    .login-screen {
      position: fixed;
      inset: 0;
      z-index: 100;
      display: grid;
      place-items: center;
      padding: 20px;
      background: linear-gradient(135deg, #eef5ff, #f7fafc 46%, #eefaf5);
    }
    .login-card {
      width: min(420px, 100%);
      display: grid;
      gap: 16px;
      padding: 22px;
      background: white;
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: 0 24px 70px rgba(22, 35, 50, .16);
    }
    .login-card h2 { margin: 0; font-size: 22px; }
    .login-card p { margin: 0; color: var(--muted); font-size: 13px; }
    .login-tip {
      display: grid;
      gap: 4px;
      padding: 10px;
      border-radius: 8px;
      background: #f7fafc;
      color: var(--muted);
      font-size: 12px;
    }
    .user-chip {
      display: grid;
      gap: 2px;
      min-width: 120px;
      color: var(--muted);
      font-size: 12px;
    }
    .user-chip strong { color: var(--ink); font-size: 13px; }

    .layout {
      display: grid;
      grid-template-columns: 236px minmax(0, 1fr);
      min-height: calc(100vh - 68px);
    }
    .nav {
      background: #ffffff;
      border-right: 1px solid var(--line);
      padding: 14px;
      display: grid;
      align-content: start;
      gap: 8px;
    }
    .tab-btn {
      display: grid;
      grid-template-columns: 28px 1fr;
      align-items: center;
      gap: 10px;
      border: 0;
      background: transparent;
      text-align: left;
      padding: 11px;
      border-radius: 8px;
      color: #344253;
      box-shadow: none;
    }
    .tab-btn strong { font-size: 14px; }
    .tab-btn span {
      width: 28px;
      height: 28px;
      display: grid;
      place-items: center;
      border-radius: 7px;
      background: var(--soft);
      color: var(--blue);
      font-weight: 800;
    }
    .tab-btn.active { background: #edf5ff; color: var(--blue); }
    .nav-card {
      margin-top: 8px;
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 11px;
      display: grid;
      gap: 7px;
      background: #fbfcfd;
    }

    .content { padding: 16px; min-width: 0; }
    .panel, .forecast-output, .forecast-inputs, .template-buttons { min-width: 0; }
    .view { display: none; }
    .view.active { display: block; }
    .shell {
      display: grid;
      grid-template-columns: 260px minmax(480px, 1fr) 288px;
      gap: 12px;
      align-items: start;
      position: relative;
      min-width: 0;
    }
    .shell.sidebar-hidden {
      grid-template-columns: minmax(0, 1fr) 288px;
    }
    .shell.insights-hidden {
      grid-template-columns: 260px minmax(0, 1fr);
    }
    .shell.sidebar-hidden.insights-hidden {
      grid-template-columns: minmax(0, 1fr);
    }
    .shell.sidebar-hidden .sidebar {
      display: none;
    }
    .shell.insights-hidden .insights {
      display: none;
    }
    .seat-pool-handle,
    .insights-handle {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 96px;
      height: 34px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #ffffff;
      color: #344253;
      padding: 0 10px;
      font-size: 12px;
      font-weight: 800;
    }
    .seat-pool-handle:hover,
    .insights-handle:hover {
      border-color: var(--blue);
      color: var(--blue);
      background: #edf5ff;
    }
    .schedule-toolbar.readonly-schedule .editor {
      display: none;
    }
    .schedule-toolbar {
      position: sticky;
      top: 68px;
      z-index: 8;
      display: grid;
      grid-template-columns: minmax(250px, auto) minmax(420px, 1fr) auto;
      gap: 8px;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      flex-wrap: wrap;
      padding: 10px 0;
      background: rgba(245, 247, 249, .96);
      backdrop-filter: blur(8px);
    }
    .schedule-controls {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
    }
    .schedule-controls select {
      width: auto;
      min-width: 126px;
    }
    .schedule-search {
      width: clamp(180px, 18vw, 260px);
      min-height: 34px;
    }
    .sidebar, .board, .insights, .panel {
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      min-width: 0;
    }
    .sidebar, .insights, .panel { padding: 14px; display: grid; gap: 14px; }
    .sidebar, .insights {
      max-height: calc(100vh - 176px);
      overflow-y: auto;
      overscroll-behavior: contain;
      scrollbar-gutter: stable;
    }
    .panel-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      padding-bottom: 4px;
    }
    .panel-head h2, .section-title h2 { margin: 0; font-size: 16px; line-height: 1.2; }
    .section-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
      margin-bottom: 9px;
    }
    .section-title h2 { font-size: 14px; }
    .section-title small { color: var(--muted); font-size: 12px; }

    .agent-list, .shift-list, .metric-list { display: grid; gap: 8px; }
    .agent {
      display: grid;
      grid-template-columns: 34px 1fr auto;
      align-items: center;
      gap: 9px;
      padding: 9px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fbfcfd;
    }
    .avatar {
      width: 34px;
      height: 34px;
      border-radius: 8px;
      display: grid;
      place-items: center;
      color: white;
      font-size: 13px;
      font-weight: 800;
    }
    .agent b, .shift b { display: block; font-size: 13px; margin-bottom: 2px; }
    .agent span, .shift span, .metric span, .notice span { color: var(--muted); font-size: 12px; }
    .tag {
      padding: 4px 7px;
      border-radius: 999px;
      background: var(--soft);
      color: #2d3b49;
      font-size: 12px;
      white-space: nowrap;
    }
    .tag.on { color: var(--green); background: #eefaf5; }
    .tag.off { color: var(--red); background: #fff1f0; }
    .import-box .tag {
      border-radius: 8px;
      white-space: normal;
      line-height: 1.6;
    }
    .shift {
      display: grid;
      grid-template-columns: 12px 1fr;
      gap: 8px;
      align-items: center;
      padding: 9px;
      border: 1px solid var(--line);
      border-radius: 8px;
      cursor: grab;
      user-select: none;
    }
    .shift:active { cursor: grabbing; }
    .swatch { width: 12px; height: 38px; border-radius: 99px; }
    .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

    .board {
      min-width: 0;
      max-height: calc(100vh - 176px);
      min-height: 420px;
      overflow: auto;
      overscroll-behavior: contain;
      scrollbar-gutter: stable;
    }
    .board.month-mode {
      overflow-x: auto;
      overflow-y: auto;
    }
    .board-head, .row {
      display: grid;
      grid-template-columns: 190px repeat(7, 136px);
      min-width: 1142px;
      width: 1142px;
    }
    .board.month-mode .board-head,
    .board.month-mode .row {
      grid-template-columns: 190px repeat(30, 136px);
      min-width: 4270px;
      width: 4270px;
    }
    .board-head {
      position: sticky;
      top: 0;
      z-index: 7;
      border-bottom: 1px solid var(--line);
      background: #fbfcfd;
    }
    .row { min-height: 86px; border-bottom: 1px solid var(--line); }
    .row:last-child { border-bottom: 0; }
    .corner, .day-head {
      padding: 12px 10px;
      min-height: 64px;
      border-right: 1px solid var(--line);
      display: grid;
      align-content: center;
      gap: 4px;
    }
    .corner {
      position: sticky;
      left: 0;
      z-index: 5;
      background: #fbfcfd;
      box-shadow: 4px 0 8px rgba(22, 35, 50, .04);
    }
    .day-head:last-child, .cell:last-child { border-right: 0; }
    .day-head strong, .person-cell b { font-size: 13px; }
    .day-head span, .person-cell span { color: var(--muted); font-size: 12px; }
    .coverage {
      height: 6px;
      border-radius: 999px;
      overflow: hidden;
      background: #e9eef3;
      margin-top: 4px;
    }
    .coverage i { display: block; height: 100%; width: var(--w); background: var(--c); }
    .person-cell {
      position: sticky;
      left: 0;
      z-index: 4;
      border-right: 1px solid var(--line);
      padding: 12px;
      display: grid;
      align-content: center;
      gap: 4px;
      background: white;
      box-shadow: 4px 0 8px rgba(22, 35, 50, .04);
    }
    .cell {
      border-right: 1px solid var(--line);
      padding: 9px;
      display: grid;
      gap: 6px;
      align-content: center;
      background: white;
      cursor: pointer;
      min-width: 0;
      overflow: hidden;
      position: relative;
      z-index: 1;
    }
    .cell:hover { background: #f7fafc; }
    .cell.selected { outline: 2px solid var(--blue); outline-offset: -2px; background: #edf5ff; }
    .cell.multi-selected {
      outline: 2px solid var(--teal);
      outline-offset: -2px;
      background: #eefaf5;
    }
    .cell.drag-over {
      background: #edf5ff;
      box-shadow: inset 0 0 0 3px var(--blue);
    }
    .cell.conflict {
      outline: 2px solid var(--red);
      outline-offset: -2px;
      background: #fff7f6;
    }
    .cell.conflict::after {
      content: "!";
      position: absolute;
      right: 6px;
      top: 6px;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      display: grid;
      place-items: center;
      background: var(--red);
      color: #fff;
      font-size: 11px;
      font-weight: 900;
      z-index: 2;
    }
    .pill {
      min-height: 34px;
      border-radius: 7px;
      padding: 7px 8px;
      color: white;
      display: grid;
      gap: 1px;
      box-shadow: inset 0 0 0 1px rgba(255,255,255,.14);
      width: 100%;
      min-width: 0;
      max-width: 100%;
    }
    .pill b, .pill span {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .pill b { font-size: 12px; line-height: 1.1; }
    .pill span { font-size: 11px; opacity: .9; }
    .board.month-mode .pill {
      padding: 7px;
    }
    .board.month-mode .pill b,
    .board.month-mode .pill span {
      font-size: 11px;
    }
    .empty {
      color: #98a4af;
      font-size: 12px;
      border: 1px dashed #cad4dd;
      border-radius: 7px;
      height: 34px;
      display: grid;
      place-items: center;
    }
    .editor {
      padding: 0;
      display: flex;
      justify-content: flex-end;
      flex-wrap: wrap;
      gap: 8px;
      background: transparent;
      align-items: center;
    }
    .editor #selectionText { min-width: 180px; }
    .editor select { width: clamp(160px, 18vw, 260px); max-width: 100%; }

    .metric {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 10px;
      background: #fbfcfd;
      display: grid;
      gap: 6px;
    }
    .metric b { font-size: 20px; line-height: 1; }
    .metric-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
    .notice {
      display: grid;
      gap: 6px;
      padding: 10px;
      border-radius: 8px;
      border: 1px solid var(--line);
      background: white;
    }
    .notice strong { font-size: 13px; }
    .notice.warning { border-color: #f0d48a; background: #fff9e8; }
    .notice.good { border-color: #a9dcc9; background: #eefaf5; }
    .notice.risk { border-color: #efb0aa; background: #fff1f0; }
    .workbench-feedback {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      margin-top: 12px;
    }
    .feedback-list {
      display: grid;
      gap: 8px;
      max-height: 220px;
      overflow: auto;
    }
    .feedback-item {
      display: grid;
      gap: 4px;
      padding: 10px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #fbfcfd;
      text-align: left;
      white-space: normal;
    }
    .feedback-item.conflict { border-color: #efb0aa; background: #fff7f6; }
    .feedback-item.summary { border-color: #a9dcc9; background: #eefaf5; }
    .feedback-item b { font-size: 13px; }
    .feedback-item span { color: var(--muted); font-size: 12px; line-height: 1.45; }
    .heat {
      display: grid;
      grid-template-columns: repeat(24, 1fr);
      gap: 2px;
      align-items: end;
      height: 78px;
      padding-top: 8px;
    }
    .bar {
      min-width: 5px;
      border-radius: 3px 3px 0 0;
      background: var(--teal);
      height: var(--h);
      opacity: var(--o);
    }

    .table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; max-width: 100%; min-width: 0; }
    table { width: 100%; border-collapse: collapse; min-width: 860px; background: white; }
    th, td {
      padding: 11px 12px;
      border-bottom: 1px solid var(--line);
      text-align: left;
      font-size: 13px;
      vertical-align: middle;
    }
    th { background: #fbfcfd; color: #405061; font-size: 12px; font-weight: 800; }
    tr:last-child td { border-bottom: 0; }
    .color-chip {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      white-space: nowrap;
    }
    .color-dot {
      width: 14px;
      height: 14px;
      border-radius: 99px;
      display: inline-block;
      border: 1px solid rgba(0,0,0,.12);
    }
    .row-actions { display: flex; gap: 6px; align-items: center; }

    .form-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 12px;
    }
    .form-grid .full { grid-column: 1 / -1; }
    .modal-backdrop {
      position: fixed;
      inset: 0;
      display: none;
      place-items: center;
      background: rgba(15, 23, 42, .36);
      z-index: 50;
      padding: 18px;
    }
    .modal-backdrop.open { display: grid; }
    .modal {
      width: min(760px, 100%);
      max-height: min(760px, calc(100vh - 36px));
      overflow: auto;
      background: white;
      border-radius: 8px;
      border: 1px solid var(--line);
      box-shadow: 0 28px 80px rgba(15,23,42,.22);
    }
    .modal-head, .modal-actions {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 14px;
      border-bottom: 1px solid var(--line);
    }
    .modal-head h3 { margin: 0; font-size: 16px; }
    .modal-body { padding: 14px; display: grid; gap: 14px; }
    .modal-actions { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
    .import-box {
      display: grid;
      gap: 12px;
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 14px;
      background: linear-gradient(180deg, #ffffff, #f8fbfd);
    }
    .import-head {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 14px;
    }
    .import-title {
      display: grid;
      gap: 5px;
    }
    .import-title strong {
      font-size: 16px;
    }
    .template-actions {
      display: flex;
      gap: 8px;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
    }
    .template-buttons {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }
    .template-buttons button {
      padding: 7px 9px;
      font-size: 12px;
    }
    .upload-row {
      display: grid;
      grid-template-columns: auto minmax(0, 1fr);
      gap: 10px;
      align-items: center;
      padding: 10px;
      border: 1px dashed #b8c6d3;
      border-radius: 8px;
      background: #ffffff;
    }
    .file-input {
      display: none;
    }
    .file-trigger {
      width: max-content;
      border: 1px solid var(--blue);
      color: var(--blue);
      background: #edf5ff;
      border-radius: 7px;
      padding: 8px 11px;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
    }
    .upload-status {
      min-height: 18px;
      color: var(--muted);
      font-size: 12px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .data-preview {
      display: none;
    }
    .csv-store {
      display: none;
    }
    .rule-summary {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 10px;
    }
    .forecast-grid {
      display: grid;
      grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
      gap: 14px;
      align-items: start;
    }
    .forecast-inputs {
      display: grid;
      gap: 12px;
    }
    .forecast-inputs textarea {
      min-height: 150px;
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 12px;
      line-height: 1.45;
      color: var(--ink);
      background: #f9fbfd;
      caret-color: var(--blue);
      white-space: pre;
      border-color: #cfd9e2;
    }
    .kpi-grid {
      display: grid;
      grid-template-columns: repeat(6, minmax(0, 1fr));
      gap: 10px;
    }
    .forecast-toolbar {
      display: flex;
      gap: 10px;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      flex-wrap: wrap;
    }
    .forecast-toolbar select {
      min-width: 150px;
    }
    .forecast-section-title {
      margin: 14px 0 8px;
      display: flex;
      justify-content: space-between;
      gap: 10px;
      align-items: center;
      color: var(--muted);
      font-size: 12px;
      font-weight: 800;
    }
    .management-toolbar {
      display: flex;
      gap: 10px;
      align-items: center;
      justify-content: space-between;
      margin: 12px 0;
      flex-wrap: wrap;
    }
    .management-toolbar input { max-width: 360px; }
    .field-note {
      color: var(--muted);
      font-size: 11px;
      line-height: 1.45;
    }
    .employee-picker {
      border: 1px solid var(--line);
      border-radius: 8px;
      padding: 10px;
      display: grid;
      gap: 8px;
    }
    .employee-picker select { min-height: 180px; }
    .forecast-custom-dates {
      display: inline-flex;
      gap: 8px;
      align-items: center;
    }
    .forecast-custom-dates input { width: 150px; }
    .scope-tabs {
      display: inline-flex;
      gap: 4px;
      padding: 4px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #f8fbfd;
    }
    .scope-tabs button {
      padding: 7px 10px;
      border: 0;
      background: transparent;
      color: var(--muted);
      font-size: 12px;
      font-weight: 800;
    }
    .scope-tabs button.active {
      background: white;
      color: var(--blue);
      box-shadow: 0 0 0 1px #cfe0f5 inset;
    }

    @media (max-width: 1380px) {
      .shell { grid-template-columns: 250px minmax(0, 1fr); }
      .insights { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); }
      .seat-pool-handle { left: 238px; }
      .insights-handle { right: 4px; }
    }
    @media (max-width: 900px) {
      .topbar {
        height: auto;
        padding: 12px;
        grid-template-columns: 1fr;
      }
      .week-nav { justify-content: start; overflow-x: auto; }
      .actions { justify-content: start; flex-wrap: wrap; }
      .top-scope {
        width: 100%;
        padding-right: 0;
        border-right: 0;
      }
      .top-scope .scope-tabs,
      .global-workplace {
        width: 100%;
      }
      .layout { grid-template-columns: 1fr; }
      .nav { display: flex; overflow-x: auto; }
      .tab-btn { min-width: 118px; }
      .nav-card { display: none; }
      .content { padding: 10px; }
      .shell { grid-template-columns: 1fr; }
      .board { overflow-x: auto; }
      .board-head, .row { min-width: 840px; }
      .schedule-toolbar {
        top: 0;
        grid-template-columns: 1fr;
      }
      .editor { grid-template-columns: 1fr 1fr; }
      .insights { grid-template-columns: 1fr; }
      .form-grid, .rule-summary, .forecast-grid, .kpi-grid { grid-template-columns: 1fr; }
      .week-title { min-width: 190px; }
      .forecast-toolbar { align-items: stretch; }
      .forecast-toolbar .template-buttons {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
      }
      .forecast-toolbar select,
      .forecast-toolbar button,
      .forecast-toolbar .file-trigger,
      .scope-tabs {
        width: 100%;
      }
    }
