/* ============================================================
   CLP Power Hong Kong Limited
   AI Assisted Project Planning and Design - Phase 2
   Corporate design system
   Tokens sourced from the CLP Power corporate site:
     --theme-blue  #0033a0
     --theme-green #08932a
     --theme-grey  #b7b7b7
     font stack    Roboto, Arial
   ============================================================ */

:root {
  /* Corporate core */
  --clp-blue:        #0033A0;
  --clp-blue-900:    #001F61;
  --clp-blue-700:    #002A85;
  --clp-blue-300:    #4D6FBD;
  --clp-blue-100:    #D9E0F1;
  --clp-blue-50:     #EEF2FA;

  --clp-green:       #08932A;
  --clp-green-700:   #066E20;
  --clp-green-100:   #DDF1E2;
  --clp-green-50:    #F1F9F3;

  --clp-grey:        #B7B7B7;
  --clp-grey-700:    #69696C;
  --clp-grey-300:    #D8D8DA;
  --clp-grey-150:    #E8E8EB;
  --clp-grey-100:    #F1F2F4;
  --clp-grey-50:     #F7F8FA;

  --clp-ink:         #1F1F1F;
  --clp-white:       #FFFFFF;

  /* Functional status colours - kept within the corporate tone */
  --clp-amber:       #B26B00;
  --clp-amber-100:   #FBEFD9;
  --clp-red:         #A3231F;
  --clp-red-100:     #F8E3E2;
  --clp-teal:        #006F8A;
  --clp-teal-100:    #DCEEF3;

  /* Typography */
  --font-base: Roboto, Arial, "Helvetica Neue", Helvetica, "Microsoft JhengHei", sans-serif;

  /* Metrics */
  --radius:      4px;
  --radius-lg:   6px;
  --shadow-1:    0 1px 2px rgba(31,31,31,.08), 0 1px 3px rgba(31,31,31,.06);
  --shadow-2:    0 2px 6px rgba(0,51,160,.10), 0 6px 18px rgba(31,31,31,.08);
  --rail-w:      248px;
  --header-h:    60px;
  --subbar-h:    44px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-base);
  font-size: 14px;
  line-height: 1.5;
  color: var(--clp-ink);
  background: var(--clp-grey-50);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4,h5 { margin: 0; font-weight: 500; line-height: 1.3; }
p { margin: 0 0 10px; }
ul, ol { margin: 0 0 10px; padding-left: 20px; }
a { color: var(--clp-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }
::selection { background: var(--clp-blue-100); }

/* ---------- Application shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Corporate header ---------- */
.clp-header {
  height: var(--header-h);
  background: var(--clp-blue);
  color: var(--clp-white);
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
  z-index: 40;
}
/* CLP corporate arrow motif */
.clp-header::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 320px;
  background:
    repeating-linear-gradient(115deg,
      rgba(255,255,255,.075) 0 2px,
      rgba(255,255,255,0) 2px 26px);
  pointer-events: none;
}
.clp-header::before {
  content: "";
  position: absolute;
  right: -60px; top: -40px;
  width: 240px; height: 240px;
  background: var(--clp-green);
  opacity: .16;
  transform: skewX(-22deg);
  pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; min-width: 0; }
.brand-logo-box {
  width: 110px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 110px;
  background: var(--clp-white);
  border-radius: 3px;
  padding: 6px 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.10);
}
.brand-logo {
  display: block;
  width: 88px;
  height: auto;
}
.brand-text { display: flex; flex-direction: column; }
.brand-title { font-size: 14px; font-weight: 500; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,.72); letter-spacing: .02em; }

.header-spacer { flex: 1; }
.header-right { display: flex; align-items: center; gap: 8px; position: relative; z-index: 1; }

.env-badge {
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 2px;
  padding: 3px 8px;
  color: rgba(255,255,255,.9);
}
.env-badge.demo { border-color: var(--clp-green); background: var(--clp-green); color: #fff; }

.role-select {
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.35);
  color: var(--clp-white);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 13px;
  max-width: 230px;
}
.role-select option { color: var(--clp-ink); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--clp-white); color: var(--clp-blue);
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
}

