:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #647084;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #eef2f6;
  --accent: #14756f;
  --accent-dark: #0f5f5a;
  --accent-soft: #e2f3f0;
  --good: #087f5b;
  --bad: #b42318;
  --warn: #a15c07;
  --shadow: 0 18px 45px rgba(18, 28, 45, .08);
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.shell {
  width: min(1480px, calc(100vw - 16px));
  height: calc(100vh - 12px);
  margin: 6px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
}

.topbar h1,
.logs-toolbar h2,
.item-head h2 {
  margin: 0;
  line-height: 1.12;
}

.topbar h1 { font-size: 21px; }
.logs-toolbar h2 { font-size: 14px; }
.item-head h2 {
  display: -webkit-box;
  max-height: 48px;
  overflow: hidden;
  font-size: 18px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-dot,
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--good);
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(760px, 1fr) 300px;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.tab-page { display: block; min-height: 0; }

#calculatorTab {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 8px;
  min-height: 0;
}

.scan-panel,
.item-panel,
.calc-grid,
.result-panel,
.logs-toolbar,
.message {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scan-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  border-top: 4px solid var(--accent);
  padding: 10px 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
button {
  height: 38px;
  border-radius: 7px;
  font-size: 13px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 0 11px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

button {
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

button:hover { background: var(--accent-dark); }
button:disabled { cursor: wait; opacity: .65; }

.ghost {
  width: max-content;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.ghost:hover { background: #f8fafc; }

.scan-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 106px;
  gap: 8px;
}

.scan-actions {
  display: flex;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.item-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  grid-template-rows: auto auto;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  padding: 11px;
}

.item-head {
  grid-column: 1 / 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.facts {
  grid-column: 1 / 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.facts div,
.result-panel div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
  padding: 8px 10px;
  min-width: 0;
}

.facts span,
.result-panel span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
}

.facts strong,
.result-panel strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.measurement-guide {
  display: block;
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  align-self: stretch;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.measurement-guide img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 126px;
  max-height: 126px;
  object-fit: cover;
}

.measurement-guide figcaption {
  display: none;
  min-height: 34px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.calc-grid {
  grid-column: auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 94px 98px;
  align-items: end;
  gap: 8px;
  padding: 10px 12px;
}

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

.result-panel .total-card {
  border-color: #9de8d4;
  background: #edfdf8;
}

.result-panel .total-card strong {
  color: var(--good);
  font-size: 19px;
}

.message {
  min-height: 38px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
  padding: 8px 10px;
}

.message.error {
  border-color: #fecaca;
  background: #fff5f5;
  color: var(--bad);
}

.message.good {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--good);
}

.hidden { display: none; }

.logs-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.logs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px;
}

.logs-toolbar .ghost {
  height: 32px;
  padding: 0 10px;
}

.log-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding-right: 2px;
}

.log-card {
  background: white;
  border: 1px solid var(--line);
  border-left: 4px solid #94a3b8;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .04);
  padding: 7px 8px;
}

.log-card.good,
.log-card.status-200,
.log-card.ok { border-left-color: var(--good); }

.log-card.error,
.log-card.status-400,
.log-card.status-404,
.log-card.status-429,
.log-card.running { border-left-color: var(--bad); }

.log-card span,
.log-card em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.log-card strong {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.log-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.log-card pre {
  display: none;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  color: #334155;
  font-family: Consolas, Monaco, monospace;
  font-size: 11px;
  line-height: 1.35;
  margin: 8px 0 0;
  max-height: 96px;
  overflow: auto;
  padding: 8px;
}

.log-card ol {
  display: grid;
  gap: 3px;
  margin: 6px 0 0;
  padding-left: 16px;
  max-height: 74px;
  overflow: hidden;
}

.log-card li {
  color: #334155;
  font-size: 11px;
  line-height: 1.22;
}

.log-card li.error {
  color: var(--bad);
  font-weight: 800;
}

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .log-list { max-height: 360px; }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 16px, 680px);
    margin: 8px auto;
  }

  .topbar,
  .scan-panel,
  .logs-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .scan-panel,
  .item-panel,
  .result-panel,
  .calc-grid,
  .facts,
  .scan-row {
    grid-template-columns: 1fr;
  }

  .measurement-guide,
  .item-head,
  .facts,
  .calc-grid {
    grid-column: auto;
    grid-row: auto;
  }

  .measurement-guide img { max-height: 180px; }
}
