/*
  Tower Footing Resistance tool — All Electron aligned theme
  Key change: all component styling is scoped to .tfr-tool so it does not
  fight the WordPress/theme styling outside the calculator.
*/

.tfr-tool {
  --tfr-accent: #6557a2;
  --tfr-accent-dark: #4f4388;
  --tfr-accent-soft: #f6f3ff;
  --tfr-text: #1f2933;
  --tfr-muted: #667085;
  --tfr-border: rgba(31, 41, 51, 0.14);
  --tfr-border-strong: rgba(101, 87, 162, 0.28);
  --tfr-surface: #ffffff;
  --tfr-surface-soft: #faf9ff;
  --tfr-danger: #b42318;
  --tfr-danger-soft: #fff1f0;
  --tfr-ok: #0f7b55;
  --tfr-warn: #b54708;
  --tfr-radius: 14px;
  --tfr-radius-sm: 10px;
  --tfr-shadow: 0 10px 28px rgba(31, 41, 51, 0.07);

  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  position: relative;
  padding: 0 0 58px;
  color: var(--tfr-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
}

.tfr-tool,
.tfr-tool * { box-sizing: border-box; }

.tfr-tool .topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 18px 0 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--tfr-border);
}

.tfr-tool h1,
.tfr-tool h2,
.tfr-tool p { margin-top: 0; }

.tfr-tool h1 {
  margin-bottom: 5px;
  color: var(--tfr-accent);
  font-size: clamp(1.45rem, 2vw, 1.95rem);
  line-height: 1.18;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.tfr-tool h2 {
  margin-bottom: 12px;
  color: var(--tfr-text);
  font-size: 1rem;
  line-height: 1.25;
  font-weight: 700;
}

.tfr-tool p {
  margin-bottom: 0;
  max-width: 68ch;
  color: var(--tfr-muted);
}

.tfr-tool .status-pill {
  position: absolute;
  right: 0;
  bottom: 12px;
  z-index: 5;
  max-width: min(420px, 100%);
  padding: 7px 12px;
  border: 1px solid var(--tfr-border);
  border-radius: 999px;
  background: var(--tfr-surface-soft);
  color: var(--tfr-muted);
  font-size: 0.86rem;
  line-height: 1.25;
  text-align: right;
}

.tfr-tool .status-pill.warn {
  border-color: rgba(245, 158, 11, 0.42);
  background: #fffbeb;
  color: #92400e;
  white-space: normal;
}

.tfr-tool .layout {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  width: 100%;
}

.tfr-tool .left-panel,
.tfr-tool .right-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.tfr-tool .card {
  position: relative;
  overflow: hidden;
  padding: 16px;
  border: 1px solid var(--tfr-border);
  border-radius: var(--tfr-radius);
  background: var(--tfr-surface);
  box-shadow: var(--tfr-shadow);
}

.tfr-tool .card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--tfr-accent);
  opacity: 0.9;
}

.tfr-tool .card > * { position: relative; }
.tfr-tool .left-panel .card:first-child { background: linear-gradient(180deg, var(--tfr-surface-soft), #fff 42%); }

.tfr-tool .toolbar,
.tfr-tool .chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.tfr-tool .toolbar.compact { margin: 8px 0; }
.tfr-tool .chart-toolbar { justify-content: flex-end; margin-bottom: 8px; }

.tfr-tool button {
  appearance: none;
  border: 1px solid var(--tfr-accent);
  border-radius: 999px;
  background: var(--tfr-accent);
  color: #fff;
  padding: 8px 13px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.1;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .03s ease;
}

.tfr-tool button:hover {
  background: var(--tfr-accent-dark);
  border-color: var(--tfr-accent-dark);
  box-shadow: 0 0 0 3px rgba(101, 87, 162, .16);
}

.tfr-tool button:active { transform: translateY(1px); }

.tfr-tool button.ghost,
.tfr-tool #fitFopRhoBtn,
.tfr-tool #fitFopCorrectionBtn,
.tfr-tool #fitObliqueCorrectionBtn {
  background: #fff;
  color: var(--tfr-accent);
  border-color: var(--tfr-border-strong);
}

.tfr-tool button.ghost:hover,
.tfr-tool #fitFopRhoBtn:hover,
.tfr-tool #fitFopCorrectionBtn:hover,
.tfr-tool #fitObliqueCorrectionBtn:hover {
  background: var(--tfr-accent-soft);
  border-color: var(--tfr-accent);
}

