/* ==========================================================================
   Harbour Care Centre - Fee Calculator
   --------------------------------------------------------------------------
   1. Branding tokens   <-- edit this block to re-brand the whole app
   2. Base
   3. Layout
   4. Header / Footer
   5. Form controls
   6. Segmented toggle
   7. Buttons
   8. Result
   9. Responsive
  10. Modal
  11. Pro-forma invoice (print only)
  12. Print
   ========================================================================== */

/* ==========================================================================
   1. BRANDING TOKENS
   Every colour, radius and font in the app resolves to one of these.
   Change a value here and it propagates everywhere - no other edits needed.
   ========================================================================== */
:root {
  /* Primary - deep red, sampled from the Harbour Care Centre logo (#CA2021) */
  --brand-red:          #CA2021;
  --brand-red-dark:     #96181A;   /* hover / pressed / headings */
  --brand-red-darker:   #6E1113;   /* the headline total */
  --brand-red-tint:     #FBEDEC;   /* soft red wash for fills */

  /* Secondary - complementary beige / gold */
  --brand-gold:         #B08A46;
  --brand-gold-dark:    #8A6A32;
  --brand-beige:        #F0E4CE;
  --brand-beige-soft:   #FAF3E6;

  /* Neutrals */
  --surface:            #FFFFFF;
  --surface-muted:      #FCFAF7;   /* off-white page background */
  --ink:                #23201E;
  --ink-muted:          #6B635C;
  --line:               #E4DCD1;

  /* Feedback */
  --error:              #B3261E;

  /* Typography */
  --font-body:    "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --font-figures: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;

  /* Shape & depth */
  --radius:       12px;
  --radius-sm:     8px;
  --shadow:       0 1px 2px rgba(35, 32, 30, .05), 0 8px 24px rgba(35, 32, 30, .06);
  --shadow-lift:  0 2px 4px rgba(110, 17, 19, .10), 0 12px 32px rgba(110, 17, 19, .12);

  /* Rhythm */
  --shell-max: 62rem;
  --gap:       1.25rem;
}

/* ==========================================================================
   2. BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface-muted);
}

h1, h2, p, dl, dd { margin: 0; }

:focus-visible {
  outline: 3px solid var(--brand-gold);
  outline-offset: 2px;
}

/* Announced by screen readers, invisible on screen */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   3. LAYOUT
   ========================================================================== */
.shell {
  width: 100%;
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

main.shell { padding-block: 2rem 3rem; }

.calculator {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  /* Row 1 sizes to the total card and row 2 absorbs the slack. Without the
     1fr, the taller left-hand card inflates both rows and the total drifts
     away from the buttons beneath it. */
  grid-template-rows: auto 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* The inputs run down the left; the total and the actions stack on the right.
   Both gaps between them are the grid's own 1.5rem, so the spacing matches
   every other card boundary in the layout. */
.calculator > .panel:not(.actions-card) { grid-column: 1; grid-row: 1 / span 2; }
.calculator > .result                   { grid-column: 2; grid-row: 1; }
.calculator > .actions-card             { grid-column: 2; grid-row: 2; }

/* ==========================================================================
   4. HEADER / FOOTER
   ========================================================================== */
.site-header {
  background: var(--surface);
  border-bottom: 3px solid var(--brand-red);
}

/* Logo hard left, page title hard right */
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1rem;
}

.site-header__logo {
  width: auto;
  height: 120px;
  max-width: 45%;
  object-fit: contain;
  flex: none;
}

.site-header__title {
  font-size: clamp(1.25rem, 4vw, 1.875rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: .01em;
  text-align: right;
  color: var(--brand-gold-dark);
}

.site-footer {
  border-top: 1px solid var(--line);
  padding-block: 1.25rem;
  color: var(--ink-muted);
  font-size: .8125rem;
  text-align: center;
}

/* ==========================================================================
   5. FORM CONTROLS
   ========================================================================== */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.panel__heading {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brand-red-dark);
  padding-bottom: .75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.field + .field,
.field + .method-panel,
.method-panel + .method-panel { margin-top: var(--gap); }

.field__label {
  display: block;
  margin-bottom: .375rem;
  font-size: .875rem;
  font-weight: 600;
  color: var(--ink);
}

.field__hint {
  margin-top: .5rem;
  font-size: .8125rem;
  color: var(--ink-muted);
}

.field__error {
  margin-top: .5rem;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--error);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
}

/* Side-by-side fields are spaced by the grid gap, not the stacking margin */
.field-row .field + .field { margin-top: 0; }

/* Quick-set duration chips */
.quick-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  margin-top: .875rem;
}

