:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #1c2330;
  --muted: #637083;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --ok: #2b8a3e;
  --ok-soft: #e9f7ec;
  --warn: #b35c00;
  --warn-soft: #fff4e0;
  --bad: #c92a2a;
  --bad-soft: #ffeceb;
  --pole-device: #3b6fd8;
  --pole-main: #e8590c;
  --pole-spare: #dfe3e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1d222c;
    --border: #2a303c;
    --text: #e6e9ef;
    --muted: #8f99aa;
    --accent: #ff7a33;
    --accent-soft: #2d1d12;
    --ok: #51cf66;
    --ok-soft: #13261a;
    --warn: #ffb347;
    --warn-soft: #2b2112;
    --bad: #ff6b6b;
    --bad-soft: #2d1616;
    --pole-device: #5b8cf0;
    --pole-main: #ff7a33;
    --pole-spare: #343b48;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand svg { color: var(--accent); fill: var(--accent); stroke: none; width: 22px; height: 22px; }
.tagline { margin: 0; color: var(--muted); font-size: 14px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 24px;
  max-width: 1280px; margin: 0 auto; padding: 24px;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
}

.panel { min-width: 0; }

/* Upload */
.dropzone {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 460px; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; overflow: hidden;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-image { border-style: solid; cursor: default; background: #000; }
.dz-empty { display: grid; justify-items: center; gap: 6px; padding: 24px; text-align: center; color: var(--muted); }
.dz-empty svg { width: 40px; height: 40px; color: var(--accent); margin-bottom: 6px; }
.dz-empty strong { color: var(--text); font-size: 16px; }
.dropzone.has-image .dz-empty { display: none; }
.preview { display: block; width: 100%; max-height: 70vh; object-fit: contain; }
[hidden] { display: none !important; }

.upload-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; margin-top: 10px; }
.file-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }

/* Single line diagram */
.sld-card { margin-top: 20px; }
.sld-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.sld-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.sld-canvas { overflow-x: auto; padding: 12px; background: #fff; }
.sld-canvas svg { display: block; margin: 0 auto; width: 100%; height: auto; min-width: 560px; fill: initial; stroke: none; }

/* Summary card */
.summary-panel { position: sticky; top: 24px; align-self: start; }
@media (max-width: 960px) { .summary-panel { position: static; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-empty { display: grid; justify-items: center; gap: 10px; padding: 48px 24px; text-align: center; color: var(--muted); }
.card-empty svg { width: 36px; height: 36px; }
.card-empty p { margin: 0; max-width: 260px; }

.card-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.card-head h2 { margin: 2px 0 4px; font-size: 20px; line-height: 1.25; }
.card-head .sub { color: var(--muted); font-size: 13px; }
.sample-note { margin-top: 8px; font-size: 12px; color: var(--warn); }

.section { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: 0; }
.section h3 { margin: 0 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }

.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.unknown { color: var(--muted); font-weight: 400; font-style: italic; }

.poles { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; }
.pole { display: grid; place-items: center; height: 34px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; background: var(--pole-spare); }
.pole.main { background: var(--pole-main); }
.pole.device { background: var(--pole-device); }
.pole.spare { color: var(--muted); }
.pole.obscured { color: var(--muted); background: repeating-linear-gradient(45deg, var(--pole-spare) 0 4px, transparent 4px 8px); border: 1px dashed var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.circuits { width: 100%; border-collapse: collapse; font-size: 13px; }
.circuits th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); padding: 0 6px 6px 0; }
.circuits td { padding: 7px 6px 7px 0; border-top: 1px solid var(--border); vertical-align: top; }
.circuits .label { font-weight: 600; }
.circuits .detail { color: var(--muted); font-size: 12px; }
.circuits .num { white-space: nowrap; }

.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip.high, .chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.medium, .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.low, .chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.edited { background: var(--accent-soft); color: var(--accent); }

/* Inline edit controls: look like text until hovered or focused */
.edit {
  font: inherit; color: inherit; background: transparent;
  border: 1px solid transparent; border-radius: 6px; padding: 2px 4px; margin-left: -5px;
  max-width: 100%;
}
.edit:hover { border-color: var(--border); background: var(--surface-2); }
.edit:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.edit::placeholder { color: var(--muted); font-style: italic; font-weight: 400; }
select.edit { cursor: pointer; padding-right: 0; }
select.edit option { color: var(--text); background: var(--surface); }
.edit-label { width: 100%; font-weight: 600; }
.edit-num { font-weight: 600; box-sizing: content-box; }
.rating-edit { display: inline-flex; align-items: center; white-space: nowrap; }
.rating-edit select.edit { margin-left: -5px; margin-right: 0; }
.rating-edit .edit-num { margin-left: 0; }
.unit { font-weight: 600; margin-left: 1px; }
.edit-rcd { font-size: 12px; color: var(--muted); }
.edit-hint { margin: -6px 0 8px; font-size: 12px; color: var(--muted); }
.section > .edit-hint:first-child { margin-top: 0; }
.edit-short { font-weight: 600; box-sizing: content-box; }
.edit-text {
  display: block; width: calc(100% + 5px); resize: none; overflow: hidden;
  font-weight: 600; line-height: 1.4;
}
.edit-title { font-size: 20px; font-weight: 700; line-height: 1.25; margin: 2px 0 4px -5px; }
.card-head .sub .edit { font-size: 13px; font-weight: 400; color: var(--muted); }
.card-head .sub .edit:focus { color: var(--text); }

.tags { display: grid; gap: 8px; }
.tag { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); }
.tag .title { font-weight: 600; font-size: 13px; }
.tag .meta { font-size: 12px; color: var(--muted); }

.notes { margin: 0; padding-left: 18px; font-size: 13px; }
.notes li + li { margin-top: 4px; }
.notes.warnings li::marker { color: var(--warn); }

/* Loading and error */
.loading { padding: 32px 20px; display: grid; gap: 12px; }
.loading .status { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.loading .muted { color: var(--muted); font-size: 13px; margin: 0; }
.error { padding: 24px 20px; display: grid; gap: 10px; }
.error strong { color: var(--bad); }
.error p { margin: 0; color: var(--muted); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .spinner, .skeleton { animation: none; }
}