.tfr-tool td button {
  padding: 5px 8px;
  border-color: #fecaca;
  background: #fff;
  color: var(--tfr-danger);
}

.tfr-tool td button:hover {
  background: var(--tfr-danger-soft);
  border-color: #fda29b;
  box-shadow: none;
}

.tfr-tool #finishPinBtn,
.tfr-tool #refineTowerBtn.finish-state,
.tfr-tool #adjustPointsBtn.finish-state {
  background: var(--tfr-danger) !important;
  border-color: var(--tfr-danger) !important;
  color: #fff !important;
}

.tfr-tool .drop-zone {
  margin: 8px 0 10px;
  padding: 15px 14px;
  border: 1px dashed var(--tfr-border-strong);
  border-radius: var(--tfr-radius-sm);
  background: #fff;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

.tfr-tool .drop-zone:hover,
.tfr-tool .drop-zone.dragover {
  border-color: var(--tfr-accent);
  background: var(--tfr-accent-soft);
  box-shadow: inset 0 0 0 1px rgba(101, 87, 162, .06);
}

.tfr-tool .drop-zone-small { padding: 10px 12px; }
.tfr-tool .drop-title { color: var(--tfr-text); font-weight: 700; }
.tfr-tool .drop-subtitle { margin-top: 3px; color: var(--tfr-muted); font-size: 0.82rem; }

.tfr-tool label {
  display: grid;
  gap: 5px;
  margin: 9px 0;
  color: var(--tfr-text);
  font-weight: 650;
}

.tfr-tool .inline-select {
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  margin-top: 12px;
}

.tfr-tool input,
.tfr-tool select,
.tfr-tool textarea {
  font: inherit;
  color: var(--tfr-text);
}

.tfr-tool input[type="number"],
.tfr-tool input[type="text"],
.tfr-tool select,
.tfr-tool td input,
.tfr-tool td select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--tfr-border);
  border-radius: 9px;
  background: #fff;
  padding: 6px 9px;
  font-weight: 400;
}

.tfr-tool input[type="number"] { max-width: 140px; }
.tfr-tool input[type="range"] { width: 100%; accent-color: var(--tfr-accent); }

.tfr-tool .fit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.tfr-tool .fit-row button { margin-bottom: 9px; min-width: 56px; }
.tfr-tool .fit-both-btn { display: block; width: auto; min-width: 96px; margin: 8px 0 0 auto; }

.tfr-tool .hint {
  margin-top: 10px;
  padding: 10px 11px;
  border-left: 3px solid var(--tfr-accent);
  border-radius: 0 var(--tfr-radius-sm) var(--tfr-radius-sm) 0;
  background: var(--tfr-accent-soft);
  color: #475467;
  font-size: 0.84rem;
}

.tfr-tool .table-wrap {
  overflow-x: auto;
  border: 1px solid var(--tfr-border);
  border-radius: var(--tfr-radius-sm);
  background: #fff;
}

.tfr-tool table {
  width: 100%;
  min-width: 292px;
  border-collapse: collapse;
  border-spacing: 0;
  font: inherit;
}

.tfr-tool th,
.tfr-tool td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(31, 41, 51, .08);
  text-align: left;
  vertical-align: middle;
}

.tfr-tool thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbfbfd;
  color: #475467;
  font-size: 0.78rem;
  font-weight: 700;
}

.tfr-tool tbody tr:last-child td { border-bottom: 0; }
.tfr-tool td:first-child { width: 38px; text-align: center; }
.tfr-tool td:nth-child(2) { max-width: 68px; }

.tfr-tool th[data-sort] { cursor: pointer; user-select: none; }
.tfr-tool th[data-sort]::after { content: "↕"; margin-left: 4px; color: #98a2b3; font-size: .75em; }
.tfr-tool th[data-sort].sort-asc::after { content: "↑"; color: var(--tfr-accent); }
.tfr-tool th[data-sort].sort-desc::after { content: "↓"; color: var(--tfr-accent); }

.tfr-tool .use-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
}