/* ---------- Body layout ---------- */
.shell { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---------- Navigation rail ---------- */
.rail {
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  background: var(--clp-white);
  border-right: 1px solid var(--clp-grey-150);
  padding: 14px 0 24px;
  overflow-y: auto;
}
.rail-group { margin-bottom: 18px; }
.rail-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--clp-grey-700); padding: 0 18px 6px; font-weight: 500;
}
.rail-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; cursor: pointer;
  border-left: 3px solid transparent;
  color: var(--clp-ink); font-size: 13.5px;
}
.rail-item:hover { background: var(--clp-blue-50); }
.rail-item.active {
  background: var(--clp-blue-50);
  border-left-color: var(--clp-blue);
  color: var(--clp-blue);
  font-weight: 500;
}
.rail-item .ico { width: 18px; text-align: center; flex: 0 0 18px; opacity: .8; }
.rail-item .count {
  margin-left: auto; background: var(--clp-grey-100); color: var(--clp-grey-700);
  border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 500;
}
.rail-item.active .count { background: var(--clp-blue); color: #fff; }

/* ---------- Main region ---------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.page { padding: 20px 24px 48px; overflow-y: auto; flex: 1 1 auto; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 21px; font-weight: 500; }
.page-head .sub { color: var(--clp-grey-700); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.breadcrumb { font-size: 12.5px; color: var(--clp-grey-700); margin-bottom: 8px; }
.breadcrumb a { color: var(--clp-grey-700); }
.breadcrumb span { margin: 0 6px; opacity: .6; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--clp-grey-300);
  background: var(--clp-white);
  color: var(--clp-ink);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 7px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--clp-blue-300); color: var(--clp-blue); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--clp-grey-300); color: var(--clp-ink); }
.btn-primary { background: var(--clp-blue); border-color: var(--clp-blue); color: #fff; }
.btn-primary:hover { background: var(--clp-blue-700); border-color: var(--clp-blue-700); color: #fff; }
.btn-accept { background: var(--clp-green); border-color: var(--clp-green); color: #fff; }
.btn-accept:hover { background: var(--clp-green-700); border-color: var(--clp-green-700); color: #fff; }
.btn-danger { color: var(--clp-red); border-color: #E6C6C5; }
.btn-danger:hover { background: var(--clp-red-100); border-color: var(--clp-red); color: var(--clp-red); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-link { border: none; background: none; color: var(--clp-blue); padding: 2px 4px; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--clp-white);
  border: 1px solid var(--clp-grey-150);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--clp-grey-150);
}
.card-head h2 { font-size: 14.5px; font-weight: 500; }
.card-head .hint { font-size: 12px; color: var(--clp-grey-700); }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 10px 16px; border-top: 1px solid var(--clp-grey-150);
  background: var(--clp-grey-50);
  display: flex; gap: 8px; align-items: center;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.split { display: grid; grid-template-columns: minmax(0,1fr) 380px; gap: 16px; align-items: start; }
.split-wide { display: grid; grid-template-columns: 300px minmax(0,1fr); gap: 16px; align-items: start; }
@media (max-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .split, .split-wide { grid-template-columns: minmax(0,1fr); }
}

/* ---------- KPI tiles ---------- */
.kpi {
  background: var(--clp-white);
  border: 1px solid var(--clp-grey-150);
  border-top: 3px solid var(--clp-blue);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.kpi.green { border-top-color: var(--clp-green); }
.kpi.amber { border-top-color: var(--clp-amber); }
.kpi.grey  { border-top-color: var(--clp-grey); }
.kpi .k-label { font-size: 12px; color: var(--clp-grey-700); text-transform: uppercase; letter-spacing: .05em; }
.kpi .k-value { font-size: 28px; font-weight: 500; line-height: 1.15; margin-top: 4px; color: var(--clp-blue); }
.kpi.green .k-value { color: var(--clp-green-700); }
.kpi.amber .k-value { color: var(--clp-amber); }
.kpi.grey  .k-value { color: var(--clp-grey-700); }
.kpi .k-note { font-size: 12px; color: var(--clp-grey-700); margin-top: 4px; }

/* ---------- Tables ---------- */
.tbl { font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 500; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--clp-grey-700);
  padding: 9px 14px; border-bottom: 1px solid var(--clp-grey-150);
  background: var(--clp-grey-50); white-space: nowrap;
}
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--clp-grey-150); vertical-align: top; }
.tbl tbody tr:hover { background: var(--clp-blue-50); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-plain tbody tr:hover { background: transparent; }

.kv { font-size: 13px; }
.kv th {
  text-align: left; font-weight: 400; color: var(--clp-grey-700);
  padding: 6px 14px 6px 0; width: 190px; vertical-align: top;
  text-transform: none; letter-spacing: 0; font-size: 13px; background: none; border: none;
}
.kv td { padding: 6px 0; border: none; vertical-align: top; }

/* ---------- Chips / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  padding: 2px 8px; border-radius: 11px;
  background: var(--clp-grey-100); color: var(--clp-grey-700);
  white-space: nowrap;
}
.chip.blue   { background: var(--clp-blue-100);  color: var(--clp-blue-900); }
.chip.green  { background: var(--clp-green-100); color: var(--clp-green-700); }
.chip.amber  { background: var(--clp-amber-100); color: var(--clp-amber); }
.chip.red    { background: var(--clp-red-100);   color: var(--clp-red); }
.chip.teal   { background: var(--clp-teal-100);  color: var(--clp-teal); }
.chip.solid-blue { background: var(--clp-blue); color: #fff; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.phase-tag {
  font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase;
  border: 1px solid var(--clp-grey-300); color: var(--clp-grey-700);
  border-radius: 2px; padding: 1px 5px;
}
.phase-tag.p1 { border-color: var(--clp-teal); color: var(--clp-teal); }
.phase-tag.p2 { border-color: var(--clp-blue-300); color: var(--clp-blue); }

/* ---------- Filter bar ---------- */
.filterbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--clp-white);
  border: 1px solid var(--clp-grey-150);
  border-radius: var(--radius-lg);
  padding: 10px 12px; margin-bottom: 14px;
}
.filterbar select, .filterbar input {
  font-family: inherit; font-size: 13px;
  border: 1px solid var(--clp-grey-300); border-radius: var(--radius);
  padding: 6px 9px; background: #fff; color: var(--clp-ink);
}
.filterbar input { min-width: 230px; }
.filterbar select:focus, .filterbar input:focus, textarea:focus {
  outline: 2px solid var(--clp-blue-100); outline-offset: 0; border-color: var(--clp-blue-300);
}
.filterbar .fb-label { font-size: 12px; color: var(--clp-grey-700); }

