/* =====================================================================
   WACC CALCULATOR STYLES

   Layout and components only. Every colour and font is a CSS variable
   (--bg, --accent, --sans ...) set by js/brand.js, so re-branding never
   needs a change in this file.
   ===================================================================== */

/* =====================================================================
   BASE
   ===================================================================== */
html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
  -webkit-text-size-adjust: 100%;
}
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 22px 18px calc(48px + env(safe-area-inset-bottom, 0px));
}

h1 { font-size: 26px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 14px; margin: 18px 0 6px; }
.sub   { color: var(--muted); margin: 2px 0 0; }
.muted { color: var(--muted); }
.print-only { display: none; }

a { color: var(--accent); }

/* =====================================================================
   APP HEADER (logo and name)
   ===================================================================== */
.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.app-header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
}
.brand img { height: 28px; width: auto; display: block; }

/* =====================================================================
   BUTTONS AND SMALL CONTROLS
   ===================================================================== */
button, .btn {
  display: inline-block;
  font: 500 14px/1.2 var(--sans);
  padding: 9px 14px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}
.btn.p { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }

select {
  font: 500 13px var(--sans);
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
}

button:focus-visible, .btn:focus-visible, select:focus-visible,
.card:focus-visible, .field input:focus-visible, .brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* =====================================================================
   PAGE HEADINGS AND TOOLBARS
   ===================================================================== */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 16px;
}
.toolbar .spacer { flex: 1; }

/* =====================================================================
   LIST SCREEN
   ===================================================================== */
.sortbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
}
.card:hover { border-color: var(--accent); }
.card-name { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.card-meta { grid-column: 1; color: var(--muted); font-size: 13px; }
.card-wacc { grid-column: 2; grid-row: 1 / span 2; font: 500 22px var(--mono); color: var(--accent); }

.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
}
.empty p { margin: 0 0 12px; }

/* =====================================================================
   FORM SCREEN
   ===================================================================== */
fieldset {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  margin: 0 0 14px;
  padding: 14px 16px 6px;
  min-width: 0;
}
/* Float the legend so it sits inside the box instead of straddling the border */
legend {
  float: left;
  width: 100%;
  padding: 0;
  margin: 0 0 12px;
  font-weight: 600;
  font-size: 15px;
}
legend + * { clear: both; }

/* One input row: label + hint on the left, input box on the right */
.row {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 4px 14px;
  align-items: center;
  margin-bottom: 12px;
}
.row label { font-weight: 500; }
.row small {
  grid-column: 1;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
  margin-top: -2px;
}
@media (max-width: 480px) { .row { grid-template-columns: 1fr 120px; } }

/* Full-width row for text fields (company name, period) */
.row.wide { grid-template-columns: 1fr; }
.row.wide .field { grid-column: 1; grid-row: auto; }

/* Input wrapper: holds the box plus a unit symbol (% or £) */
.field { position: relative; grid-column: 2; grid-row: 1 / span 2; }
.field input {
  width: 100%;
  font: 500 15px var(--mono);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 30px 8px 10px;
  text-align: right;
}
.field.text input { font: 400 15px var(--sans); padding: 8px 10px; text-align: left; }
.field span {                       /* unit symbol, right-hand by default */
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font: 13px var(--mono);
  pointer-events: none;
}
.field.pre span { left: 10px; right: auto; }              /* "£" prefix variant */
.field.pre input { padding-left: 26px; padding-right: 10px; }

/* Sticky bar at the bottom of the form: live WACC, Cancel, Save */
.form-error { color: var(--danger); margin: 0 0 8px; font-size: 14px; }
.actionbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg);
  border-top: 1px solid var(--line);
  margin: 8px -18px 0;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
}
.actionbar .live { margin-right: auto; color: var(--muted); font-size: 13px; }
.actionbar .live b { font: 500 16px var(--mono); color: var(--accent); margin-left: 4px; }

/* =====================================================================
   REPORT SCREEN
   ===================================================================== */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px;
}

.report-head { margin: 0 0 14px; }

.big   { font: 500 44px/1.1 var(--mono); color: var(--accent); margin: 2px 0; }
.big-l { color: var(--muted); font-size: 13px; }
.warn  { color: var(--warning); font-size: 13px; min-height: 1.2em; margin: 6px 0 0; }
.note  { color: var(--muted); font-size: 12.5px; margin: 14px 0 0; }

/* Capital structure bar and its legend */
.bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; margin: 16px 0 8px; background: var(--line); }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.legend b { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.dot-equity { background: var(--equity); }
.dot-debt   { background: var(--debt); }
.dot-pref   { background: var(--pref); }

/* Tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 500; color: var(--muted); }
td { font-family: var(--mono); }
tr.tot td, tr.tot th { border-bottom: 0; font-weight: 600; color: var(--ink); }

/* Sensitivity table */
.sens td, .sens th { font-size: 12.5px; text-align: center; padding: 5px 6px; }
.sens td.c { background: var(--highlight); font-weight: 600; }   /* centre cell = current inputs */

/* Inputs-used table */
.inputs-table th { color: var(--ink); font-weight: 400; }
.inputs-table tr.group th { color: var(--muted); font-weight: 600; padding-top: 14px; border-bottom-color: transparent; }
.inputs-table td { white-space: nowrap; }

/* =====================================================================
   PRINT / EXPORT TO PDF
   Hides the app chrome and prints the report on a plain white page.
   ===================================================================== */
@media print {
  @page { margin: 14mm; }

  html, body { background: #fff; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .no-print, .app-header { display: none !important; }
  .print-only { display: block; }

  main { max-width: none; padding: 0; }
  .panel { border: 0; padding: 0; background: transparent; }

  table, tr, .bar { break-inside: avoid; }
  h2 { break-after: avoid; }

  .print-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 14px;
    border-bottom: 2px solid var(--accent);
  }
  .print-brand .brand-left { display: flex; align-items: center; gap: 10px; font-weight: 600; }
  .print-brand img { height: 32px; width: auto; }
  .print-brand .when { color: var(--muted); font-size: 12px; }
}
