/* Money Monkey GUI v2 (spec-driven). No framework, CSS variables + theme presets. */
:root {
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,0.12);
  --shadow-sm: 0 4px 12px rgba(0,0,0,0.10);
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

/* Theme presets: applied via <html data-mm-theme="..."> */
html[data-mm-theme="day"] {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(17,24,39,0.12);
  --accent: #2563eb;
  --accent-2: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
}

html[data-mm-theme="night"] {
  --bg: #0b1220;
  --surface: #0f1a2e;
  --surface-2: #0c1526;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(229,231,235,0.14);
  --accent: #60a5fa;
  --accent-2: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
}

html[data-mm-theme="midnight"] {
  --bg: #070a12;
  --surface: #0b0f1c;
  --surface-2: #090c16;
  --text: #e5e7eb;
  --muted: #9aa4b2;
  --border: rgba(229,231,235,0.12);
  --accent: #a78bfa;
  --accent-2: #22c55e;
  --danger: #fb7185;
  --warn: #f59e0b;
}

html[data-mm-theme="dusk"] {
  --bg: #111827;
  --surface: #151f35;
  --surface-2: #0f172a;
  --text: #f3f4f6;
  --muted: #a1a1aa;
  --border: rgba(243,244,246,0.12);
  --accent: #f59e0b;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
}

html[data-mm-theme="minimum"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --text: #111111;
  --muted: #444444;
  --border: rgba(0,0,0,0.14);
  --accent: #111111;
  --accent-2: #111111;
  --danger: #111111;
  --warn: #111111;
}

/* Extra schemes (helpful, optional) */
html[data-mm-theme="forest"] {
  --bg: #071a12;
  --surface: #0a2218;
  --surface-2: #081c14;
  --text: #e7f6ef;
  --muted: #9cc7b3;
  --border: rgba(231,246,239,0.14);
  --accent: #22c55e;
  --accent-2: #84cc16;
  --danger: #fb7185;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

.mm-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 60px 1fr;
  min-height: 100vh;
}

.mm-topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.mm-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
}
.mm-brand img {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}
.mm-brand .mm-title {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.mm-brand .mm-title strong { font-size: 14px; letter-spacing: 0.3px; }
.mm-brand .mm-title span { font-size: 12px; color: var(--muted); }

.mm-chiprow {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mm-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.mm-chip b { font-weight: 700; font-size: 12px; }

.mm-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mm-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 80ms ease, opacity 120ms ease;
}
.mm-btn:hover { transform: translateY(-1px); }
.mm-btn:active { transform: translateY(0px); }
.mm-btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

.mm-btn--danger { border-color: rgba(220,38,38,0.35); background: rgba(220,38,38,0.14); }
.mm-btn--primary { border-color: rgba(37,99,235,0.35); background: rgba(37,99,235,0.14); }

.mm-sidebar {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 12px;
}

.mm-navgroup-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 10px 8px;
}

.mm-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mm-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--text);
}
.mm-nav a:hover { background: var(--surface-2); }
.mm-nav a.mm-active {
  background: rgba(37,99,235,0.14);
  border-color: rgba(37,99,235,0.22);
}

.mm-main {
  grid-column: 2;
  grid-row: 2;
  padding: 18px 18px 30px;
  position: relative;
  overflow-x: hidden;
}

.mm-pagehead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.mm-pagehead h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.2px;
}

.mm-subtle {
  color: var(--muted);
  font-size: 13px;
}

.mm-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}

.mm-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  min-height: 64px;
}
.mm-card h2 {
  margin: 0 0 8px;
  font-size: 14px;
}
.mm-card p { margin: 0; color: var(--muted); font-size: 13px; }
.mm-card .mm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.mm-hr { height: 1px; background: var(--border); margin: 10px 0; }

.mm-kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  font-size: 13px;
}
.mm-kv div:nth-child(odd) { color: var(--muted); }

.mm-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mm-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mm-badge {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
}


