@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Source+Sans+3:wght@400;600;700&display=swap');

:root {
  --bg: #f6f9f7;
  --ink: #172123;
  --ink-muted: #4f6368;
  --panel: #ffffffcc;
  --panel-solid: #ffffff;
  --line: #c8d6d4;
  --brand: #005b67;
  --brand-2: #a94236;
  --good: #1f7f4b;
  --bad: #a72930;
  --shadow: 0 14px 35px rgba(15, 36, 39, 0.14);
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 15% -10%, #e2f0ed 0, transparent 40%),
    radial-gradient(circle at 100% 15%, #fee9df 0, transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: 'Source Sans 3', sans-serif;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(2px);
  pointer-events: none;
}

.bg-shape-a {
  width: 340px;
  height: 340px;
  top: 12%;
  right: -120px;
  background: linear-gradient(140deg, #ffd6bd, #f69a76);
  opacity: 0.3;
}

.bg-shape-b {
  width: 300px;
  height: 300px;
  left: -130px;
  bottom: 8%;
  background: linear-gradient(120deg, #9bcfca, #64a3a6);
  opacity: 0.28;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1520px;
  margin: 0 auto;
  padding: 28px 20px 32px;
}

body.app-locked {
  overflow: hidden;
}

body.app-locked .app-shell,
body.app-locked .bg-shape {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.auth-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 33, 36, 0.56);
  padding: 20px;
}

.auth-backdrop[hidden] {
  display: none;
}

.auth-card {
  width: min(420px, 96vw);
  background: #fbfefe;
  border: 1px solid #cadada;
  border-radius: 16px;
  box-shadow: 0 18px 34px rgba(14, 32, 36, 0.35);
  padding: 16px;
}

.auth-card h2 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: #19383e;
  font-size: 1.2rem;
}

.auth-subtitle {
  margin: 8px 0 10px;
  color: #41595f;
  font-size: 0.92rem;
}

.auth-form label {
  display: block;
  color: #38535a;
  font-size: 0.88rem;
  margin-bottom: 5px;
}

.auth-form input {
  width: 100%;
  border: 1px solid #b5c6c5;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fbfdfd;
  color: var(--ink);
  font-size: 0.95rem;
}

.auth-form input:focus {
  outline: 2px solid #89c6c2;
  border-color: #6aa5a3;
}

.auth-form button {
  margin-top: 10px;
  border: 1px solid #0d616e;
  background: #0f6f7a;
  color: #f6fdfd;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.auth-error {
  margin: 10px 0 0;
  color: #8d2632;
  font-weight: 600;
  font-size: 0.86rem;
}

.hero {
  background: linear-gradient(135deg, #0f6f7a, #0a4d58 65%, #1f3f49);
  color: #f7fbfb;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  letter-spacing: 0.2px;
  font-size: clamp(1.5rem, 2.2vw, 2.25rem);
}

.hero p {
  margin: 8px 0 0;
  max-width: 760px;
  line-height: 1.35;
  color: #d5ecee;
}

.layout {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
  align-items: start;
}

.control-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 38px);
  overflow: auto;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid #dce8e7;
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.12rem;
  font-family: 'Space Grotesk', sans-serif;
}

#resetDefaults {
  border: 1px solid #2a5f67;
  background: #ffffff;
  color: #204c52;
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 600;
  cursor: pointer;
}

#resetDefaults:hover {
  background: #e9f4f4;
}

.control-group {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 10px;
}

.control-group h3 {
  margin: 0 0 9px;
  font-size: 0.98rem;
  font-family: 'Space Grotesk', sans-serif;
  color: #1f3f45;
}

.control-group-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.control-group-toggle::after {
  content: '▾';
  font-size: 0.9rem;
  color: #1f3f45;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.control-group-toggle[aria-expanded='false']::after {
  transform: rotate(-90deg);
}

.control-group-toggle:focus-visible {
  outline: 2px solid #89c6c2;
  outline-offset: 3px;
  border-radius: 6px;
}

.control-group.is-collapsed > :not(h3) {
  display: none;
}

.control-group label {
  display: block;
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.control-group label.field-highlight-label {
  color: #0b5a65;
  font-weight: 700;
}

.control-group input,
.control-group select,
.control-group textarea {
  margin-top: 5px;
  width: 100%;
  border: 1px solid #b5c6c5;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fbfdfd;
  color: var(--ink);
  font-size: 0.95rem;
}

.control-group input:focus,
.control-group select:focus,
.control-group textarea:focus {
  outline: 2px solid #89c6c2;
  border-color: #6aa5a3;
}

.control-group select {
  white-space: normal;
  text-overflow: clip;
  line-height: 1.25;
  height: auto;
}

.control-group option {
  white-space: normal;
}

.control-group input[disabled] {
  background: #eef3f3;
  color: #6a7f84;
  cursor: not-allowed;
}

.control-group .derived-readonly {
  margin-top: 5px;
  width: 100%;
  border: 1px solid #c2d2d2;
  border-radius: 10px;
  padding: 9px 10px;
  background: #f1f6f6;
  color: #35525a;
  font-size: 0.92rem;
}

.control-group .field-highlight-input {
  border: 2px solid #0f6f7a;
  background: #e9f6f8;
  box-shadow: 0 0 0 3px rgba(15, 111, 122, 0.16);
}

.control-group .field-highlight-input:focus {
  outline: 2px solid #4fb8c4;
  border-color: #0b6170;
  box-shadow: 0 0 0 4px rgba(79, 184, 196, 0.25);
}

.control-group textarea {
  resize: vertical;
  min-height: 72px;
}

.inline-action-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

#openFteIndividualsModal {
  border: 1px solid #2a5f67;
  background: #ffffff;
  color: #1f4f56;
  border-radius: 10px;
  padding: 7px 10px;
  font-weight: 600;
  cursor: pointer;
}