.quick-add__label {
  font-size: .8125rem;
  color: var(--ink-muted);
}

.quick-add__row {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
}

.chip {
  padding: .3125rem .625rem;
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--brand-gold-dark);
  background: var(--brand-beige-soft);
  border: 1px solid var(--brand-beige);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.chip:hover:not(:disabled) {
  color: #fff;
  background: var(--brand-gold);
  border-color: var(--brand-gold);
}

.chip:disabled {
  color: var(--ink-muted);
  background: transparent;
  border-color: var(--line);
  opacity: .6;
  cursor: not-allowed;
}

.control {
  width: 100%;
  padding: .625rem .75rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.control:hover { border-color: var(--brand-gold); }

.control:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px var(--brand-red-tint);
}

.control--narrow { max-width: 12rem; }

.control.is-invalid,
.money-input.is-invalid { border-color: var(--error); }

/* Dependency level select: native control, branded chevron */
.control--select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23CA2021' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .875rem center;
  cursor: pointer;
}

/* Additional-charge checkboxes */
.checks {
  display: grid;
  gap: .5rem;
}

.check {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: .625rem .75rem;
  font-size: .9375rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.check:hover { border-color: var(--brand-gold); }

.check__input {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  flex: none;
  accent-color: var(--brand-red);
  cursor: pointer;
}

.check__amount {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--brand-gold-dark);
}

/* Checked rows lift onto the beige ground; harmless where :has() is unsupported */
.check:has(.check__input:checked) {
  background: var(--brand-beige-soft);
  border-color: var(--brand-beige);
}