/* ---------- Workflow stepper ---------- */
.stepper { display: flex; overflow-x: auto; gap: 0; padding: 2px; }
.step {
  position: relative;
  flex: 1 0 auto; min-width: 118px;
  padding: 9px 12px 9px 22px;
  background: var(--clp-grey-100);
  color: var(--clp-grey-700);
  font-size: 12px;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%, 12px 50%);
  margin-right: 2px;
}
.step:first-child { clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%); padding-left: 14px; }
.step:last-child  { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 12px 50%); }
.step .s-name { font-weight: 500; display: block; color: inherit; }
.step .s-note { font-size: 11px; opacity: .85; }
.step.done    { background: var(--clp-green-100); color: var(--clp-green-700); }
.step.current { background: var(--clp-blue); color: #fff; }
.step.blocked { background: var(--clp-amber-100); color: var(--clp-amber); }

/* ---------- Agent cards ---------- */
.agent-card {
  background: #fff; border: 1px solid var(--clp-grey-150);
  border-radius: var(--radius-lg); padding: 13px 14px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer; box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.agent-card:hover { border-color: var(--clp-blue-300); box-shadow: var(--shadow-2); }
.agent-card .a-top { display: flex; align-items: center; gap: 9px; }
.agent-num {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: var(--radius);
  background: var(--clp-blue); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.agent-card.is-p1 .agent-num { background: var(--clp-teal); }
.agent-card.na { opacity: .5; }
.agent-card .a-name { font-weight: 500; font-size: 13.5px; }
.agent-card .a-area { font-size: 11.5px; color: var(--clp-grey-700); }
.agent-card .a-purpose {
  font-size: 12.5px; color: var(--clp-grey-700);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.agent-card .a-foot { display: flex; align-items: center; gap: 6px; margin-top: auto; }

/* ---------- Confidence meter ---------- */
.conf { display: flex; align-items: center; gap: 8px; }
.conf-track { flex: 1; height: 6px; border-radius: 3px; background: var(--clp-grey-150); overflow: hidden; min-width: 70px; }
.conf-fill { height: 100%; background: var(--clp-green); border-radius: 3px; }
.conf-fill.med { background: var(--clp-amber); }
.conf-fill.low { background: var(--clp-red); }
.conf-val { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--clp-grey-700); min-width: 34px; }

/* ---------- Notices ---------- */
.notice {
  border-left: 3px solid var(--clp-blue);
  background: var(--clp-blue-50);
  padding: 10px 14px; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px; margin-bottom: 12px;
}
.notice.warn   { border-left-color: var(--clp-amber); background: var(--clp-amber-100); }
.notice.danger { border-left-color: var(--clp-red);   background: var(--clp-red-100); }
.notice.ok     { border-left-color: var(--clp-green); background: var(--clp-green-50); }
.notice strong { font-weight: 500; }

/* ---------- Human-in-the-loop banner ---------- */
.hitl {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--clp-amber-100);
  border: 1px solid #EBD3A6;
  border-radius: var(--radius-lg);
  padding: 11px 14px; font-size: 12.5px; color: #6E4300;
  margin-bottom: 14px;
}
.hitl .h-ico { font-weight: 700; }

/* ---------- Lineage / traceability ---------- */
.lineage { font-size: 12.5px; }
.lineage li { margin-bottom: 5px; }
.lineage .src { color: var(--clp-blue); }
.trace-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--clp-grey-150); font-size: 12.5px; }
.trace-row:last-child { border-bottom: none; }
.trace-row .t-key { color: var(--clp-grey-700); flex: 0 0 150px; }