/* Banner */
.mm-banner {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px 12px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.mm-banner__msg { font-size: 13px; }
.mm-banner[data-level="danger"] { border-color: rgba(220,38,38,0.35); background: rgba(220,38,38,0.10); }
.mm-banner[data-level="warn"] { border-color: rgba(217,119,6,0.35); background: rgba(217,119,6,0.10); }

/* Now Doing */
.mm-nowdoing { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.mm-nowdoing__main { font-size: 15px; font-weight: 700; }

/* Activity tape */
.mm-tape { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.mm-tape-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.mm-tape-left { display: flex; gap: 10px; align-items: flex-start; }
.mm-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-top: 4px;
  background: var(--muted);
}
.mm-dot--info { background: var(--accent); }
.mm-dot--warn { background: var(--warn); }
.mm-dot--danger { background: var(--danger); }

.mm-tape-text { display: flex; flex-direction: column; gap: 2px; }
.mm-tape-text strong { font-size: 13px; }
.mm-tape-text .mm-subtle { font-size: 12px; }
.mm-tape-meta { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.mm-tape-time { font-size: 12px; color: var(--muted); white-space: nowrap; }


/* Context drawer */
.mm-drawer {
  position: fixed;
  top: 60px;
  right: -420px;
  width: 420px;
  height: calc(100vh - 60px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px;
  transition: right 140ms ease;
  z-index: 50;
}
.mm-drawer.mm-open { right: 0; }
.mm-drawer h3 { margin: 0 0 10px; font-size: 15px; }
.mm-drawer .mm-subtle { margin-bottom: 10px; }


/* Drawer: What / Why / What next */
.mm-drawer-wwn { display: flex; flex-direction: column; gap: 14px; }
.mm-wwn-section { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(255,255,255,0.02); }
.mm-wwn-h { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; color: var(--muted); }
.mm-wwn-b { font-size: 13px; line-height: 1.35; }
.mm-wwn-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.mm-adv { margin-top: 10px; }
.mm-adv summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.mm-adv-body { margin-top: 8px; font-size: 13px; color: var(--text); }

.mm-drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.mm-highlight {
  outline: 2px solid rgba(37,99,235,0.5);
  box-shadow: 0 0 0 6px rgba(37,99,235,0.12);
}

/* Modal */
.mm-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.46);
  display: none;
  z-index: 60;
}
.mm-modal-backdrop.mm-open { display: block; }
.mm-modal {
  position: fixed;
  top: 18%; left: 50%;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: none;
  z-index: 61;
}
.mm-modal.mm-open { display: block; }
.mm-modal h3 { margin: 0 0 8px; font-size: 16px; }
.mm-modal p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.mm-modal .mm-actions { justify-content: flex-end; }

/* Toast */
.mm-toastwrap {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 70;
}
.mm-toast {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.mm-toast strong { font-size: 13px; }
.mm-toast .mm-subtle { font-size: 12px; }
.mm-toast button { border: none; background: transparent; color: var(--muted); cursor: pointer; }

/* Responsive */
@media (max-width: 980px) {
  .mm-shell { grid-template-columns: 1fr; }
  .mm-sidebar { display: none; }
  .mm-brand { min-width: 0; }
  .mm-drawer { width: min(420px, calc(100vw - 16px)); }
}


/* ---- Dashboard (TAB 1) ---- */
.mm-kpi-grid{
  display:grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
@media (max-width: 1200px){
  .mm-kpi-grid{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px){
  .mm-kpi-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.mm-kpi-card{
  display:block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform 120ms ease, border-color 120ms ease;
}
.mm-kpi-card:hover{
  transform: translateY(-1px);
  border-color: rgba(255,255,255,0.22);
}
.mm-kpi-title{
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.mm-kpi-value{
  font-size: 22px;
  font-weight: 700;
  margin-top: 6px;
}
.mm-kpi-sub{
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.mm-engine-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 980px){
  .mm-engine-grid{ grid-template-columns: 1fr; }
}

.mm-engine-tile{
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.mm-engine-title{
  font-size: 14px;
  font-weight: 700;
}
.mm-engine-allowed{
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}
.mm-engine-allowed.mm-bad{
  color: var(--warn);
}
.mm-engine-allowed.mm-danger{
  color: var(--danger);
}

.mm-engine-actions{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}
.mm-engine-secondary{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mm-pill{
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.10);
  color: var(--muted);
  white-space: nowrap;
}

.mm-strip{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 980px){
  .mm-strip{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mm-strip-item{
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.mm-strip-k{
  font-size: 12px;
  color: var(--muted);
}
.mm-strip-v{
  font-size: 14px;
  font-weight: 700;
  margin-top: 4px;
}
.mm-strip-item.mm-attn{
  border-color: rgba(255,255,255,0.22);
}
.mm-strip-item.mm-danger{
  border-color: var(--danger);
}

.mm-empty-card{
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: rgba(0,0,0,0.08);
}
.mm-hide{ display:none !important; }

.mm-btn--ghost{
  background: transparent;
  border: 1px solid var(--border);
}

.mm-btn.mm-working{
  opacity: 0.85;
}
.mm-btn.mm-success{
  border-color: var(--accent-2);
}
.mm-btn.mm-fail{
  border-color: var(--danger);
}

.mm-link{
  color: var(--accent);
  text-decoration: none;
}
.mm-link:hover{
  text-decoration: underline;
}


/* --- Live Activity filters --- */
.mm-filterbar{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:flex-end;
}
.mm-filter{display:flex; flex-direction:column; gap:6px; min-width:140px;}
.mm-filter--actions{margin-left:auto; min-width:auto;}
.mm-label{font-size:12px; opacity:0.85;}
.mm-select{
  padding:8px 10px;
  border-radius:10px;
  border:1px solid var(--mm-border);
  background:var(--mm-card);
  color:var(--mm-text);
}
.mm-badge--soft{
  background: rgba(127,127,127,0.10);
  border: 1px solid rgba(127,127,127,0.20);
}
.mm-cat{
  display:inline-flex;
  align-items:center;
  padding:2px 8px;
  border-radius:999px;
  font-size:12px;
  border:1px solid rgba(127,127,127,0.18);
  background: rgba(127,127,127,0.08);
  margin-left:8px;
}
.mm-tape-text strong{display:flex; align-items:center; gap:8px;}


/* Banner actions (Chunk 1F) */
.mm-banner__actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }


/* Forms (Chunk 1F — Credentials) */
.mm-form { display: flex; flex-direction: column; gap: 10px; }
.mm-label { font-size: 12px; color: var(--muted); }
.mm-input, .mm-textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 10px;
  font-size: 13px;
  outline: none;
}
.mm-textarea { resize: vertical; min-height: 76px; }
.mm-input:disabled, .mm-textarea:disabled { opacity: 0.6; cursor: not-allowed; }
.mm-form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mm-checkbox { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); }
.mm-callout {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
}
.mm-callout[data-level="warn"] { border-color: rgba(217,119,6,0.35); background: rgba(217,119,6,0.10); }
.mm-callout[data-level="danger"] { border-color: rgba(220,38,38,0.35); background: rgba(220,38,38,0.10); }
.mm-callout[data-level="success"] { border-color: rgba(22,163,74,0.35); background: rgba(22,163,74,0.10); }
.mm-small { font-size: 12px; color: var(--muted); }
.mm-details { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); }
.mm-details summary { cursor: pointer; color: var(--text); font-weight: 600; }



/* Keyboard focus ring (accessibility): visible only for keyboard nav. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* Keyboard-only focus polish for pill/chip controls (keeps grandma-safe clarity). */
.mm-pill:focus-visible,
.mm-chip:focus-visible,
button.mm-pill:focus-visible,
a.mm-pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
}


/* Table focus polish (keyboard-only): row context without fighting the deep-link highlight. */
.mm-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
}

.mm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.mm-table thead th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.mm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.mm-table tbody tr:hover td {
  background: var(--surface-2);
}

.mm-table tbody tr:focus-within td {
  background: var(--surface-2);
}

/* When a row is deep-link highlighted, use a clean left-rail instead of an extra outline ring. */
.mm-table tr.mm-highlight {
  outline: none;
  box-shadow: none;
}

.mm-table tbody tr.mm-highlight td {
  background: var(--surface-2);
}

.mm-table tbody tr.mm-highlight td:first-child {
  box-shadow: inset 4px 0 0 var(--accent);
}

/* Ensure “View” buttons stay legible inside a highlighted row. */
.mm-table tr.mm-highlight button:focus-visible,
.mm-table tr.mm-highlight a:focus-visible {
  outline-offset: 3px;
}
/* Scorecards viewer: client-side sort + pin (operator-safe). */
.mm-sort-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
}
.mm-sort-btn:hover {
  background: var(--surface-2);
}
.mm-sort-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mm-pin-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.mm-pin-btn:hover {
  background: var(--surface-2);
}
.mm-pin-btn.mm-pin--on {
  color: var(--text);
  box-shadow: inset 0 0 0 999px rgba(0,0,0,0.02);
}


/* Runbook: guided checklists (operator-safe) */
.mm-runbook-details {
  display: block;
}
.mm-runbook-details > summary {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mm-runbook-details > summary::-webkit-details-marker {
  display: none;
}
.mm-runbook-details > summary::after {
  content: "▸";
  font-size: 12px;
  color: var(--muted);
}
.mm-runbook-details[open] > summary::after {
  content: "▾";
}
.mm-runbook-steps {
  margin: 10px 0 0 18px;
  padding: 0;
}
.mm-runbook-steps li {
  margin: 6px 0;
}
.mm-codebox {
  margin: 8px 0 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
}

