/* ============================================================
 * PatientFlow Mapper — styles
 * ============================================================ */

:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
  --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

.hidden { display: none !important; }
.grow { flex: 1; }
hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ============ top bar ============ */
#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; white-space: nowrap; }
.brand-name b { color: var(--accent); font-weight: 800; }
.brand-icon { font-size: 20px; }

.wf-title-wrap { display: flex; align-items: center; gap: 8px; min-width: 180px; flex: 1; }
.wf-title {
  font-size: 15px; font-weight: 600; color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
  padding: 4px 8px; background: transparent; width: 100%; max-width: 420px;
  font-family: var(--font);
}
.wf-title:hover { border-color: var(--border); }
.wf-title:focus { border-color: var(--accent); outline: none; background: #fff; }

.scenario-badge {
  background: #fdf4ff; color: #a21caf; border: 1px solid #f0abfc;
  font-size: 10px; font-weight: 800; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.sub-badge {
  background: #f5f3ff; color: #6d28d9; border: 1px solid #c4b5fd;
  font-size: 10px; font-weight: 800; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap; cursor: default;
}

.toolbar { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tb-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px;
  font-family: var(--font); white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.tb-btn:hover { background: var(--accent-soft); border-color: #bfdbfe; }
.tb-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tb-btn.accent { border-color: #d8b4fe; background: #faf5ff; color: #7e22ce; font-weight: 600; }
.tb-btn.accent:hover { background: #f3e8ff; }
.tb-btn.ai { border-color: #fbbf24; background: #fffbeb; color: #92400e; font-weight: 600; }
.tb-btn.ai:hover { background: #fef3c7; }
.tb-btn.cloud { border-color: #7dd3fc; background: #f0f9ff; color: #0369a1; font-weight: 600; }
.tb-btn.cloud:hover { background: #e0f2fe; }
.tb-btn.cloud.attention { border-color: #f97316; background: #fff7ed; color: #c2410c; }

.cloud-note {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 8px;
}

.profile-chip {
  border: 1px solid var(--border); background: var(--bg); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; font-family: var(--font);
  font-weight: 600; color: var(--muted);
}
.profile-chip:hover { border-color: var(--accent); color: var(--accent); }

.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 240px; padding: 6px; z-index: 60;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; font-family: var(--font);
}
.dropdown-menu button:hover { background: var(--accent-soft); }
.dropdown-menu hr { margin: 6px 0; }

/* ============ layout ============ */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

#sidebar {
  width: 258px; min-width: 258px; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.side-section { padding: 12px 12px 8px; border-bottom: 1px solid var(--border); }
.side-section.grow { flex: 1; }
.side-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.side-section h3 .hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.hint { color: var(--muted); font-size: 11px; font-weight: 400; }

.mini-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  width: 22px; height: 22px; cursor: pointer; font-size: 13px; line-height: 1;
  color: var(--muted); margin-left: auto;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }

/* palette */
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pal-item {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  padding: 7px 8px; cursor: pointer; font-size: 12px; font-family: var(--font); color: var(--text);
  transition: border-color .12s, background .12s;
}
.pal-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.pal-icon { font-size: 14px; width: 20px; text-align: center; }
.pal-start { color: #16a34a; } .pal-end { color: #475569; }
.pal-decision { color: #a855f7; } .pal-wait { color: #ea580c; } .pal-process { color: var(--accent); }

/* workbook tree */
.wb-block { margin-bottom: 6px; }
.wb-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px;
  border-radius: 7px; cursor: pointer; font-weight: 700; font-size: 13px;
}
.wb-head:hover, .wb-head.active { background: var(--bg); }
.wb-caret { color: var(--muted); font-size: 10px; }
.wb-rows { margin-left: 10px; border-left: 2px solid var(--border); padding-left: 6px; }
.wf-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px;
  border-radius: 7px; cursor: pointer; font-size: 13px;
}
.wf-row:hover { background: var(--bg); }
.wf-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.wf-row.sub .wf-ico { color: #7e22ce; font-weight: 700; }
.wf-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wf-bn {
  font-size: 10px; font-weight: 800; color: #b45309; background: #fef3c7;
  padding: 1px 6px; border-radius: 999px; white-space: nowrap;
}
.row-menu-btn {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 14px; padding: 0 4px; border-radius: 4px; visibility: hidden;
}
.wf-row:hover .row-menu-btn, .wb-head:hover .row-menu-btn { visibility: visible; }
.row-menu-btn:hover { color: var(--accent); background: #dbeafe; }
.add-wf-btn {
  border: 1px dashed var(--border); background: none; color: var(--muted);
  border-radius: 7px; padding: 5px 8px; margin: 4px 0 2px; cursor: pointer;
  font-size: 12px; font-family: var(--font); width: 100%; text-align: left;
}
.add-wf-btn:hover { border-color: var(--accent); color: var(--accent); }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; padding-bottom: 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ============ canvas ============ */
#canvas-wrap { flex: 1; position: relative; min-width: 0; background: var(--bg); }
#canvas { width: 100%; height: 100%; display: block; outline: none; cursor: grab; touch-action: none; }
#canvas.pan-ready { cursor: grab; }
#canvas.panning { cursor: grabbing; }
#canvas.connect-mode { cursor: crosshair; }

.node { cursor: move; }
.node .port { opacity: 0; transition: opacity .12s; cursor: crosshair; }
.node:hover .port, .node.selected .port { opacity: 1; }
.node.drop-target rect, .node.drop-target polygon { stroke: #16a34a !important; stroke-width: 3 !important; }
.node text { user-select: none; pointer-events: none; }
.edge { cursor: pointer; }
.edge text { user-select: none; }

#minimap {
  position: absolute; right: 14px; bottom: 14px; width: 208px; height: 136px;
  background: rgba(255, 255, 255, .92); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); z-index: 14;
  cursor: pointer; overflow: hidden;
}
#minimap svg { width: 100%; height: 100%; display: block; }

.canvas-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; font-size: 13px;
  padding: 8px 16px; border-radius: 999px; box-shadow: var(--shadow);
  pointer-events: none; z-index: 15;
}

.inline-edit {
  position: fixed; z-index: 80;
  font-family: var(--font); font-size: 13px; font-weight: 600; text-align: center;
  border: 2px solid var(--accent); border-radius: 6px; padding: 4px;
  box-shadow: var(--shadow);
}

/* ============ right panel ============ */
#rightpanel {
  width: 308px; min-width: 308px; background: var(--panel);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
.rp-tabs { display: flex; border-bottom: 1px solid var(--border); }
.rp-tabs button {
  flex: 1; border: none; background: none; padding: 10px 4px; cursor: pointer;
  font-size: 13px; font-family: var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600;
}
.rp-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.rp-body { flex: 1; overflow-y: auto; padding: 14px; }
.rp-body h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 14px 0 8px;
}
.rp-body h4:first-child { margin-top: 0; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px;
  font-size: 13px; font-family: var(--font); color: var(--text); background: #fff;
  font-weight: 400;
}
label input:focus, label select:focus, label textarea:focus { outline: none; border-color: var(--accent); }
label.chk { display: flex; align-items: center; gap: 7px; font-weight: 400; font-size: 13px; color: var(--text); }
label.chk input { width: auto; margin: 0; }
textarea { resize: vertical; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-size: 13px;
  font-family: var(--font); font-weight: 600; margin-top: 4px;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.empty { color: var(--muted); font-size: 13px; line-height: 1.6; }
.fine-print { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin-bottom: 10px; }

/* severity picker */
.sev-picker { display: flex; gap: 6px; margin-bottom: 10px; }
.sev-btn {
  flex: 1; border: 1.6px solid var(--border); background: #fff; border-radius: 7px;
  padding: 7px 0; cursor: pointer; font-weight: 800; font-size: 13px;
  color: var(--sev); font-family: var(--font);
}
.sev-btn.on { background: var(--sev); border-color: var(--sev); color: #fff; }

/* comments */
.comments { max-height: 220px; overflow-y: auto; margin-bottom: 8px; }
.comment { border-left: 3px solid var(--border); padding: 6px 10px; margin-bottom: 8px; font-size: 12.5px; }
.comment-head { color: var(--muted); font-size: 11px; margin-bottom: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.comment-head b { color: var(--text); }
.comment-add textarea { margin-bottom: 6px; width: 100%; border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; font-family: var(--font); font-size: 13px; }

/* issues tab */
.issue-card {
  border: 1px solid var(--border); border-left: 4px solid var(--sev);
  border-radius: 8px; padding: 9px 11px; margin-bottom: 8px; cursor: pointer;
  transition: box-shadow .12s;
}
.issue-card:hover { box-shadow: var(--shadow); }
.issue-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.issue-sev {
  color: #fff; font-weight: 800; font-size: 11px; border-radius: 999px;
  padding: 1px 8px; white-space: nowrap;
}
.issue-meta { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.issue-causes { font-size: 12px; color: var(--text); margin-top: 5px; font-style: italic; }

/* stats tab */
.stat-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.tile {
  border: 1px solid var(--border); border-radius: 9px; padding: 10px;
  display: flex; flex-direction: column; gap: 2px; background: var(--bg);
}
.tile b { font-size: 18px; }
.tile span { font-size: 11px; color: var(--muted); }
.dept-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 11.5px; }
.dept-bar-label { width: 92px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.dept-bar { flex: 1; height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; display: flex; }
.dept-bar .seg { height: 100%; }
.dept-bar-val { width: 52px; text-align: right; color: var(--text); font-weight: 600; flex: none; }
.path-list { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ============ AI drawer ============ */
#ai-drawer {
  position: absolute; right: 0; top: 0; bottom: 0; width: 400px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(15, 23, 42, .1);
  display: flex; flex-direction: column; z-index: 40;
}
#ai-drawer header {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
  background: #fffbeb;
}
#ai-settings { padding: 14px; border-bottom: 1px solid var(--border); background: var(--bg); }
#ai-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.ai-msg .ai-who { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.ai-msg .ai-text {
  font-size: 13px; line-height: 1.55; white-space: pre-wrap;
  border-radius: 10px; padding: 9px 12px;
}
.ai-msg.user .ai-text { background: var(--accent-soft); }
.ai-msg.assistant .ai-text { background: var(--bg); }
#ai-chips { padding: 0 14px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px;
  font-size: 11.5px; padding: 5px 11px; cursor: pointer; color: var(--muted); font-family: var(--font);
}
.chip:hover { border-color: #f59e0b; color: #92400e; background: #fffbeb; }
#ai-drawer footer { padding: 10px 14px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; }
#ai-input {
  flex: 1; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  font-family: var(--font); font-size: 13px; resize: none;
}
#ai-input:focus { outline: none; border-color: #f59e0b; }

/* ============ status bar ============ */
#statusbar {
  display: flex; align-items: center; gap: 18px;
  padding: 5px 14px; font-size: 12px; color: var(--muted);
  background: var(--panel); border-top: 1px solid var(--border);
}

/* ============ modals & toasts ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px; width: 440px; max-width: 96vw; max-height: 88vh; overflow-y: auto;
  position: relative;
}
.modal.wide { width: 760px; }
.modal h2 { font-size: 17px; margin-bottom: 10px; }
.modal h3 { font-size: 13px; margin: 14px 0 6px; }
.modal-close {
  position: absolute; top: 12px; right: 12px; border: none; background: none;
  font-size: 15px; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.action-list button {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; padding: 10px 13px; margin-bottom: 7px; cursor: pointer;
  font-size: 13.5px; font-family: var(--font); font-weight: 600;
}
.action-list button:hover { background: var(--accent-soft); border-color: #bfdbfe; }
.action-list .danger-text { color: var(--danger); }
.action-list .danger-text:hover { background: #fef2f2; border-color: #fecaca; }

.cmp-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.cmp-table th, .cmp-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.cmp-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.delta { font-weight: 700; }
.delta.good { color: #16a34a; }
.delta.bad { color: var(--danger); }
.delta.zero { color: var(--muted); font-weight: 400; }

.diff-list { max-height: 260px; overflow-y: auto; }
.diff { font-size: 12.5px; padding: 6px 10px; border-radius: 7px; margin-bottom: 5px; }
.diff.add { background: #f0fdf4; color: #166534; }
.diff.del { background: #fef2f2; color: #991b1b; }
.diff.mod { background: #fefce8; color: #854d0e; }

.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.help-cols ul { padding-left: 18px; }
.help-cols li { font-size: 12.8px; margin-bottom: 6px; line-height: 1.5; }
.kbd-list { font-size: 12px; color: var(--muted); line-height: 2; }
kbd {
  background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: var(--font);
}

.err-detail {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px;
  padding: 10px; font-size: 11.5px; color: #991b1b;
  white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow-y: auto;
  margin-bottom: 10px; user-select: text;
}

#toast-root { position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1e293b; color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); transition: all .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* narrow screens: collapse side panels behind scroll */
@media (max-width: 1100px) {
  #sidebar { width: 220px; min-width: 220px; }
  #rightpanel { width: 270px; min-width: 270px; }
}
