:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --text: #17211f;
  --muted: #66736f;
  --line: #d8e0dd;
  --accent: #0c7f6f;
  --accent-dark: #075f53;
  --blue: #245d8f;
  --yellow: #fff4cf;
  --orange: #ffe1ca;
  --red: #ffd6d6;
  --red-strong: #b42318;
  --shadow: 0 12px 35px rgba(20, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(14px, 4vw, 36px);
  color: #fff;
  background: linear-gradient(115deg, #17332f 0%, #0d6559 55%, #245d8f 100%);
}

.eyebrow {
  margin: 0 0 5px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 19px;
}

.header-status {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 13px;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px clamp(10px, 3vw, 28px) 32px;
  display: grid;
  gap: 16px;
}

.panel,
.summary-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  white-space: nowrap;
}

.badge.muted {
  color: var(--muted);
  background: var(--surface-2);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.compact-grid {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.field textarea {
  min-height: 78px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(12, 127, 111, 0.12);
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
}

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

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

.secondary-btn {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.danger-btn {
  color: #fff;
  background: var(--red-strong);
}

.charger-meta {
  margin: -4px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
}

.export-box {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
}

.export-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.export-box textarea {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.warnings {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.warning {
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--yellow);
  color: #6f4d00;
}

.chargers-list {
  display: grid;
  gap: 12px;
}

.charger-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.charger-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.charger-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.soc-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 34px;
  padding: 4px 8px;
  border-radius: 7px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.charger-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.charger-grid .wide {
  grid-column: span 2;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.summary-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

.summary-value {
  font-size: 24px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1160px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf3f2;
  color: #42504c;
  font-weight: 700;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.status-ok {
  background: #fff;
}

.status-warning {
  background: var(--yellow);
}

.status-risk {
  background: var(--orange);
}

.status-impossible {
  background: var(--red);
}

.status-passed {
  color: #8b9693;
  background: #f1f3f2;
}

.soc-large {
  display: inline-block;
  min-width: 56px;
  font-size: 20px;
  font-weight: 850;
}

.status-chip {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 7px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.68);
}

.comment-cell {
  max-width: 250px;
  color: var(--muted);
}

@media (max-width: 1050px) {
  .form-grid,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .charger-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 700px) {
  .app-header,
  .section-title,
  .charger-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-header {
    padding: 16px clamp(12px, 4vw, 20px);
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .app-shell {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .header-status,
  .toolbar,
  .toolbar button {
    width: 100%;
  }

  .form-grid,
  .compact-grid,
  .summary-grid,
  .charger-grid {
    grid-template-columns: 1fr;
  }

  .charger-grid .wide {
    grid-column: auto;
  }

  .panel,
  .summary-panel,
  .result-panel {
    padding: 12px;
  }

  .summary-value {
    font-size: 22px;
  }

  /* Larger touch targets and no iOS auto-zoom on focus */
  .field input,
  .field select,
  .field textarea,
  .table-soc-input,
  .curve-table input {
    min-height: 44px;
    font-size: 16px;
  }

  button {
    min-height: 44px;
  }

  /* Result table -> stacked cards */
  .table-wrap {
    overflow-x: visible;
    border: 0;
    border-radius: 0;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  table tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    text-align: right;
  }

  table tbody tr td:last-child {
    border-bottom: 0;
  }

  table tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
  }

  /* Status coloring stays on the whole card, not just first cell */
  table tr.charger-power-low td:first-child,
  table tr.charger-power-good td:first-child,
  table tr.charger-power-fast td:first-child {
    border-left: 0;
  }

  table tr.charger-power-low {
    border-left: 5px solid #d92d20;
  }

  table tr.charger-power-good {
    border-left: 5px solid #14804a;
  }

  table tr.charger-power-fast {
    border-left: 5px solid #245d8f;
  }

  .comment-cell {
    max-width: none;
  }

  .comment-cell:empty {
    display: none;
  }

  .table-check {
    white-space: normal;
  }
}

.charger-card.charger-power-low {
  border-left: 6px solid #d92d20;
}

.charger-card.charger-power-good {
  border-left: 6px solid #14804a;
}

.charger-card.charger-power-fast {
  border-left: 6px solid #245d8f;
}

.table-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.table-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.table-soc-input {
  width: 72px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
}

table tr.charger-power-low td:first-child {
  border-left: 5px solid #d92d20;
}

table tr.charger-power-good td:first-child {
  border-left: 5px solid #14804a;
}

table tr.charger-power-fast td:first-child {
  border-left: 5px solid #245d8f;
}

.curve-editor {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.curve-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.curve-head h3 {
  margin: 0;
  font-size: 16px;
}

.curve-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(320px, 1fr);
  gap: 12px;
  align-items: start;
}

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

.curve-table {
  min-width: 0;
  width: 100%;
}

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

.curve-table input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
}

.small-btn {
  min-height: 32px;
  padding: 6px 9px;
}

.curve-graph {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.curve-graph svg {
  width: 100%;
  height: auto;
  display: block;
}

.curve-graph .axis {
  stroke: #8b9693;
  stroke-width: 1;
}

.curve-graph .curve-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.curve-graph text {
  fill: var(--muted);
  font-size: 11px;
}

.curve-graph .axis-title {
  font-weight: 700;
}

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

.curve-graph .curve-dot {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
}

.ghost-btn {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 7px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
}