/* ---------- Timeline (event log) ---------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 8px; top: 4px; bottom: 4px;
  width: 2px; background: var(--clp-grey-150);
}
.tl-item { position: relative; padding: 0 0 16px; }
.tl-item::before {
  content: ""; position: absolute; left: -22px; top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--clp-white); border: 2px solid var(--clp-blue);
}
.tl-item.ai::before    { border-color: var(--clp-teal); }
.tl-item.human::before { border-color: var(--clp-green); }
.tl-item.alert::before { border-color: var(--clp-amber); }
.tl-date { font-size: 11.5px; color: var(--clp-grey-700); }
.tl-title { font-weight: 500; font-size: 13.5px; }
.tl-body { font-size: 12.5px; color: var(--clp-grey-700); }

/* ---------- Map workspace ---------- */
.map-wrap {
  position: relative; background: #EEF1EC;
  border: 1px solid var(--clp-grey-150); border-radius: var(--radius);
  overflow: hidden;
}
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-legend {
  display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 14px;
  border-top: 1px solid var(--clp-grey-150); background: var(--clp-grey-50);
  font-size: 12px;
}
.lg { display: flex; align-items: center; gap: 6px; }
.lg i { width: 18px; height: 0; border-top-width: 3px; border-top-style: solid; display: inline-block; }
.lg i.dash { border-top-style: dashed; }
.lg b { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.layer-toggle { display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.layer-toggle label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.route-opt {
  border: 1px solid var(--clp-grey-150); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer; font-size: 12.5px;
}
.route-opt:hover { border-color: var(--clp-blue-300); background: var(--clp-blue-50); }
.route-opt.selected { border-color: var(--clp-green); background: var(--clp-green-50); }
.route-opt .r-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.route-opt .r-name { font-weight: 500; font-size: 13px; }

/* ---------- Drawing workspace ---------- */
.dwg-wrap {
  background: #fff; border: 1px solid var(--clp-grey-150); border-radius: var(--radius);
  overflow: auto;
}
.dwg-wrap svg { display: block; width: 100%; height: auto; background: #fff; }
.dwg-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--clp-grey-150); margin-bottom: 0; }
.dwg-tab {
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  border: 1px solid transparent; border-bottom: none; color: var(--clp-grey-700);
  border-radius: var(--radius) var(--radius) 0 0;
}
.dwg-tab:hover { background: var(--clp-blue-50); color: var(--clp-blue); }
.dwg-tab.active {
  background: #fff; border-color: var(--clp-grey-150);
  color: var(--clp-blue); font-weight: 500;
  margin-bottom: -1px; border-bottom: 1px solid #fff;
}

/* ---------- Correspondence ---------- */
.letter {
  background: #fff; border: 1px solid var(--clp-grey-150);
  padding: 26px 30px; font-size: 13px; line-height: 1.65;
  border-radius: var(--radius); max-width: 780px;
}
.letter .l-head { border-bottom: 2px solid var(--clp-blue); padding-bottom: 10px; margin-bottom: 18px; }
.letter .l-head .l-org { color: var(--clp-blue); font-weight: 700; letter-spacing: .1em; font-size: 16px; }
.letter .l-head .l-unit { font-size: 11.5px; color: var(--clp-grey-700); }
.letter .l-meta { font-size: 12px; color: var(--clp-grey-700); margin-bottom: 14px; }
.letter .l-sig { margin-top: 22px; }
.flag-inline {
  background: var(--clp-amber-100); border-bottom: 2px solid var(--clp-amber);
  padding: 0 2px; cursor: help;
}

/* ---------- Scheme builder ---------- */
.sc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--clp-grey-150); font-size: 13px;
}
.sc-item:last-child { border-bottom: none; }
.sc-item .s-ico { width: 20px; text-align: center; }
.sc-item .s-name { font-weight: 500; }
.sc-item .s-meta { font-size: 11.5px; color: var(--clp-grey-700); }
.sc-item .s-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.progress-track { height: 8px; background: var(--clp-grey-150); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--clp-blue); }
.progress-fill.green { background: var(--clp-green); }

