/* cpr-tokens.css — design tokens + shared web components (§8.1) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, Arial, sans-serif; font-size: 14px; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}

:root {
  --navy: #1E4480; --blue: #2A6AB0; --primary: #005EFF; --primary-light: #E6EFFF;
  --text: #2D2E31; --bg: #F3F4F7; --card: #FFFFFF; --border: #E2E4E9;
  --success: #3EB645; --warning: #F59E0B; --high: #F97316; --critical: #E90229; --info: #005EFF; --neutral: #8A8F98;
  --active-bg: #4F73F6; --active-shadow: 0 6px 14px rgba(0,94,255,.24); --hover-bg: #F8F8F9;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- Layout shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; overflow-y: auto;
}
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.sidebar-logo { width: 32px; height: 32px; border-radius: 8px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.sidebar-brand { font-size: 16px; font-weight: 700; color: var(--navy); }
.sidebar-menu { list-style: none; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; flex-grow: 1; }
.sidebar-menu a { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; border-radius: 6px; color: var(--text); font-size: 14px; font-weight: 500; transition: background .15s, color .15s; }
.sidebar-menu a svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; }
.sidebar-menu a:hover { background: var(--hover-bg); color: var(--navy); }
.sidebar-menu a.active { background: var(--active-bg); color: #fff; box-shadow: var(--active-shadow); }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-hmi-link { display: flex; align-items: center; justify-content: center; gap: 8px; height: 40px; border-radius: 6px; background: var(--primary-light); color: var(--primary); font-weight: 600; font-size: 13px; }
.sidebar-menu a.nav-disabled { color: var(--neutral); cursor: default; opacity: .55; }
.sidebar-menu a.nav-disabled:hover { background: none; color: var(--neutral); }
.sidebar-menu a.nav-disabled span:first-of-type { flex-grow: 1; }
.soon-tag { font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--border); color: var(--neutral); border-radius: 4px; padding: 2px 5px; flex-shrink: 0; }

.pager { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--neutral); }
.pager-btns { display: flex; align-items: center; gap: 10px; }
.pager-btn { border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; }
.pager-btn:hover:not(:disabled) { background: var(--hover-bg); }
.pager-btn:disabled { opacity: .4; cursor: default; }
.pager-current { font-weight: 600; color: var(--text); }

.main-area { margin-left: 248px; flex-grow: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 56px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 90; gap: 16px; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--navy); white-space: nowrap; }
.topbar-mid { display: flex; align-items: center; gap: 12px; flex-grow: 1; }
.plant-select, .search-input { height: 34px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; font-size: 13px; background: var(--bg); color: var(--text); }
.search-input { flex-grow: 1; max-width: 340px; }
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); background: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.bell-btn { position: relative; width: 34px; height: 34px; border-radius: 50%; border: none; background: transparent; display: flex; align-items: center; justify-content: center; color: var(--neutral); }
.bell-btn:hover { background: var(--hover-bg); }
.bell-badge { position: absolute; top: 2px; right: 2px; background: var(--critical); color: #fff; font-size: 9px; font-weight: 700; width: 15px; height: 15px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 6px; position: relative; }
.user-chip:hover { background: var(--hover-bg); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.user-meta .u-name { font-size: 13px; font-weight: 600; }
.user-meta .u-role { font-size: 11px; color: var(--neutral); }
.role-switch-menu { display: none; position: absolute; top: 46px; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.1); min-width: 220px; padding: 6px; z-index: 200; }
.role-switch-menu.open { display: block; }
.role-switch-menu .rs-item { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.role-switch-menu .rs-item:hover { background: var(--hover-bg); }
.role-switch-menu .rs-item .rs-role { font-size: 11px; color: var(--neutral); }
.role-switch-menu .rs-divider { height: 1px; background: var(--border); margin: 6px 2px; }
.btn-open-hmi { height: 34px; padding: 0 14px; border-radius: 6px; background: var(--primary); color: #fff; font-weight: 600; font-size: 13px; border: none; display: flex; align-items: center; gap: 6px; }

.content { padding: 24px; max-width: 1600px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-title { font-size: 24px; font-weight: 700; }
.page-sub { font-size: 13px; color: var(--neutral); margin-top: 2px; }

/* ---------------- Cards, KPIs, tables ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.card-pad { padding: 16px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-title-row h3 { font-size: 15px; font-weight: 600; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 1200px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; cursor: pointer; transition: box-shadow .15s; }
.kpi-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--neutral); margin-top: 4px; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* Search/filter row used at the top of list pages (events, monitoring, closed) —
   wraps the search input + button in a card-like bar so it doesn't sit bare on
   the page background and its controls line up on a shared height. */
