/* Shared structure for the dashboard engine. Each option sets the tokens and its own look. */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Review strip (not part of the app) */
.review { background: #fff; color: #222; border-bottom: 1px solid #e4e4e4; font: 500 13px/1.4 Inter, system-ui, sans-serif; }
.review .in { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); }
.review a { color: #555; text-decoration: none; padding: 4px 10px; border-radius: 6px; }
.review a.on { background: #0A2240; color: #fff; }
.review .tag { margin-left: auto; background: #FBF0D9; color: #7D6413; padding: 3px 8px; border-radius: 6px; font-weight: 600; }

/* Dashboard bar */
.dash-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: var(--gap); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: var(--pill-radius, 999px); color: var(--muted); font-weight: 600; font-size: 14px; min-height: 38px; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--tab-on-bg, var(--panel)); color: var(--tab-on-text, var(--text)); box-shadow: var(--tab-shadow, none); }
.bar-actions, .edit-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.b-pri, .b-sec, .b-ghost, .b-edit, .b-done { border-radius: var(--btn-radius, 10px); padding: 9px 14px; font-weight: 600; font-size: 14px; min-height: 40px; border: 1px solid transparent; }
.b-pri { background: var(--accent); color: var(--on-accent); }
.b-sec { background: transparent; border-color: var(--line-strong, var(--line)); color: var(--text); }
.b-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.b-edit { background: var(--panel); border-color: var(--line); color: var(--text); }
.b-done { background: var(--text); color: var(--bg); }

.edit-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: var(--gap); border: 1px dashed var(--accent); border-radius: var(--radius); background: var(--edit-bg, transparent); font-size: 14px; color: var(--muted); }
.name-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-bottom: var(--gap); padding: 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.name-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.name-form input { min-height: 40px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); width: min(320px, 70vw); }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.w { grid-column: span 4; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 18px; min-width: 0; position: relative; cursor: pointer; transition: border-color .15s, box-shadow .2s, transform .2s; }
.w:hover { border-color: var(--line-strong, var(--accent)); box-shadow: var(--hover-shadow, none); }
.w.size-s { grid-column: span 3; } .w.size-m { grid-column: span 4; } .w.size-l { grid-column: span 6; } .w.size-xl { grid-column: span 12; }
.w-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.w-head h3 { margin: 0; font: var(--card-title-font, 600 15px/1.25 var(--font)); color: var(--text); }
.w-head small { color: var(--muted); font-size: 12px; }
.open-hint { color: var(--muted); font-size: 14px; opacity: 0; transition: opacity .15s; }
.w:hover .open-hint { opacity: 1; }
.w-tools { display: none; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.editing .w { cursor: grab; border-style: dashed; }
.editing .w-head { flex-wrap: wrap; }
.editing .w-tools { display: flex; order: -1; width: 100%; justify-content: flex-start; padding-bottom: 10px; margin-bottom: 2px; border-bottom: 1px dashed var(--line); }
.editing .w-tools .drag { margin-left: auto; }
.editing .open-hint { display: none; }
.editing .w-body { pointer-events: none; opacity: .85; }
.w-tools .sz, .w-tools .rm { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; font-size: 11px; font-weight: 700; min-width: 30px; height: 30px; padding: 0 6px; color: var(--muted); }
.w-tools .sz.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.w-tools .rm:hover { color: var(--warn); border-color: var(--warn); }
.w-tools .drag { font-size: 18px; color: var(--muted); padding: 0 4px; cursor: grab; }
.ghost { opacity: .35; }
.chosen { box-shadow: 0 12px 30px rgba(0,0,0,.25); }
.empty { text-align: center; padding: 50px 20px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }

/* Widget content */
.kpi { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.kpi b { font: var(--kpi-font, 700 34px/1 var(--font)); letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi b.warn { color: var(--warn); }
.delta { font-size: 12px; font-weight: 600; color: var(--muted); }
.delta.up, .delta.good { color: var(--ok); }
.sub { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.spark { width: 100%; height: 40px; display: block; margin-top: 10px; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark-fill { fill: var(--accent); opacity: .12; }
.spark-dot { fill: var(--accent); }
.decisions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.decisions li { padding: 12px 14px; border-radius: calc(var(--radius) - 4px); background: var(--panel-2); border-left: 3px solid var(--accent); }
.d-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.d-due.hot { color: var(--warn); font-weight: 700; }
.decisions strong { display: block; font-size: 15px; }
.decisions p { margin: 4px 0 10px; font-size: 13px; color: var(--muted); }
.decisions em { font-style: normal; font-weight: 600; color: var(--text); }
.d-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.d-btns button { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 0 8px 8px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td small { display: block; color: var(--muted); font-size: 12px; }
.tbl td b { font-weight: 600; }
.warn { color: var(--warn); font-weight: 700; }
.muted { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.dot.good { background: var(--ok); } .dot.watch { background: var(--caution); } .dot.risk { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 25%, transparent); }
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin: 4px 0 2px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter i.hot { background: var(--warn); }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 6px; }
.bar-col { flex: 1; display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; justify-content: center; }
.bar-pair i { width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; }
.b1 { background: var(--accent); } .b2 { background: var(--accent-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin-bottom: 12px; }
.stack i, .key { display: inline-block; }
.s0 { background: var(--ok); } .s1 { background: var(--accent); } .s2 { background: var(--caution); } .s3 { background: var(--warn); }
.kv { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 13px; }
.kv li { display: flex; justify-content: space-between; }
.key { width: 9px; height: 9px; border-radius: 2px; margin-right: 8px; }
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; font-size: 13px; }
.funnel li { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center; }
.fbar { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.fbar i { display: block; height: 100%; background: var(--accent); }
.funnel b { font-variant-numeric: tabular-nums; font-size: 12px; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.rows li:last-child { border-bottom: 0; }
.rows b { font-weight: 600; display: block; }
.rows small { color: var(--muted); font-size: 12px; }
.rows .r { text-align: right; display: grid; justify-items: end; gap: 3px; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.load { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 13px; }
.load li { display: grid; grid-template-columns: 28px 72px 1fr 24px 54px; gap: 8px; align-items: center; }
.load .meter { margin: 0; height: 8px; }
.ini { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700; background: var(--panel-2); color: var(--text); }
.ini.ai { background: var(--accent); color: var(--on-accent); }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; }
.feed li { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 7px 0 7px 10px; border-left: 2px solid var(--line); }
.feed li.done { border-left-color: var(--ok); } .feed li.ai { border-left-color: var(--accent); } .feed li.alert { border-left-color: var(--warn); }
.feed time { color: var(--muted); font-variant-numeric: tabular-nums; }
.agents { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 13px; }
.agents li { display: grid; grid-template-columns: 12px 1fr; gap: 10px; align-items: start; }
.agents p { margin: 2px 0 0; color: var(--muted); }
.agents small { color: var(--muted); }
.ag-state { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: var(--muted); }
.ag-state.working { background: var(--accent); animation: pulse 1.8s infinite; } .ag-state.ready { background: var(--ok); } .ag-state.waiting { background: var(--caution); }
@keyframes pulse { 50% { opacity: .35; } }
.handoff { display: grid; gap: 8px; }
.handoff input, .handoff select { min-height: 42px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); width: 100%; }
.hrow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }
.handoff .ok { margin: 0; font-size: 13px; color: var(--ok); font-weight: 600; }

/* Drawers */
.library, .detail { position: fixed; inset: 0; background: rgba(5, 12, 24, .45); z-index: 50; display: flex; justify-content: flex-end; }
.library[hidden], .detail[hidden], .toast[hidden] { display: none; }
.lib-in, .det-in { width: min(460px, 100%); height: 100%; overflow-y: auto; background: var(--drawer-bg, var(--panel)); color: var(--text); padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) 24px 22px; box-shadow: -10px 0 40px rgba(0,0,0,.25); }
.lib-in header, .det-in header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.lib-in h3, .det-in h3 { margin: 0; font-size: 20px; }
.det-dept { color: var(--muted); }
.det-body h4 { margin: 18px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.det-body p { color: var(--muted); }
.det-body .w-body, .det-body table { font-size: 14px; }
.x { border: 1px solid var(--line); background: transparent; border-radius: 8px; width: 38px; height: 38px; font-size: 14px; flex: none; }
.lib-list { display: grid; gap: 8px; }
.lib-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.lib-item:hover { border-color: var(--accent); }
.lib-item small { display: block; color: var(--muted); font-size: 12px; }
.lib-state { font-size: 12px; font-weight: 700; color: var(--accent-text, var(--accent)); white-space: nowrap; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 60; }

@media (max-width: 1100px) {
  .w.size-s { grid-column: span 6; } .w.size-m { grid-column: span 6; } .w.size-l, .w.size-xl { grid-column: span 12; }
}
@media (max-width: 640px) {
  .w, .w.size-m, .w.size-l, .w.size-xl { grid-column: span 12; }
  .w.size-s { grid-column: span 12; }
  .grid { grid-template-columns: 1fr; }
  .w { grid-column: 1 / -1 !important; }
  .load li { grid-template-columns: 28px 64px 1fr 20px; }
  .load li .pill { display: none; }
  .hrow { grid-template-columns: 1fr 1fr; } .hrow .b-pri { grid-column: 1 / -1; }
  .tbl th:nth-child(4), .tbl td:nth-child(4) { display: none; }
  .w-tools .sz[data-size="xl"] { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
