/* ============================================================
   Lao Flood RoleMap — Work & Information Flow
   Designed to match the mockup: clean, light surface, navy nav,
   color-coded alert cards, mind-map canvas, side details panel.
   ============================================================ */

:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --line:      #e2e8f0;
  --line-strong:#cbd5e1;
  --text:      #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;
  --primary:   #2563eb;
  --primary-d: #1d4ed8;
  --navy:      #0f2c64;
  --navy-d:    #0a1f4a;

  --alert-green:  #22c55e;
  --alert-yellow: #f59e0b;
  --alert-red:    #ef4444;

  --cat-situation:    #38bdf8;
  --cat-technical:    #22c55e;
  --cat-decision:     #a855f7;
  --cat-operation:    #fbbf24;
  --cat-communication:#3b82f6;
  --cat-community:    #ec4899;

  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow:    0 4px 12px rgba(15,23,42,0.08), 0 2px 4px rgba(15,23,42,0.04);
  --shadow-lg: 0 12px 40px rgba(15,23,42,0.14);
  --radius:    12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  /* Prevent any single overflowing element from forcing the whole page to
     scroll horizontally on mobile (which triggers zoom-out behaviour). */
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%; /* don't auto-inflate text on rotation */
}
.rolemap-body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ======================== TOP NAV ======================== */
.rm-topbar {
  display: grid;
  grid-template-columns: minmax(280px,1fr) auto minmax(280px,1fr);
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-d) 100%);
  color: #fff;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 30;
}
.rm-brand { display: flex; align-items: center; gap: 12px; }
.rm-back {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; text-decoration: none;
  background: rgba(255,255,255,0.08);
  font-size: 18px; line-height: 1;
}
.rm-back:hover { background: rgba(255,255,255,0.16); }
.rm-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.rm-brand-text strong { font-size: 16px; font-weight: 700; }
.rm-brand-text span { font-size: 11px; opacity: 0.7; }