.search-bar-row { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.search-bar-row .search-input { height: 36px; background: #fff; }
.search-bar-row .btn { height: 36px; }

table.cpr-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cpr-table thead th { text-align: left; font-weight: 600; color: var(--neutral); font-size: 11px; text-transform: uppercase; letter-spacing: .3px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg); }
table.cpr-table tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); height: 40px; vertical-align: middle; }
table.cpr-table tbody tr:hover { background: var(--hover-bg); cursor: pointer; }
.table-wrap { overflow-x: auto; }
.empty-row td { text-align: center; color: var(--neutral); padding: 24px; }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-neutral { background: #EEF0F3; color: var(--neutral); }
.badge-neutral-dark { background: #DADEE5; color: #4A4E57; }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-success { background: #E7F8EA; color: var(--success); }
.badge-success-outline { background: #fff; color: var(--success); border: 1px solid var(--success); }
.badge-warning { background: #FEF3E0; color: #B9700A; }
.badge-high { background: #FFEBDF; color: #C2540C; }
.badge-critical { background: #FDE3E7; color: var(--critical); }

.risk-LOW { background: #E7F8EA; color: var(--success); }
.risk-MEDIUM { background: #FEF3E0; color: #B9700A; }
.risk-HIGH { background: #FFEBDF; color: #C2540C; }
.risk-CRITICAL { background: #FDE3E7; color: var(--critical); }

.gate-NONE { background: #EEF0F3; color: var(--neutral); }
.gate-WARNING { background: #FEF3E0; color: #B9700A; }
.gate-ACK_REQUIRED { background: #FFEBDF; color: #C2540C; }
.gate-HOLD { background: #FDE3E7; color: var(--critical); }

/* ---------------- Buttons ---------------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 6px; font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #0048C4; }
.btn-outline { background: #fff; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--hover-bg); }
.btn-danger { background: #fff; border-color: var(--critical); color: var(--critical); }
.btn-danger:hover { background: #FDE3E7; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }

/* ---------------- Alert banner ---------------- */
.alert-banner { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border-radius: 8px; border: 1px solid; }
.alert-critical { background: #FDE3E7; border-color: #F7B7C2; color: #8A0016; }
.alert-info { background: var(--primary-light); border-color: #BBD4FF; color: var(--navy); }
.alert-banner .alert-title { font-weight: 700; font-size: 13px; }
.alert-banner .alert-body { font-size: 12px; margin-top: 2px; }

/* ---------------- Drawer / modal ---------------- */
.overlay { position: fixed; inset: 0; background: rgba(20,22,28,.4); z-index: 500; display: none; }
.overlay.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 92vw; background: var(--card); z-index: 501; box-shadow: -8px 0 24px rgba(0,0,0,.12); transform: translateX(100%); transition: transform .25s ease; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 16px; font-weight: 700; }
.drawer-close { width: 28px; height: 28px; border-radius: 50%; border: none; background: var(--bg); font-size: 16px; }
.drawer-body { padding: 16px; overflow-y: auto; flex-grow: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer-footer { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 480px; max-width: 92vw; background: var(--card); border-radius: 10px; z-index: 502; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: none; max-height: 86vh; overflow-y: auto; }
.modal.open { display: block; }
.modal.modal-wide { width: 720px; }
.modal-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal-footer:empty, .drawer-footer:empty { padding: 0; border-top: none; }

/* ---------------- Wizard stepper ---------------- */
.wizard-steps { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.wizard-step { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; color: var(--neutral); padding: 4px 8px; border-radius: 999px; }
.wizard-step .ws-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; }
.wizard-step.current { color: var(--primary); background: var(--primary-light); }
.wizard-step.current .ws-dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.wizard-step.done .ws-dot { background: var(--success); border-color: var(--success); color: #fff; }
.wizard-body { min-height: 220px; }
.item-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.item-card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.impact-row { display: grid; grid-template-columns: 22px 1fr 90px 1fr; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12px; }
.impact-row:last-child { border-bottom: none; }
.stale-banner { background: #FFF3E0; border: 1px solid var(--warning); color: #8a5a00; border-radius: 8px; padding: 10px 12px; font-size: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------------- Sticky flow-map button (global, all pages) ---------------- */
.sticky-fab { position: fixed; right: 22px; bottom: 22px; width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 24px rgba(0,94,255,.35); z-index: 550; text-decoration: none; transition: transform .15s ease; }
.sticky-fab:hover { transform: scale(1.06); background: #0048C4; }
/* Demo Script FAB (P7) stacks directly above the Flow Map FAB — same size/style, different
   accent color so the two are visually distinct at a glance. */
.sticky-fab-script { bottom: 86px; background: #7C3AED; box-shadow: 0 10px 24px rgba(124,58,237,.35); border: none; cursor: pointer; }
.sticky-fab-script:hover { background: #6425D0; }

/* Flow Map (flows.html) is a standalone true-multi-lane swimlane portal page
   (v2, Tahap "flows redesign") with its own page-local <style> block, matching
   the reusable pattern from the MEU project's flows.html — see D-16/D-18 in
   CPR-DEMO-STATUS.md. The old single-row expandable-card CSS this replaced
   (.flow-search/.flow-card/.role-pill/.swimlane-*) has been removed here.  */

.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 600; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 260px; max-width: 360px; padding: 12px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; box-shadow: 0 6px 18px rgba(0,0,0,.15); color: #fff; }
.toast-success { background: var(--success); }
.toast-error { background: var(--critical); }
.toast-info { background: var(--navy); }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text); }
.field .req { color: var(--critical); }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=datetime-local], .field textarea, .field select {
  height: 36px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
.field textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
.field .help { font-size: 11px; color: var(--neutral); }
.bool-toggle { display: flex; gap: 8px; }
.bool-toggle button { flex: 1; height: 40px; border-radius: 6px; border: 1px solid var(--border); background: #fff; font-weight: 600; font-size: 13px; color: var(--text); }
.bool-toggle button.selected-yes { background: #E7F8EA; border-color: var(--success); color: var(--success); }
.bool-toggle button.selected-no { background: #FDE3E7; border-color: var(--critical); color: var(--critical); }
.sticky-actions { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--border); padding: 12px 16px; display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- Why popover ---------------- */
.why-btn { background: none; border: 1px solid var(--border); border-radius: 999px; font-size: 11px; padding: 2px 10px; color: var(--primary); font-weight: 600; }
.why-popover { position: absolute; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 26px rgba(0,0,0,.14); padding: 12px; width: 320px; z-index: 700; font-size: 12px; }
.why-popover .why-line { padding: 5px 0; border-bottom: 1px dashed var(--border); }
.why-popover .why-line:last-child { border-bottom: none; }
.why-chip { display: inline-block; background: var(--primary-light); color: var(--primary); border-radius: 4px; padding: 1px 6px; font-size: 10px; font-weight: 700; margin-right: 4px; }

/* ---------------- Tabs ---------------- */
.tabs-bar { display: flex; gap: 4px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab-btn {
  appearance: none; -webkit-appearance: none; background: none; border: none; border-radius: 0;
  padding: 13px 14px 11px; margin-bottom: -1px; font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--neutral); border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer;
  outline: none; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn:focus-visible { box-shadow: 0 0 0 2px var(--primary-light); border-radius: 4px; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.help-chip { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; background: var(--bg); color: var(--neutral); font-size: 10px; font-weight: 700; border: 1px solid var(--border); cursor: help; }
.info-i { color: var(--neutral); font-size: 11px; cursor: help; }

.readiness-list { display: flex; flex-direction: column; gap: 6px; }
.readiness-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.readiness-item .rc-ok { color: var(--success); }
.readiness-item .rc-bad { color: var(--critical); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 600; }

.muted { color: var(--neutral); }
.mono { font-variant-numeric: tabular-nums; }