/* Read-only calculated weekly fee */
.fee {
  display: block;
  padding: .75rem .875rem;
  background: var(--brand-beige-soft);
  border: 1px solid var(--brand-beige);
  border-left: 3px solid var(--brand-red);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.fee__amount {
  display: block;
  font-family: var(--font-figures);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: var(--brand-red-darker);
}

.fee__items {
  display: block;
  margin-top: .125rem;
  font-size: .8125rem;
  color: var(--ink-muted);
}

/* Money input: fixed currency affix */
.money-input {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.money-input:hover { border-color: var(--brand-gold); }

.money-input:focus-within {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px var(--brand-red-tint);
}

.money-input__symbol {
  display: flex;
  align-items: center;
  padding-inline: .75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--brand-red-dark);
  background: var(--brand-beige-soft);
  border-right: 1px solid var(--line);
}

.money-input__control {
  flex: 1 1 auto;
  min-width: 0;
  padding: .625rem .75rem;
  font-family: var(--font-figures);
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: transparent;
  border: 0;
}

.money-input__control:focus { outline: none; }

/* Trim the number spinners - these figures are typed, not nudged */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ==========================================================================
   6. SEGMENTED TOGGLE
   ========================================================================== */
.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .25rem;
  padding: .25rem;
  background: var(--brand-beige-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.segmented__input {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.segmented__option {
  padding: .5rem .75rem;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
  transition: background-color .15s ease, color .15s ease;
}

.segmented__option:hover { color: var(--brand-red-dark); }

.segmented__input:checked + .segmented__option {
  background: var(--brand-red);
  color: #fff;
  box-shadow: 0 1px 2px rgba(110, 17, 19, .25);
}

.segmented__input:focus-visible + .segmented__option {
  outline: 3px solid var(--brand-gold);
  outline-offset: 2px;
}

/* ==========================================================================
   7. BUTTONS
   ========================================================================== */
/* Primary spans the row; the two secondaries hold a strict 50/50 split.
   minmax(0, 1fr) is what keeps them fixed - a plain 1fr would let the longer
   label widen its own track, so swapping "Copy Summary to Clipboard" for
   "Copied!" would resize both buttons. */
.actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: .75rem;
}

/* The primary action leads: full width, and taller and larger than the
   secondary pair beneath it. */
.actions .btn--primary {
  grid-column: 1 / -1;
  min-height: 3.5rem;
  font-size: 1.0625rem;
}

.actions__hint {
  margin-top: .625rem;
  font-size: .8125rem;
  color: var(--ink-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6875rem 1.25rem;
  font-family: inherit;
  font-size: .9375rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.btn--primary {
  background: var(--brand-red);
  color: #fff;
}

.btn--primary:hover { background: var(--brand-red-dark); }

.btn--secondary {
  background: var(--brand-beige-soft);
  color: var(--brand-gold-dark);
  border-color: var(--brand-beige);
}

.btn--secondary:hover {
  background: var(--brand-beige);
  border-color: var(--brand-gold);
}

/* Transient confirmation after a copy */
.btn.is-copied,
.btn.is-copied:hover {
  background: var(--brand-gold);
  color: #fff;
  border-color: var(--brand-gold);
}

.btn.is-failed,
.btn.is-failed:hover {
  background: var(--surface);
  color: var(--error);
  border-color: var(--error);
}

.btn--ghost {
  background: var(--surface);
  color: var(--brand-red-dark);
  border-color: var(--brand-red);
}

.btn--ghost:hover {
  background: var(--brand-red);
  color: #fff;
}

.btn--small {
  padding: .375rem .75rem;
  font-size: .8125rem;
}

.btn:disabled,
.btn:disabled:hover {
  background: var(--line);
  color: var(--ink-muted);
  border-color: transparent;
  cursor: not-allowed;
}

/* ==========================================================================
   8. RESULT
   ========================================================================== */
.result {
  padding: 1.75rem 1.5rem;
  background: linear-gradient(180deg, var(--brand-beige-soft), var(--surface) 55%);
  border: 1px solid var(--brand-beige);
  border-top: 4px solid var(--brand-red);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  text-align: center;
}

.result__heading {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--brand-gold-dark);
}

.result__total {
  display: block;
  margin-top: .5rem;
  font-family: var(--font-figures);
  font-size: clamp(2.75rem, 9vw, 4rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--brand-red-darker);
  word-break: break-word;
}

.result__total.is-empty { color: var(--brand-beige); }

.result__status {
  margin-top: .75rem;
  font-size: .875rem;
  color: var(--ink-muted);
}

.result__status.is-error {
  color: var(--error);
  font-weight: 600;
}

.breakdown {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--brand-beige);
  text-align: left;
}

.breakdown__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: .5rem;
}

.breakdown__row + .breakdown__row { border-top: 1px dashed var(--brand-beige); }

.breakdown__row dt {
  font-size: .875rem;
  color: var(--ink-muted);
}

.breakdown__row dd {
  font-family: var(--font-figures);
  font-size: .9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
}

.breakdown__note {
  display: block;
  font-size: .75rem;
  font-weight: 400;
  color: var(--brand-gold-dark);
}

.result__formula {
  margin-top: 1rem;
  padding: .625rem .75rem;
  background: var(--brand-red-tint);
  border-radius: var(--radius-sm);
  font-family: var(--font-figures);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--brand-red-dark);
}

/* ==========================================================================
   9. RESPONSIVE
   ========================================================================== */
@media (max-width: 56rem) {
  .calculator {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
  }

  /* Stacked, the total leads, then the inputs, then the buttons that act on
     them - so the actions are not offered before there is anything to act on */
  .calculator > .panel:not(.actions-card),
  .calculator > .result,
  .calculator > .actions-card { grid-column: 1; grid-row: auto; }

  .result                                 { order: 1; }
  .calculator > .panel:not(.actions-card) { order: 2; }
  .calculator > .actions-card             { order: 3; }
}