.tfr-tool .tabs {
  display: flex;
  gap: 4px;
  align-items: end;
  padding-left: 8px;
  border-bottom: 1px solid var(--tfr-border);
}

.tfr-tool .tab {
  margin-bottom: -1px;
  border: 1px solid var(--tfr-border);
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
  background: var(--tfr-surface-soft);
  color: #475467;
  box-shadow: none;
}

.tfr-tool .tab.active {
  background: #fff;
  color: var(--tfr-accent);
}

.tfr-tool .tab-panel { display: none; }
.tfr-tool .tab-panel.active { display: block; }
.tfr-tool .analysis-card,
.tfr-tool .map-card { min-height: 610px; border-top-left-radius: 0; }

.tfr-tool .map-toolbar { min-height: 34px; }
.tfr-tool #mapHint { color: var(--tfr-muted); font-size: .88rem; }

.tfr-tool .map,
.tfr-tool .schematic {
  width: 100%;
  height: 550px;
  overflow: hidden;
  border: 1px solid var(--tfr-border);
  border-radius: var(--tfr-radius-sm);
}

.tfr-tool .schematic { background: linear-gradient(180deg, #fff, var(--tfr-surface-soft)); }
.tfr-tool #analysisChart { width: 100%; max-height: 410px; cursor: crosshair; }
.tfr-tool #analysisChart.selecting { cursor: crosshair; }

.tfr-tool .axis-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  margin: 0;
  color: #475467;
  font-weight: 500;
}

.tfr-tool .axis-toggle input { margin: 0; }

.tfr-tool .results-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(95px, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.tfr-tool .result,
.tfr-tool .analysis-details,
.tfr-tool .detail-item {
  border: 1px solid var(--tfr-border);
  border-radius: var(--tfr-radius-sm);
  background: #fff;
}

.tfr-tool .result {
  padding: 10px;
  background: #fbfbfd;
}

.tfr-tool .result .label,
.tfr-tool .detail-item .label {
  color: var(--tfr-muted);
  font-size: 0.78rem;
}

.tfr-tool .result .value,
.tfr-tool .detail-item .value {
  margin-top: 2px;
  font-weight: 700;
}

.tfr-tool .result .value { font-size: 1rem; }
.tfr-tool .result.ok .value { color: var(--tfr-ok); }
.tfr-tool .result.warn .value { color: var(--tfr-warn); }

.tfr-tool .analysis-details {
  margin: 10px 0 8px;
  background: #fbfbfd;
}

.tfr-tool .analysis-details summary,
.tfr-tool .demo-details summary {
  cursor: pointer;
  padding: 9px 11px;
  color: #475467;
  font-weight: 700;
}

.tfr-tool .details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
}

.tfr-tool .detail-item { padding: 8px; }
.tfr-tool .detail-item .value .slope-r { font-weight: 800; }

.tfr-tool .file-card { padding-top: 16px; }
.tfr-tool .bottom-file-actions { margin-bottom: 0; }
.tfr-tool .file-actions button { flex: 1 1 auto; }

.tfr-tool .demo-details {
  margin-top: 10px;
  border: 1px solid var(--tfr-border);
  border-radius: var(--tfr-radius-sm);
  background: #fff;
}

.tfr-tool .demo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 0 10px 10px;
}

.tfr-tool .demo-grid button { padding: 7px 8px; font-size: .82rem; }

.tfr-tool .fit-quality-box {
  display: inline-block;
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border: 1px solid rgba(31, 41, 51, .22);
  border-radius: 3px;
}

.tfr-tool .map-pin-label {
  padding: 1px 5px;
  border: 1px solid rgba(31, 41, 51, .18);
  border-radius: 6px;
  background: rgba(255,255,255,.92);
  box-shadow: none;
  color: var(--tfr-text);
  font-size: 12px;
  font-weight: 750;
}

