html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1d1d1f; background: #fff;
  -webkit-font-smoothing: antialiased;
}
#app { padding: 8px; position: relative; }

/* always-visible Configure button (top-right) */
#cfgBtn {
  position: absolute; top: 6px; right: 8px; z-index: 6;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: inherit; font-size: 12px; font-weight: 500; color: #1d1d1f;
  background: #fff; border: 1px solid #d2d2d7; border-radius: 980px;
  padding: 5px 13px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
#cfgBtn:hover { background: #f5f5f7; border-color: #c5c5cb; }
#cfgBtn:active { background: #ececf0; }

#status { font-size: 12px; color: #6e6e73; padding: 6px 4px; }
#status.error { color: #d70015; }
.hint { font-size: 12px; color: #86868b; }
.pad { padding: 16px; }
a, a:visited { color: #0071e3; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== rendered table ===== */
.mh-wrap { overflow-x: auto; }
.mh-title { font-size: 15px; font-weight: 700; padding: 4px 2px 8px; color: #1d1d1f; }
table.mh-table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.mh-table th, table.mh-table td { border: 1px solid #bcbcbc; padding: 6px 10px; text-align: center; }
table.mh-table thead th { background: #f3f3f3; font-weight: 600; }
table.mh-table th.mh-corner { vertical-align: middle; background: #ececec; }
table.mh-table th.mh-group { background: #e8eef7; }
table.mh-table td.mh-rowhead { text-align: left; font-weight: 600; background: #fafafa; }
tr.mh-total td { font-weight: 700; }
tr.mh-total-bottom td { border-top: 2px solid #8aa1c4; }
tr.mh-total-top td { border-bottom: 2px solid #8aa1c4; }
td.mh-total-label { text-align: left; }
/* keep the grand-total row pinned while the table scrolls */
table.mh-table tfoot td { position: sticky; bottom: 0; z-index: 2; }
table.mh-table tr.mh-total-top td { position: sticky; top: 0; z-index: 2; }

/* ===== Apple-style configuration UI ===== */
#configPanel {
  background: #f5f5f7; padding: 18px; border-radius: 14px;
  max-height: 100%; overflow: auto; color: #1d1d1f;
}
.cfg-title-bar { margin-bottom: 14px; }
.cfg-title-h { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }

.cfg-section {
  background: #fff; border-radius: 16px; padding: 16px 18px; margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.03);
}
.cfg-section h3 { margin: 0 0 14px; font-size: 13px; font-weight: 600; color: #1d1d1f; letter-spacing: -0.01em; }
.cfg-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 6px; }

/* labelled control */
.fld { display: inline-flex; flex-direction: column; gap: 5px; margin: 0 14px 10px 0; vertical-align: top; }
.fld-l { font-size: 11px; color: #6e6e73; font-weight: 500; }
.fmt-grid { display: flex; flex-wrap: wrap; align-items: flex-end; }

/* inputs / selects */
.ipt {
  font-family: inherit; font-size: 13px; padding: 7px 10px;
  border: 1px solid #d2d2d7; border-radius: 8px; background: #fff; color: #1d1d1f;
  outline: none; box-sizing: border-box; height: 34px;
}
.ipt:focus { border-color: #0071e3; box-shadow: 0 0 0 3px rgba(0,113,227,.15); }
.ipt:disabled { background: #f5f5f7; color: #aeaeb2; }
.w60 { width: 60px } .w70 { width: 74px } .w90 { width: 96px }
.w110 { width: 110px } .w130 { width: 150px } .w200 { width: 200px }
.grow { flex: 1; min-width: 160px; }

/* colour swatches */
input[type=color], .swatch {
  -webkit-appearance: none; appearance: none;
  width: 40px; height: 30px; padding: 2px;
  border: 1px solid #d2d2d7; border-radius: 8px; background: #fff; cursor: pointer;
}

/* iOS-style toggle */
.switch { position: relative; display: inline-block; width: 42px; height: 25px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #e9e9ea; border-radius: 25px; transition: .2s; }
.switch .slider:before {
  content: ""; position: absolute; height: 21px; width: 21px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: #34c759; }
.switch input:checked + .slider:before { transform: translateX(17px); }

/* row fields */
.rowfields { display: flex; flex-direction: column; gap: 8px; }
.rf-row { display: flex; align-items: center; gap: 12px; }
.rf-name { min-width: 150px; font-size: 13px; font-weight: 500; }

/* categories & measures */
.tag {
  display: inline-block; min-width: 64px; text-align: center;
  font-size: 11px; font-weight: 600; color: #0071e3; background: #eaf3fe;
  border-radius: 6px; padding: 5px 8px;
}
.group-block { border: 1px solid #e5e5ea; border-radius: 14px; padding: 14px; margin: 10px 0; background: #fdfdfd; }
.group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.measure-block { border: 1px solid #e5e5ea; border-radius: 12px; padding: 12px; margin: 8px 0; background: #fff; }
.m-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.subcard { background: #f9f9fb; border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.subcard-h { font-size: 11px; font-weight: 600; color: #6e6e73; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .03em; }

/* conditional colour rule builder */
.colorspec { background: #fff; border: 1px solid #ececf0; border-radius: 10px; padding: 10px 12px; margin: 6px 0; }
.cs-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.cs-rules { display: flex; flex-direction: column; gap: 6px; }
.rule-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cs-else-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* buttons */
button { font-family: inherit; cursor: pointer; }
button.primary { background: #0071e3; color: #fff; border: none; border-radius: 980px; padding: 9px 22px; font-size: 13px; font-weight: 500; }
button.primary:hover { background: #0077ed; }
button.secondary { background: #e8e8ed; color: #1d1d1f; border: none; border-radius: 980px; padding: 8px 16px; font-size: 13px; font-weight: 500; }
button.secondary:hover { background: #dcdce1; }
button.small { padding: 5px 12px; font-size: 12px; }

.cfg-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px;
  position: sticky; bottom: 0; padding: 12px 0 4px;
  background: rgba(245,245,247,.92); backdrop-filter: saturate(180%) blur(8px);
}
.cfg-error { color: #d70015; font-size: 12px; margin: 6px 2px; display: none; }