@media (max-width: 30rem) {
  .shell { padding-inline: 1rem; }
  .panel, .result { padding: 1.25rem 1rem; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .segmented { grid-template-columns: minmax(0, 1fr); }
  .site-header__logo { height: 72px; }
  .control--narrow { max-width: none; }
  .modal__actions { flex-direction: column-reverse; }
  .modal__actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ==========================================================================
   10. MODAL
   Native <dialog>, so focus trapping, Esc-to-close and the backdrop
   come from the browser rather than from JavaScript.
   ========================================================================== */
.modal {
  width: min(30rem, calc(100vw - 2rem));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand-red);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
}

.modal::backdrop { background: rgba(35, 32, 30, .55); }

.modal__panel { padding: 1.5rem; }

.modal__title {
  margin-bottom: 1.25rem;
  padding-bottom: .75rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--brand-red-dark);
  border-bottom: 1px solid var(--line);
}

.modal__warning {
  margin-top: 1rem;
  padding: .75rem .875rem;
  font-size: .8125rem;
  line-height: 1.45;
  color: var(--ink-muted);
  background: var(--brand-beige-soft);
  border-left: 3px solid var(--brand-gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.5rem;
}

/* ==========================================================================
   11. PRO-FORMA INVOICE
   Hidden on screen; section 12 reveals it for printing. Follows the layout
   of References/Proforma Invoice.xlsx.
   ========================================================================== */
.invoice { display: none; }

.invoice__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--brand-red);
}

.invoice__logo {
  width: auto;
  height: 110px;
  flex: none;
}

.invoice__masthead { text-align: right; }

.invoice__org {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--brand-red);
}

.invoice__doctype {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.invoice__date {
  margin-top: .25rem;
  font-size: .875rem;
  color: var(--ink-muted);
}

.invoice__details { margin-top: 1.5rem; }

.invoice__detail {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding-block: .4rem;
  border-bottom: 1px dotted var(--line);
}

.invoice__detail dt { color: var(--ink-muted); }

.invoice__detail dd {
  font-weight: 600;
  text-align: right;
}

.invoice__table {
  width: 100%;
  margin-top: 1.75rem;
  border-collapse: collapse;
}

.invoice__caption {
  padding-bottom: .5rem;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: left;
  color: var(--brand-red);
}

.invoice__table th,
.invoice__table td {
  padding-block: .5rem;
  text-align: left;
  font-weight: 400;
  border-bottom: 1px solid var(--line);
}

.invoice__table td {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.invoice__total-row th,
.invoice__total-row td {
  padding-top: .875rem;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--brand-red-darker);
  border-top: 2px solid var(--brand-red);
  border-bottom: 0;
}

.invoice__includes-row td {
  padding-top: 0;
  padding-bottom: .625rem;
  font-size: .8125rem;
  font-style: italic;
  text-align: left;
  color: var(--ink-muted);
}

.invoice__bank {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.invoice__bank-note {
  margin-top: .875rem;
  padding: .625rem .75rem;
  font-size: .875rem;
  background: var(--brand-beige-soft);
  border-left: 3px solid var(--brand-gold);
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.invoice__bank-heading {
  margin-bottom: .5rem;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--brand-red);
}

.invoice__disclaimer {
  margin-top: 1.75rem;
  padding-top: .875rem;
  font-size: .875rem;
  font-style: italic;
  color: var(--ink-muted);
  border-top: 1px solid var(--line);
}

/* ==========================================================================
   12. PRINT
   Everything interactive is dropped; only the pro-forma invoice remains.
   ========================================================================== */
@media print {
  @page { margin: 15mm; }

  .site-header,
  main,
  .site-footer,
  .modal,
  .modal::backdrop { display: none !important; }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .invoice { display: block; }

  /* Keep related blocks from splitting across pages */
  .invoice__head,
  .invoice__table,
  .invoice__bank { break-inside: avoid; }
}