#openFteIndividualsModal:hover {
  background: #e9f4f4;
}

.inline-action-note {
  color: #4f6368;
  font-size: 0.82rem;
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.warning-box {
  border: 1px solid #e6b165;
  background: #fff7eb;
  color: #7f4e13;
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.35;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.kpi-card {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid #d7e4e3;
  border-radius: var(--radius-md);
  padding: 11px 12px;
  min-height: 104px;
  box-shadow: 0 10px 18px rgba(15, 36, 39, 0.08);
}

.kpi-card h4 {
  margin: 0;
  font-size: 0.87rem;
  color: var(--ink-muted);
  font-weight: 600;
}

.kpi-card p {
  margin: 8px 0 4px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.05rem, 1.6vw, 1.46rem);
  color: #102526;
  font-weight: 650;
}

.kpi-card small {
  color: #5f6f74;
}

.chart-card {
  background: var(--panel);
  border: 1px solid #d7e4e3;
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: 0 12px 22px rgba(15, 36, 39, 0.08);
}

.chart-card h3 {
  margin: 2px 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.04rem;
  color: #1a373b;
}

canvas {
  width: 100% !important;
  max-height: 360px;
}

.chart-card-primary {
  padding: 14px;
}

.chart-card-primary canvas {
  min-height: 390px;
  max-height: 450px;
}

.chart-card-compact {
  padding: 9px 10px;
}

.chart-card-compact h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.chart-card-compact canvas {
  max-height: 220px;
}

.formula-card {
  padding: 12px 12px 10px;
}

.formula-note {
  margin: 4px 0 8px;
  color: #38535a;
  font-size: 0.9rem;
}

.formula-select-label {
  display: block;
  margin-top: 6px;
  margin-bottom: 6px;
  color: #38535a;
  font-size: 0.88rem;
  font-weight: 600;
}

.formula-select {
  width: 100%;
  border: 1px solid #b5c6c5;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fbfdfd;
  color: var(--ink);
  font-size: 0.95rem;
}

.formula-select:focus {
  outline: 2px solid #89c6c2;
  border-color: #6aa5a3;
}

.formula-math {
  margin-top: 8px;
  overflow-x: auto;
  line-height: 1.35;
  color: #11292e;
  font-size: 0.92rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

thead th {
  text-align: left;
  font-weight: 700;
  font-size: 0.84rem;
  color: #1d3b41;
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
}

.table-sort-button {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.table-sort-button:hover {
  color: #0f6f7a;
  text-decoration: underline;
}

tbody td {
  border-bottom: 1px solid #e4eeed;
  padding: 8px 6px;
  font-size: 0.9rem;
}

tbody tr:hover {
  background: #f4f8f8;
}

tbody tr.allocation-total-row {
  background: #edf5f5;
  font-weight: 700;
}

tbody tr.allocation-total-row:hover {
  background: #e7f1f1;
}

.negative {
  color: var(--bad);
  font-weight: 700;
}

.positive {
  color: var(--good);
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  background: rgba(16, 37, 40, 0.38);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(940px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #fbfefe;
  border: 1px solid #cadada;
  border-radius: 16px;
  box-shadow: 0 18px 34px rgba(14, 32, 36, 0.3);
  padding: 14px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: #19383e;
}

.modal-close {
  border: 1px solid #a9bebe;
  background: #fff;
  border-radius: 9px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 600;
}

.modal-subtitle {
  margin: 8px 0 10px;
  color: #41595f;
  font-size: 0.9rem;
}

.modal-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.modal-toolbar input[type='file'] {
  min-width: 260px;
  border: 1px solid #b8cbca;
  border-radius: 10px;
  padding: 7px 9px;
  background: #f9fcfc;
}

.modal-toolbar button {
  border: 1px solid #8eabaa;
  background: #ffffff;
  color: #20474c;
  border-radius: 9px;
  padding: 7px 10px;
  font-weight: 600;
  cursor: pointer;
}

.modal-status {
  margin: 9px 0 8px;
  color: #3f575d;
  font-size: 0.86rem;
}

.modal-table-wrap {
  border: 1px solid #d3e0df;
  border-radius: 12px;
  overflow: auto;
  max-height: 46vh;
}

.modal-table {
  min-width: 560px;
}

.modal-table th,
.modal-table td {
  padding: 7px 8px;
}

.modal-input {
  width: 100%;
  border: 1px solid #b2c7c5;
  border-radius: 8px;
  background: #fbfdfd;
  padding: 7px 8px;
  font-size: 0.9rem;
  color: #1a3339;
}

.modal-remove {
  border: 1px solid #d2a3a8;
  background: #fff6f7;
  color: #7a2f37;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.modal-computed-value {
  font-weight: 600;
  color: #1f4f56;
  font-size: 0.86rem;
}

.modal-summary {
  margin-top: 9px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  color: #25464d;
  font-size: 0.9rem;
}

.modal-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-footer button {
  border: 1px solid #92adac;
  background: #ffffff;
  color: #22484e;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.modal-footer .button-primary {
  border-color: #0d616e;
  background: #0f6f7a;
  color: #f6fdfd;
}

.modal-status-negative {
  color: #8d2632;
  font-weight: 600;
}

.modal-status-positive {
  color: #1f7f4b;
  font-weight: 600;
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: relative;
    top: 0;
    max-height: none;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .hero {
    padding: 18px;
  }

  .app-shell {
    padding: 16px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-toolbar input[type='file'] {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
