/* BooksGrip Fin Planning — Structure Builder
   Calm, professional, self-contained. No external fonts or assets. */

:root {
  --ink: #1c2b33;
  --ink-soft: #47606c;
  --muted: #71858f;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --line: #d9e1e0;
  --accent: #1f5c46;
  --accent-soft: #e3efe9;
  --warn-bg: #fdf3e3;
  --warn-line: #e3b959;
  --warn-ink: #7a5410;
  --danger-bg: #fbeae8;
  --danger-line: #d98a80;
  --danger-ink: #8c2f24;
  --ok-ink: #1f5c46;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(28, 43, 51, 0.08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  font-size: 15px;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; letter-spacing: 0.01em; }
h3 { font-size: 0.95rem; }

.hint { color: var(--ink-soft); font-size: 0.85rem; margin: 0.35rem 0 0.75rem; }

/* ---------- Header ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner {
  max-width: 1440px; margin: 0 auto; padding: 0.9rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.8rem; min-width: 0; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 10px; flex: 0 0 auto;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center;
}
.brand h1 { font-size: 1.25rem; }
.tagline { margin: 0.15rem 0 0; color: var(--ink-soft); font-size: 0.88rem; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.save-status { color: var(--muted); font-size: 0.8rem; margin-right: 0.25rem; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 0.88rem; cursor: pointer;
  border-radius: 8px; padding: 0.5rem 0.85rem; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #18503c; }
.btn-ghost { background: transparent; }
.btn-preset { background: var(--accent-soft); border-color: transparent; font-weight: 600; color: var(--accent); }
.btn-preset:hover { border-color: var(--accent); }

/* ---------- Preset bar ---------- */
.preset-bar {
  max-width: 1440px; margin: 0 auto; padding: 0.85rem 1.25rem 0.25rem;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.preset-label { font-weight: 600; font-size: 0.9rem; }
.preset-buttons { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.preset-note { flex-basis: 100%; margin: 0.15rem 0 0.35rem; color: var(--ink-soft); font-size: 0.85rem; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1440px; margin: 0 auto; padding: 0.75rem 1.25rem 1.5rem;
  display: grid; grid-template-columns: 250px minmax(0, 1fr) 360px; gap: 1rem; align-items: start;
}

/* ---------- Palette ---------- */
.palette, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem; box-shadow: var(--shadow);
}
.palette-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.palette-item {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); cursor: grab; font: inherit; font-size: 0.88rem; color: var(--ink);
}
.palette-item:hover { border-color: var(--accent); }
.palette-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.palette-item.on-board { opacity: 0.45; cursor: pointer; }
.palette-item .badge { margin-left: auto; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.piece-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; background: var(--accent); }
.piece-dot.trust { background: #6a5aa8; }
.piece-dot.entity { background: #1f5c46; }
.piece-dot.tax { background: #b07d2b; }
.piece-dot.safety { background: #2b6cb0; }
.piece-dot.giving { background: #a85a7d; }
.piece-dot.docs { background: #5a7d8c; }

/* ---------- Board / layers ---------- */
.board { display: flex; flex-direction: column; gap: 0.7rem; min-width: 0; }
.layer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 0.8rem 0.8rem; box-shadow: var(--shadow);
}
.layer.foundation { background: #eef4f1; border-style: dashed; }
.layer-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.layer-head h2 { font-size: 0.92rem; text-transform: uppercase; letter-spacing: 0.05em; }
.layer-head .layer-sub { color: var(--muted); font-size: 0.8rem; }
.layer-drop {
  margin-top: 0.55rem; min-height: 56px; border-radius: 8px;
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-content: flex-start;
  padding: 0.45rem; border: 1px dashed transparent;
}
.layer-drop:empty::after {
  content: "Drop pieces here — or tap a piece in the palette.";
  color: var(--muted); font-size: 0.82rem; padding: 0.35rem;
}
.layer.drag-over .layer-drop { border-color: var(--accent); background: var(--accent-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: 0.38rem 0.5rem 0.38rem 0.7rem;
  font-size: 0.86rem; font-weight: 600; cursor: pointer; max-width: 100%;
}
.chip:hover { background: #d5e7dd; }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.selected { background: var(--accent); color: #fff; }
.chip .chip-remove {
  border: none; background: rgba(28,43,51,0.12); color: inherit; cursor: pointer;
  width: 20px; height: 20px; border-radius: 50%; font-size: 0.8rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.chip .chip-remove:hover { background: rgba(28,43,51,0.25); }

/* ---------- Funding row ---------- */
.funding-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.8rem; box-shadow: var(--shadow); }
.funding-toggle { display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer; font-size: 0.88rem; color: var(--ink-soft); }
.funding-toggle input { width: 18px; height: 18px; margin-top: 0.15rem; accent-color: var(--accent); flex: 0 0 auto; }
.funding-toggle strong { color: var(--ink); }

/* ---------- Panel ---------- */
.panel h2 { margin-bottom: 0.2rem; }
.panel-section { margin-top: 0.9rem; }
.panel-section h3 { margin-bottom: 0.3rem; color: var(--ink); }
.panel-section ul { margin: 0; padding-left: 1.1rem; }
.panel-section li { margin: 0.2rem 0; font-size: 0.9rem; }
.panel-section p { margin: 0.25rem 0; font-size: 0.9rem; }
.piece-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.close-panel { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; font: inherit; font-size: 0.8rem; padding: 0.3rem 0.6rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.7rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.lens { border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.65rem; margin-top: 0.5rem; }
.lens h4 { margin: 0 0 0.2rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.lens.judge h4 { color: var(--danger-ink); }
.lens p { margin: 0; font-size: 0.88rem; }

.score-list { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.4rem; }
.score-row { display: grid; grid-template-columns: 128px 1fr 34px; align-items: center; gap: 0.6rem; font-size: 0.86rem; }
.score-bar { height: 8px; border-radius: 999px; background: #e6ecea; overflow: hidden; }
.score-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }
.score-fill.low { background: #c0564a; }
.score-fill.mid { background: #d9a441; }
.score-val { font-weight: 700; text-align: right; }

.cost-box { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
.cost-box p { margin: 0.25rem 0 0; font-size: 0.9rem; }

.warning-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.warning {
  border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--warn-ink);
  border-radius: 8px; padding: 0.6rem 0.7rem; font-size: 0.87rem;
}
.warning.danger { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger-ink); }
.warning strong { display: block; margin-bottom: 0.15rem; }
.warning .attack { font-style: italic; }
.warning .fix { display: block; margin-top: 0.3rem; font-style: normal; }
.no-warnings { border: 1px solid var(--line); background: var(--accent-soft); color: var(--ok-ink); border-radius: 8px; padding: 0.6rem 0.7rem; font-size: 0.87rem; }

/* ---------- Finalise ---------- */
.finalise { background: var(--surface); border-top: 2px solid var(--accent); }
.finalise-inner { max-width: 1100px; margin: 0 auto; padding: 1.1rem 1.25rem 1.6rem; }
.finalise-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.finalise-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.checklist-body { margin-top: 0.6rem; }
.checklist-body h3 { margin: 1rem 0 0.35rem; }
.checklist-body ul { margin: 0; padding-left: 1.15rem; }
.checklist-body li { margin: 0.22rem 0; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); }
.site-footer p { max-width: 1440px; margin: 0 auto; padding: 0.9rem 1.25rem 1.4rem; color: var(--muted); font-size: 0.8rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 210px minmax(0, 1fr); }
  .panel { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0.6rem 0.75rem 1.2rem; }
  .header-inner, .preset-bar { padding-left: 0.75rem; padding-right: 0.75rem; }
  .palette-list { flex-direction: row; flex-wrap: wrap; }
  .palette-item { width: auto; flex: 1 1 46%; }
  .score-row { grid-template-columns: 108px 1fr 30px; }
}