/* ---------- Modal / drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(31,31,31,.42);
  z-index: 80; display: flex; justify-content: flex-end;
}
.drawer {
  width: min(860px, 94vw); background: var(--clp-grey-50);
  height: 100%; overflow-y: auto; box-shadow: -4px 0 24px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
}
.drawer-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--clp-white); border-bottom: 1px solid var(--clp-grey-150);
  padding: 14px 18px; display: flex; align-items: flex-start; gap: 12px;
}
.drawer-head h2 { font-size: 16px; font-weight: 500; }
.drawer-head .d-sub { font-size: 12.5px; color: var(--clp-grey-700); margin-top: 2px; }
.drawer-body { padding: 16px 18px 40px; }
.x-close {
  margin-left: auto; border: none; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--clp-grey-700); padding: 2px 6px;
}
.x-close:hover { color: var(--clp-ink); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(31,31,31,.42);
  z-index: 90; display: grid; place-items: center; padding: 24px;
}
.modal {
  background: #fff; border-radius: var(--radius-lg); width: min(620px, 100%);
  max-height: 88vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.24);
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--clp-grey-150); display: flex; align-items: center; }
.modal-head h2 { font-size: 15.5px; font-weight: 500; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--clp-grey-150); display: flex; gap: 8px; justify-content: flex-end; background: var(--clp-grey-50); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

label.fld { display: block; margin-bottom: 12px; font-size: 13px; }
label.fld > span { display: block; color: var(--clp-grey-700); margin-bottom: 4px; }
label.fld select, label.fld input, label.fld textarea {
  width: 100%; font-family: inherit; font-size: 13px;
  border: 1px solid var(--clp-grey-300); border-radius: var(--radius); padding: 7px 9px;
  background: #fff; color: var(--clp-ink);
}
label.fld textarea { min-height: 84px; resize: vertical; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--clp-grey-150); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 14px; cursor: pointer; font-size: 13.5px; color: var(--clp-grey-700);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--clp-blue); }
.tab.active { color: var(--clp-blue); border-bottom-color: var(--clp-blue); font-weight: 500; }

/* ---------- Diff view ---------- */
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 12.5px; }
.diff .d-col { border: 1px solid var(--clp-grey-150); border-radius: var(--radius); }
.diff .d-head { padding: 7px 11px; background: var(--clp-grey-50); border-bottom: 1px solid var(--clp-grey-150); font-weight: 500; font-size: 12px; }
.diff .d-body { padding: 11px; }
.diff .d-body .chg { background: var(--clp-amber-100); }
.diff .d-col.new .d-head { background: var(--clp-green-50); color: var(--clp-green-700); }

/* ---------- Misc ---------- */
.muted { color: var(--clp-grey-700); }
.small { font-size: 12px; }
.xsmall { font-size: 11.5px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.strike { text-decoration: line-through; opacity: .6; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.mb0 { margin-bottom: 0; } .mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; }
.flex { display: flex; } .items-center { align-items: center; } .gap8 { gap: 8px; } .gap12 { gap: 12px; }
.wrap { flex-wrap: wrap; }
.divider { height: 1px; background: var(--clp-grey-150); margin: 14px 0; }
.empty { padding: 44px 20px; text-align: center; color: var(--clp-grey-700); font-size: 13px; }

/* ---------- Footer ---------- */
.clp-footer {
  background: var(--clp-blue-900); color: rgba(255,255,255,.72);
  font-size: 11.5px; padding: 11px 24px;
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
}
.clp-footer .f-spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--clp-ink); color: #fff; border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow-2);
  max-width: 400px; border-left: 3px solid var(--clp-green);
  animation: slideIn .18s ease-out;
}
.toast.info { border-left-color: var(--clp-blue-300); }
.toast.warn { border-left-color: var(--clp-amber); }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ---------- Print ---------- */
@media print {
  .rail, .clp-header, .clp-footer, .actions, .btn { display: none !important; }
  .page { padding: 0; }
  .card { box-shadow: none; }
}