.tfr-tool .map-pin-label::before { display: none; }
.tfr-tool .leaflet-popup-content { font-size: 13px; line-height: 1.4; }
.tfr-tool .direction-line { stroke: var(--tfr-accent); stroke-width: 3; stroke-dasharray: 8 6; }
.tfr-tool .hidden { display: none !important; }

@media (max-width: 1100px) {
  .tfr-tool .layout { grid-template-columns: 1fr; }
  .tfr-tool .results-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .tfr-tool { font-size: 13px; }
  .tfr-tool .status-pill { left: 0; right: auto; max-width: 100%; text-align: left; }
  .tfr-tool .card { padding: 13px; }
  .tfr-tool .results-grid,
  .tfr-tool .details-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tfr-tool .map,
  .tfr-tool .schematic { height: 460px; }
}

@media (max-width: 480px) {
  .tfr-tool .results-grid,
  .tfr-tool .details-grid,
  .tfr-tool .demo-grid { grid-template-columns: 1fr; }
  .tfr-tool .inline-select,
  .tfr-tool .fit-row { grid-template-columns: 1fr; }
  .tfr-tool .fit-row button { margin-bottom: 0; }
}

/* Refinements after website review: compact table/form controls, clearer action hierarchy, no table gridlines, cleaner tabs and sliders. */
.tfr-tool button {
  padding: 6px 10px;
  font-size: 0.82rem;
  line-height: 1.05;
  min-height: 30px;
}

.tfr-tool button.ghost,
.tfr-tool #saveJsonBtn,
.tfr-tool #fitFopRhoBtn,
.tfr-tool #fitFopCorrectionBtn,
.tfr-tool #fitObliqueCorrectionBtn {
  background: #fff;
  color: var(--tfr-accent);
  border-color: var(--tfr-border-strong);
}

.tfr-tool button.ghost:hover,
.tfr-tool #saveJsonBtn:hover,
.tfr-tool #fitFopRhoBtn:hover,
.tfr-tool #fitFopCorrectionBtn:hover,
.tfr-tool #fitObliqueCorrectionBtn:hover {
  background: var(--tfr-accent-soft);
  border-color: var(--tfr-accent);
  box-shadow: 0 0 0 2px rgba(101, 87, 162, .12);
}

.tfr-tool label {
  gap: 3px;
  margin: 6px 0;
  font-size: 0.9rem;
}

.tfr-tool input[type="number"],
.tfr-tool input[type="text"],
.tfr-tool select,
.tfr-tool td input,
.tfr-tool td select {
  min-height: 28px;
  border-radius: 7px;
  padding: 4px 7px;
  font-size: 0.84rem;
}

.tfr-tool .fit-row {
  gap: 7px;
}

.tfr-tool .fit-row button {
  margin-bottom: 6px;
  min-width: 46px;
}

.tfr-tool .table-wrap {
  border: 0;
  border-radius: 10px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(31, 41, 51, .06);
}

.tfr-tool table {
  min-width: 270px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.84rem;
}

.tfr-tool th,
.tfr-tool td {
  padding: 4px 6px;
  border: 0 !important;
}

.tfr-tool thead th {
  background: #f7f7fb;
  font-size: 0.72rem;
}

.tfr-tool tbody tr:nth-child(even) td {
  background: #fcfcff;
}

.tfr-tool tbody tr:hover td {
  background: var(--tfr-accent-soft);
}

.tfr-tool td:first-child { width: 32px; }
.tfr-tool td:nth-child(2) { max-width: 56px; }
.tfr-tool td button {
  min-height: 26px;
  padding: 4px 7px;
  font-size: 0.78rem;
}

.tfr-tool input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 18px;
  margin: 5px 0 8px;
  background: transparent;
  accent-color: var(--tfr-accent);
}

.tfr-tool input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--tfr-accent), #b6acd9);
  box-shadow: inset 0 0 0 1px rgba(101, 87, 162, .10);
}

.tfr-tool input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--tfr-accent);
  box-shadow: 0 1px 4px rgba(31, 41, 51, .22);
}

.tfr-tool input[type="range"]::-moz-range-track {
  height: 6px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--tfr-accent), #b6acd9);
}

.tfr-tool input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--tfr-accent);
  box-shadow: 0 1px 4px rgba(31, 41, 51, .22);
}