.rm-topnav { display: flex; gap: 4px; justify-content: center; }
.rm-nav-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px;
  background: transparent; color: rgba(255,255,255,0.75); border: none;
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.rm-nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.rm-nav-btn.is-active { background: rgba(255,255,255,0.18); color: #fff; }

.rm-user { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }
.rm-icon-btn {
  position: relative;
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.85);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.rm-icon-btn:hover { background: rgba(255,255,255,0.16); color: #fff; }
.rm-badge {
  position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px;
  background: var(--alert-red); color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.rm-user-info { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.rm-user-info strong { font-size: 13px; }
.rm-user-info span { font-size: 11px; opacity: 0.7; }
.rm-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg,#3b82f6,#8b5cf6);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

/* In the canvas (lighter surface), reuse rm-icon-btn but darker tone */
.rm-canvas .rm-icon-btn {
  background: #f1f5f9; color: var(--text-soft);
}
.rm-canvas .rm-icon-btn:hover { background: #e2e8f0; color: var(--text); }

/* ======================== ALERT BAR ======================== */
.rm-alert-bar {
  display: grid;
  grid-template-columns: 200px 1fr 220px;
  gap: 16px;
  align-items: stretch;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.rm-alert-bar-label {
  font-size: 13px; font-weight: 600; color: var(--text-soft);
  display: flex; align-items: center;
}
.rm-alert-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
}
.rm-alert-card {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  align-items: center;
}
.rm-alert-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.rm-alert-card.is-active { border-width: 2px; box-shadow: var(--shadow); }
.rm-alert-card.lvl-green   { background: #f0fdf4; }
.rm-alert-card.lvl-yellow  { background: #fffbeb; }
.rm-alert-card.lvl-red     { background: #fef2f2; }
.rm-alert-card.is-active.lvl-green   { border-color: var(--alert-green); }
.rm-alert-card.is-active.lvl-yellow  { border-color: var(--alert-yellow); }
.rm-alert-card.is-active.lvl-red     { border-color: var(--alert-red); }
.rm-alert-card.lvl-all { background: linear-gradient(135deg, #f0fdf4 0%, #fffbeb 50%, #fef2f2 100%); }
.rm-alert-card.lvl-all .rm-alert-icon { background: #475569; }
.rm-alert-card.is-active.lvl-all { border-color: #475569; }
.rm-alert-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
}
.rm-alert-card.lvl-green   .rm-alert-icon { background: var(--alert-green); }
.rm-alert-card.lvl-yellow  .rm-alert-icon { background: var(--alert-yellow); }
.rm-alert-card.lvl-red     .rm-alert-icon { background: var(--alert-red); }
.rm-alert-text {}
.rm-alert-text .alert-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-soft); }
.rm-alert-text .alert-name    { font-size: 18px; font-weight: 800; line-height: 1.1; letter-spacing: 0.4px; }
.rm-alert-text .alert-trigger { font-size: 11px; color: var(--text-mute); margin-top: 2px; }

.rm-alert-meta {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  background: var(--surface);
}
.rm-alert-meta div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.rm-alert-meta span { color: var(--text-mute); }
.rm-alert-meta strong { color: var(--text); font-weight: 600; }

/* ======================== MAIN GRID ======================== */
.rm-main {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 0;
  min-height: 0;
}

/* Sidebar */
.rm-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
}
.rm-sidebar-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.rm-sidebar-head h3 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text); }
.rm-link-btn { background: none; border: none; padding: 0; color: var(--primary); font-weight: 600; font-size: 12px; cursor: pointer; }
.rm-link-btn:hover { text-decoration: underline; }

.rm-filter-group { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.rm-filter-group:last-of-type { border-bottom: none; }
.rm-filter-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.rm-check-stack { display: flex; flex-direction: column; gap: 4px; }
.rm-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; cursor: pointer; padding: 4px 0;
  color: var(--text);
}
.rm-check input { accent-color: var(--primary); width: 14px; height: 14px; }
.rm-check .lvl-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rm-check .lvl-dot.green  { background: var(--alert-green); }
.rm-check .lvl-dot.yellow { background: var(--alert-yellow); }
.rm-check .lvl-dot.red    { background: var(--alert-red); }
.rm-check .cat-icon { font-size: 14px; }

.rm-sidebar select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface); font: inherit; font-size: 13px;
  color: var(--text);
}
.rm-sidebar select:focus { outline: 2px solid var(--primary); outline-offset: -2px; }

.rm-apply { margin-top: 12px; }

.rm-btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: none; border-radius: 8px; padding: 10px 14px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.rm-btn:active { transform: translateY(1px); }
.rm-btn-primary { background: var(--primary); color: #fff; width: 100%; }
.rm-btn-primary:hover { background: var(--primary-d); }
.rm-btn-ghost { background: #f1f5f9; color: var(--text); }
.rm-btn-ghost:hover { background: #e2e8f0; }
.rm-btn-danger { background: var(--alert-red); color: #fff; }
.rm-btn-danger:hover { background: #dc2626; }
.rm-btn-notify {
  background: #25D366; color: #fff;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: 0 1px 2px rgba(37,211,102,0.30);
}
.rm-btn-notify:hover { background: #1ebb5a; }
.rm-btn-notify svg { display:block; }
.rm-btn-sm { padding: 6px 10px; font-size: 12px; }

/* ======================== CANVAS ======================== */
.rm-canvas {
  background: var(--surface);
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  border-right: 1px solid var(--line);
}
.rm-canvas-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  gap: 12px; flex-wrap: wrap;
}
.rm-canvas-head h2 { margin: 0; font-size: 16px; font-weight: 700; display: inline; }
.rm-info { color: var(--text-mute); margin-left: 6px; cursor: help; }
.rm-canvas-controls {
  display: flex; align-items: center; gap: 8px;
  /* On narrow screens the controls row would otherwise overflow the viewport
     and force horizontal page scroll. Wrap onto a new line instead. */
  flex-wrap: wrap; min-width: 0;
}

.rm-segmented {
  display: inline-flex; background: #f1f5f9; border-radius: 8px; padding: 2px;
}
.rm-segmented button {
  padding: 6px 12px; border: none; background: transparent; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--text-soft); border-radius: 6px;
}
.rm-segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.rm-groupby { align-items: center; padding-left: 8px; }
.rm-groupby-label {
  font-size: 11px; font-weight: 600; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0 8px 0 4px; white-space: nowrap;
}
.rm-groupby button { padding: 5px 10px; font-size: 11.5px; }

/* Orientation toggle (L→R / T↓D) — same chip style as the group-by toggle */
.rm-orient { align-items: center; padding-left: 8px; }
.rm-orient button {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 9px; font-size: 11.5px;
}
.rm-orient button svg { display: block; }
.rm-orient-label { font-weight: 700; letter-spacing: 0.02em; }

.rm-mindmap-wrap {
  flex: 1; position: relative; min-height: 520px;
  overflow: hidden;
}
.rm-mindmap-wrap.is-table-mode { overflow: auto; }
.rm-mindmap { width: 100%; height: 100%; display: block; cursor: grab; }
.rm-mindmap:active { cursor: grabbing; }
.rm-mindmap[hidden], .rm-table-view[hidden] { display: none !important; }

/* Mind-map nodes */
.mm-link { fill: none; stroke-width: 1.5; opacity: 0.55; pointer-events: none; }
.mm-toggle { pointer-events: all; }
.mm-toggle circle, .mm-toggle line { pointer-events: all; }
.mm-fp-icon { pointer-events: all; }
.mm-fp-icon circle:first-of-type { transition: fill-opacity 120ms ease, stroke-width 120ms ease; }
.mm-fp-icon:hover circle:first-of-type { fill-opacity: 0.4; stroke-width: 2.2; }
.mm-node { cursor: pointer; }
.mm-node-rect {
  fill: var(--surface);
  stroke-width: 1.5;
  rx: 8;
  filter: drop-shadow(0 2px 4px rgba(15,23,42,0.08));
  transition: filter 0.15s;
}
.mm-node:hover .mm-node-rect { filter: drop-shadow(0 4px 8px rgba(15,23,42,0.15)); }
.mm-node.is-selected .mm-node-rect { stroke-width: 2.5; }
.mm-node-label { font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 600; fill: var(--text); pointer-events: none; }
.mm-node-sub   { font-family: 'Inter', sans-serif; font-size: 12px; fill: var(--text-soft); pointer-events: none; }
.mm-center-circle { stroke-width: 4; }
.mm-center-rect { filter: drop-shadow(0 4px 12px rgba(15, 23, 42, 0.08)); }
.mm-center-label { font-family: 'Inter', sans-serif; font-weight: 800; fill: var(--text); pointer-events: none; text-anchor: middle; }

.rm-table-view { padding: 18px; overflow: auto; flex: 1; min-height: 520px; }
.rm-table-view table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rm-table-view th, .rm-table-view td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top;
}
.rm-table-view th { font-weight: 700; color: var(--text-soft); background: #f8fafc; position: sticky; top: 0; }
.rm-table-view tr:hover td { background: #f8fafc; cursor: pointer; }
.rm-table-view tr.is-selected td { background: #eef2ff; }
.rm-table-view .tbl-bullets { margin: 0; padding-left: 16px; font-size: 12px; line-height: 1.45; color: var(--text); }
.rm-table-view .tbl-bullets li { margin-bottom: 3px; }
.rm-table-view .tbl-bullets li:last-child { margin-bottom: 0; }
.rm-table-view .pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.rm-table-view .pill-green  { background: #dcfce7; color: #15803d; }
.rm-table-view .pill-yellow { background: #fef3c7; color: #b45309; }
.rm-table-view .pill-red    { background: #fee2e2; color: #b91c1c; }

/* ======================== DETAILS PANEL ======================== */
.rm-details {
  background: var(--surface);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 60px);
  overflow: hidden;
}
.rm-details-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.rm-details-head h3 { margin: 0; font-size: 14px; font-weight: 700; }
.rm-details-head .rm-icon-btn { background: #f1f5f9; color: var(--text-soft); width: 28px; height: 28px; font-size: 18px; }
.rm-details-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.rm-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 40px 20px; text-align: center; color: var(--text-mute);
}
.rm-empty p { margin: 0; font-size: 13px; line-height: 1.5; }

.detail-card { padding: 14px; background: #f8fafc; border-radius: 10px; margin-bottom: 14px; }
.detail-title-row { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.detail-icon-pill {
  width: 40px; height: 40px; border-radius: 10px; display: inline-flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.detail-title h4 { margin: 0 0 4px 0; font-size: 14px; font-weight: 700; line-height: 1.3; }
.detail-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.3px; text-transform: uppercase;
}
.detail-pill.lvl-green  { background: #dcfce7; color: #15803d; }
.detail-pill.lvl-yellow { background: #fef3c7; color: #b45309; }
.detail-pill.lvl-red    { background: #fee2e2; color: #b91c1c; }

.detail-section { margin-bottom: 14px; }
.detail-section-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--text-mute); margin-bottom: 6px;
}
.detail-section-body { font-size: 13px; line-height: 1.5; color: var(--text); }
.detail-bullets { font-size: 13px; line-height: 1.5; color: var(--text); margin: 4px 0 0 0; padding-left: 18px; }
.detail-bullets li { margin-bottom: 6px; }
.detail-bullets li:last-child { margin-bottom: 0; }

.agency-card {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.agency-logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg,#dbeafe,#bfdbfe);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; color: #1e40af; font-size: 12px; flex-shrink: 0;
}
.agency-card strong { display: block; font-size: 13px; font-weight: 700; }
.agency-card span { font-size: 11px; color: var(--text-soft); }

.fp-card {
  display: flex; gap: 12px; padding: 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); margin-bottom: 8px;
}
.fp-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg,#fde68a,#fbbf24);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; color: #78350f; font-size: 12px; flex-shrink: 0;
}
.fp-info { flex: 1; min-width: 0; }
.fp-name { font-size: 13px; font-weight: 700; }
.fp-pos  { font-size: 11px; color: var(--text-soft); margin-bottom: 6px; }
.fp-row  { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); margin-bottom: 2px; word-break: break-word; }
.fp-row svg { color: var(--text-mute); flex-shrink: 0; }

.responsibilities-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.responsibilities-list li { font-size: 12.5px; display: flex; gap: 6px; align-items: flex-start; }
.responsibilities-list li::before {
  content: '✓'; color: var(--alert-green); font-weight: 800; flex-shrink: 0;
}

.detail-actions {
  display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--line);
}
.detail-actions .rm-btn { flex: 1; min-width: 100px; }

.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: #fef3c7; color: #b45309;
}
.status-chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ======================== FOOTER (TIMELINE + QUICK) ======================== */
.rm-footer {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.rm-timeline { padding: 14px 24px; border-right: 1px solid var(--line); }
.rm-timeline h4 { margin: 0 0 10px 0; font-size: 13px; font-weight: 700; }
.rm-timeline-track {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
  position: relative; align-items: start;
}
.rm-timeline-track::before {
  content: ''; position: absolute; top: 18px; left: 16%; right: 16%; height: 2px;
  background: repeating-linear-gradient(to right, var(--line-strong) 0, var(--line-strong) 4px, transparent 4px, transparent 10px);
  z-index: 0;
}
.rm-tl-step {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0 8px; cursor: pointer;
  text-align: center;
}
.rm-tl-dot {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--line); color: var(--text-mute);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.rm-tl-step:hover .rm-tl-dot { transform: scale(1.06); }
.rm-tl-step.is-active .rm-tl-dot { background: currentColor; color: #fff; border-color: currentColor; transform: scale(1.08); }
.rm-tl-step.lvl-green  { color: var(--alert-green); }
.rm-tl-step.lvl-yellow { color: var(--alert-yellow); }
.rm-tl-step.lvl-red    { color: var(--alert-red); }
.rm-tl-step strong { color: var(--text); font-size: 12.5px; font-weight: 700; }
.rm-tl-step span   { color: var(--text-soft); font-size: 11px; line-height: 1.3; max-width: 180px; }

.rm-quick { padding: 14px 24px; }
.rm-quick h4 { margin: 0 0 10px 0; font-size: 13px; font-weight: 700; }
.rm-quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rm-quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer; font: inherit;
  font-size: 11px; font-weight: 600; color: var(--text-soft);
  position: relative;
}
.rm-quick-btn:hover { background: #f8fafc; color: var(--text); border-color: var(--line-strong); }
.rm-quick-btn svg { color: var(--text-soft); }

/* ======================== TOAST ======================== */
.rm-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 16px;
  border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-lg);
  z-index: 100; max-width: 380px;
}
.rm-toast.is-error { background: var(--alert-red); }
.rm-toast.is-ok    { background: #16a34a; }

/* ======================== MODAL ======================== */
.rm-modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.rm-modal-backdrop[hidden] { display: none; }
.rm-toast[hidden] { display: none; }
.rm-modal {
  background: var(--surface); border-radius: 14px;
  width: min(560px, 100%); max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.rm-modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.rm-modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.rm-modal-head .rm-icon-btn { background: #f1f5f9; color: var(--text-soft); width: 32px; height: 32px; font-size: 22px; }
.rm-modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.rm-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line); background: #f8fafc;
}

.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  height: 38px;                /* lock a single row height so date/select/text align across columns */
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; line-height: 1.2; color: var(--text); background: var(--surface);
  -webkit-appearance: none; appearance: none;
  text-align: left;
}
/* iOS Safari renders <input type="date"> with extra internal chrome and
   centers the value. Reset both so it matches sibling fields exactly. */
.form-row input[type="date"],
.form-row input[type="time"],
.form-row input[type="datetime-local"] {
  min-height: 38px; line-height: 22px;
}
.form-row input[type="date"]::-webkit-date-and-time-value { text-align: left; }
/* Restore the native dropdown arrow on <select> after appearance:none. */
.form-row select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%2364748b' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -2px; border-color: var(--primary);
}
.form-row textarea { height: auto; min-height: 70px; resize: vertical; line-height: 1.5; }
.form-row .rm-check { padding: 4px 0; font-weight: 400; color: var(--text); }
.form-row .rm-check input { margin: 0; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-help { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.form-error { font-size: 11px; color: var(--alert-red); margin-top: 2px; }
.form-multi-select {
  border: 1px solid var(--line); border-radius: 6px; padding: 8px;
  max-height: 140px; overflow-y: auto; overflow-x: hidden; background: var(--surface);
  box-sizing: border-box; width: 100%;
}
.form-multi-select label {
  display: flex; align-items: flex-start; gap: 8px; padding: 4px 2px;
  font-weight: 400; color: var(--text); font-size: 12.5px; line-height: 1.35;
  min-width: 0; cursor: pointer;
}
.form-multi-select input { flex-shrink: 0; flex-grow: 0; margin: 2px 0 0; accent-color: var(--primary); width: 16px; height: 16px; }
.form-multi-select .fms-text {
  flex: 1 1 auto; min-width: 0;
  white-space: normal; overflow-wrap: break-word; word-break: normal;
  color: var(--text); font-size: 12.5px; line-height: 1.35;
}
.form-multi-select .fms-text strong { font-weight: 600; color: var(--text); }

/* ======================== RESPONSIVE ======================== */
@media (max-width: 1180px) {
  .rm-main { grid-template-columns: 220px 1fr 280px; }
  .rm-alert-bar { grid-template-columns: 160px 1fr 200px; }
}
@media (max-width: 980px) {
  .rm-topbar { grid-template-columns: 1fr; gap: 10px; padding: 10px 14px; }
  .rm-topnav { justify-content: flex-start; flex-wrap: wrap; }
  .rm-user { justify-content: flex-start; }
  .rm-alert-bar { grid-template-columns: 1fr; }
  .rm-alert-cards { grid-template-columns: 1fr; }
  .rm-alert-card.lvl-all { grid-column: 1 / -1; }
  .rm-main { grid-template-columns: 1fr; }
  .rm-sidebar, .rm-details { max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  .rm-footer { grid-template-columns: 1fr; }
  .rm-timeline { border-right: none; border-bottom: 1px solid var(--line); }
}
@media (max-width: 600px) {
  .rm-canvas-head { flex-direction: column; align-items: flex-start; }
  .rm-canvas-controls { width: 100%; gap: 6px; }
  /* Compact the controls so common combinations (toggle + group-by + zoom) fit. */
  .rm-canvas-controls .rm-segmented button { padding: 5px 9px; font-size: 11.5px; }
  .rm-groupby button { padding: 4px 8px; font-size: 11px; }
  .rm-groupby-label { font-size: 10px; padding: 0 4px 0 2px; }
  .rm-orient button { padding: 4px 7px; font-size: 11px; gap: 3px; }
  .rm-orient-label { font-size: 10px; }
  .rm-canvas .rm-icon-btn { width: 28px; height: 28px; }
  /* Allow the "+ Add Role" button to keep its label on one line. */
  #rmAddRole { white-space: nowrap; }
  .rm-quick-actions { grid-template-columns: repeat(2, 1fr); }
  /* Keep the mind-map SVG from forcing horizontal page scroll on small screens. */
  .rm-mindmap-wrap { overflow-x: hidden; }
  .rm-mindmap { max-width: 100%; }
}

/* ============================================================
   NOTIFY FOCAL PERSONS — MODAL
   ============================================================ */
.rm-notify-modal { max-width: 720px; width: calc(100vw - 32px); }
.rm-notify-modal .rm-modal-body { padding: 0; }
.rm-notify-section { padding: 14px 20px; border-bottom: 1px solid var(--line); }
.rm-notify-section:last-child { border-bottom: 0; }
.rm-notify-label {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-soft);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px;
}
.rm-notify-hint { font-weight: 400; color: var(--text-mute); text-transform: none; letter-spacing: 0; }

/* Alert level picker */
.rm-notify-alerts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rm-notify-alert {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: pointer; text-align: left;
  transition: all 0.15s ease;
}
.rm-notify-alert:hover { border-color: var(--text-mute); }
.rm-notify-alert .rm-notify-alert-name { font-size: 14px; font-weight: 600; color: var(--text); }
.rm-notify-alert .rm-notify-alert-short { font-size: 11px; color: var(--text-mute); }
.rm-notify-alert.is-active.lvl-green  { border-color: #22c55e; background: rgba(34,197,94,0.08); }
.rm-notify-alert.is-active.lvl-yellow { border-color: #f59e0b; background: rgba(245,158,11,0.08); }
.rm-notify-alert.is-active.lvl-red    { border-color: #ef4444; background: rgba(239,68,68,0.08); }

/* Recipients list */
.rm-notify-empty { padding: 16px; text-align: center; color: var(--text-mute); font-size: 13px; background: #f8fafc; border-radius: 6px; }
.rm-notify-recipients {
  border: 1px solid var(--line); border-radius: 8px;
  max-height: 220px; overflow-y: auto; overflow-x: hidden; background: var(--surface);
}
.rm-notify-recipient {
  display: flex; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  cursor: pointer; min-width: 0;
}
.rm-notify-recipient:last-child { border-bottom: 0; }
.rm-notify-recipient:hover { background: #f8fafc; }
.rm-notify-recipient input { flex-shrink: 0; margin-top: 4px; accent-color: var(--primary); width: 16px; height: 16px; }
.rm-notify-recipient-info { flex: 1 1 auto; min-width: 0; }
.rm-notify-recipient-name { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.rm-notify-recipient-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11.5px; color: var(--text-mute); }
.rm-notify-recipient-meta em { font-style: italic; color: var(--alert-red); }
.rm-notify-recipient.is-disabled { opacity: 0.55; cursor: not-allowed; }
.rm-notify-pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 600; margin-left: 6px; vertical-align: middle; }
.rm-notify-pill-warn { background: rgba(245,158,11,0.15); color: #b45309; }

/* Message preview block */
.rm-notify-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; color: var(--text);
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; margin: 0;
  white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow-y: auto;
}

/* Options panel */
.rm-notify-options { display: flex; flex-direction: column; gap: 10px; }
.rm-notify-toggle {
  display: flex; gap: 10px; padding: 10px 12px;
  background: rgba(245,158,11,0.08); border: 1px solid rgba(245,158,11,0.25); border-radius: 8px;
  cursor: pointer; align-items: flex-start;
}
.rm-notify-toggle input { flex-shrink: 0; margin-top: 2px; accent-color: var(--primary); width: 16px; height: 16px; }
.rm-notify-toggle span { font-size: 12.5px; line-height: 1.45; color: var(--text); }
.rm-notify-field { display: flex; flex-direction: column; gap: 4px; }
.rm-notify-field > span { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.rm-notify-field input {
  width: 100%; height: 38px; box-sizing: border-box;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; font-size: 13px; color: var(--text); background: var(--surface);
  -webkit-appearance: none; appearance: none;
}
.rm-notify-field input:focus { outline: 2px solid var(--primary); outline-offset: -2px; border-color: var(--primary); }

/* Confirmation step */
.rm-notify-confirm { padding: 24px 20px; text-align: center; }
.rm-notify-confirm-icon {
  width: 64px; height: 64px; margin: 0 auto 12px;
  background: rgba(37,211,102,0.12); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.rm-notify-confirm h3 { margin: 0 0 8px; font-size: 18px; color: var(--text); }
.rm-notify-confirm p { margin: 0 0 10px; font-size: 13.5px; color: var(--text-soft); }
.rm-notify-testmode-note { padding: 10px 14px; background: rgba(245,158,11,0.10); border-radius: 6px; color: #b45309; }
.rm-notify-live-note    { padding: 10px 14px; background: rgba(239,68,68,0.10); border-radius: 6px; color: var(--alert-red); }
.rm-notify-confirm-list { list-style: none; padding: 0; margin: 12px 0 0; text-align: left; max-height: 200px; overflow-y: auto; }
.rm-notify-confirm-list li { padding: 6px 10px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.rm-notify-confirm-list li:last-child { border-bottom: 0; }

/* Sending spinner */
.rm-notify-sending { padding: 60px 20px; text-align: center; color: var(--text-soft); }
.rm-notify-sending p { margin-top: 14px; font-size: 13px; }
.rm-spinner {
  width: 36px; height: 36px; margin: 0 auto;
  border: 3px solid #e2e8f0; border-top-color: #25D366;
  border-radius: 50%; animation: rmSpin 0.9s linear infinite;
}
@keyframes rmSpin { to { transform: rotate(360deg); } }

/* Results step */
.rm-notify-results { padding: 18px 20px; }
.rm-notify-results-summary { display: flex; gap: 12px; margin-bottom: 16px; }
.rm-stat {
  flex: 1 1 0; padding: 12px; border-radius: 8px; text-align: center;
  background: #f8fafc; border: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; flex-direction: column; gap: 4px;
}
.rm-stat span { font-size: 24px; font-weight: 700; color: var(--text); }
.rm-stat.ok span   { color: #22c55e; }
.rm-stat.fail span { color: var(--alert-red); }
.rm-stat.skip span { color: #f59e0b; }
.rm-notify-error {
  padding: 10px 14px; background: rgba(239,68,68,0.10);
  border-radius: 6px; color: var(--alert-red); font-size: 13px; margin: 0 0 12px;
}
.rm-notify-results-list { list-style: none; padding: 0; margin: 0; max-height: 240px; overflow-y: auto; }
.rm-notify-results-list li {
  display: grid; grid-template-columns: 1fr auto;
  gap: 6px 12px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); font-size: 12.5px;
}
.rm-notify-results-list li:last-child { border-bottom: 0; }
.rm-notify-result-name { font-weight: 600; }
.rm-notify-result-status { font-weight: 600; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.04em; }
.rm-notify-result-sent .rm-notify-result-status   { color: #22c55e; }
.rm-notify-result-failed .rm-notify-result-status { color: var(--alert-red); }
.rm-notify-result-skipped .rm-notify-result-status { color: #f59e0b; }
.rm-notify-result-detail { grid-column: 1 / -1; color: var(--text-mute); font-size: 11.5px; }

/* Footer with two buttons side by side */
.rm-notify-modal .rm-modal-foot { display: flex; gap: 10px; justify-content: flex-end; }

/* Mobile tweaks */
@media (max-width: 600px) {
  .rm-notify-modal { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .rm-notify-alerts { grid-template-columns: 1fr; }
  .rm-notify-section { padding: 12px 14px; }
  .rm-notify-preview { font-size: 11.5px; }
  .rm-notify-modal .rm-modal-foot { padding: 12px 14px; }
}