.tfr-tool .tab:hover {
  background: #f2f3f7;
  color: var(--tfr-text);
  border-color: var(--tfr-border);
  box-shadow: none;
}

.tfr-tool .tab.active:hover {
  background: #fff;
  color: var(--tfr-accent);
}

.tfr-tool .inline-file-card {
  margin-top: 12px;
  min-height: auto;
  padding: 12px;
}

.tfr-tool .inline-file-card h2 {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.tfr-tool .file-card-row {
  display: grid;
  grid-template-columns: minmax(130px, 1.1fr) auto minmax(300px, 2.4fr);
  gap: 9px;
  align-items: center;
}

.tfr-tool .inline-file-card .drop-zone {
  margin: 0;
  padding: 8px 10px;
  text-align: left;
}

.tfr-tool .inline-file-card #saveJsonBtn {
  white-space: nowrap;
}

.tfr-tool .demo-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tfr-tool .demo-label {
  margin-right: 2px;
  color: var(--tfr-muted);
  font-size: .78rem;
  font-weight: 700;
}

.tfr-tool .demo-inline .demo-btn {
  padding-inline: 9px;
}

@media (max-width: 900px) {
  .tfr-tool .file-card-row {
    grid-template-columns: 1fr auto;
  }
  .tfr-tool .demo-inline {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .tfr-tool .file-card-row {
    grid-template-columns: 1fr;
  }
}

/* Revision: place import/export/demo in the right content column and use the wider row efficiently. */
.tfr-tool .right-file-card {
  margin-top: 0;
}

.tfr-tool .right-file-card .file-card-row {
  grid-template-columns: minmax(150px, 0.85fr) auto minmax(360px, 2.6fr);
}

.tfr-tool .right-file-card .demo-inline {
  justify-content: flex-start;
}

.tfr-tool .detail-item .value {
  overflow-wrap: anywhere;
}

.tfr-tool .detail-item .value:has(+ *) {
  color: inherit;
}

@media (max-width: 1100px) {
  .tfr-tool .right-file-card .file-card-row {
    grid-template-columns: minmax(150px, 1fr) auto;
  }
  .tfr-tool .right-file-card .demo-inline {
    grid-column: 1 / -1;
  }
}

#saveDbBtn[disabled] { opacity: .55; cursor: not-allowed; }


/* Requested update: keep the measurement table width stable while reallocating space. */
.tfr-tool #measurementTable {
  table-layout: fixed;
  width: 100%;
  min-width: 270px;
}

.tfr-tool #measurementTable th:nth-child(1),
.tfr-tool #measurementTable td:nth-child(1) { width: 32px; }

.tfr-tool #measurementTable th:nth-child(2),
.tfr-tool #measurementTable td:nth-child(2) { width: 65px; max-width: none; }

.tfr-tool #measurementTable th:nth-child(3),
.tfr-tool #measurementTable td:nth-child(3) { width: 56px; }

.tfr-tool #measurementTable th:nth-child(4),
.tfr-tool #measurementTable td:nth-child(4) { width: 65px; }

.tfr-tool #measurementTable th:nth-child(5),
.tfr-tool #measurementTable td:nth-child(5) { width: 28px; }

.tfr-tool #measurementTable td input {
  width: 100%;
  min-width: 0;
}

.tfr-tool #measurementTable input[data-k="distance"]::-webkit-outer-spin-button,
.tfr-tool #measurementTable input[data-k="distance"]::-webkit-inner-spin-button,
.tfr-tool #measurementTable input[data-k="resistance"]::-webkit-outer-spin-button,
.tfr-tool #measurementTable input[data-k="resistance"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.tfr-tool #measurementTable input[data-k="distance"],
.tfr-tool #measurementTable input[data-k="resistance"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

/* WordPress page integration: keep the tool scoped and avoid theme collisions. */
.tfr-page .tfr-tool {
  margin-top: 18px;
  margin-bottom: 34px;
}

/* Larger selection checkboxes in the measurement table. */
.tfr-tool #measurementTable input[type="checkbox"],
.tfr-tool table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  vertical-align: middle;
  accent-color: var(--tfr-accent);
}
