:root {
  color-scheme: light;
  --ink: #192026;
  --muted: #66717b;
  --line: #d9e0e4;
  --panel: #ffffff;
  --soft: #f5f7f8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --gold: #b7791f;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(31, 41, 55, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef3f4;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 56px);
  background: #102027;
  color: #fff;
}

.app-header h1,
.panel h2,
.detail-header h2,
.dialog-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 12px 0 0;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.82rem;
  font-weight: 750;
}

.sync-status.is-online {
  border-color: rgba(116, 216, 207, 0.58);
  color: #d6fffb;
}

.sync-status.is-warning {
  border-color: rgba(251, 191, 36, 0.7);
  color: #fff4cf;
}

.eyebrow {
  margin: 0 0 7px;
  color: #74d8cf;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.ghost,
.primary,
.icon-button,
.tab {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  min-height: 42px;
}

.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.danger {
  color: #ffd8d4;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.layout {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 34px) 40px;
}

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

.overview-heading h2 {
  margin: 0;
  font-size: 1.35rem;
}

.overview-heading .eyebrow {
  color: var(--accent-dark);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.summary-card,
.analysis-grid article,
.period-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(31, 41, 55, 0.06);
}

.summary-card {
  display: block;
  padding: 16px;
  width: 100%;
  min-height: 224px;
  text-align: left;
}

.summary-card.selectable {
  cursor: pointer;
}

.summary-card.selectable:hover,
.summary-card.selectable.active {
  border-color: var(--accent);
  background: #edf8f6;
}

.summary-card span,
.analysis-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.summary-card strong,
.analysis-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 1.45rem;
}

.summary-card dl {
  display: grid;
  gap: 7px;
  margin: 14px 0 12px;
}

.summary-card dl div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.summary-card dt,
.summary-card dd {
  margin: 0;
  font-size: 0.84rem;
}

.summary-card dt {
  color: var(--muted);
  font-weight: 750;
}

.summary-card dd {
  color: var(--ink);
  font-weight: 850;
}

.conditions {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.photo-import {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.gas-conversion {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(140px, 0.35fr) minmax(140px, 0.35fr) minmax(150px, 0.35fr);
  gap: 12px;
  align-items: end;
  margin-top: 14px;
  padding: 16px;
  border: 1px solid #cfe4e1;
  border-radius: 8px;
  background: #eef8f6;
}

.gas-conversion[hidden] {
  display: none;
}

.gas-conversion h3 {
  margin: 0;
  font-size: 1rem;
}

.gas-conversion p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--muted);
}

.conversion-result {
  display: grid;
  gap: 7px;
}

.conversion-result span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.conversion-result strong {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid #cfd8dc;
  border-radius: 7px;
  background: #fff;
}

.photo-import h3 {
  margin: 0;
  font-size: 1rem;
}

.photo-import p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--muted);
}

.photo-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.photo-button {
  min-height: 42px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.photo-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.hidden-control {
  display: none;
}

.photo-result {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.photo-result[hidden] {
  display: none;
}

.photo-result img {
  width: 180px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.ocr-candidates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-key-setup {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #cfe4e1;
  border-radius: 8px;
  background: #eef8f6;
}

.ai-key-setup[hidden] {
  display: none;
}

.candidate-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.candidate-button.active {
  border-color: var(--accent);
  background: #e8f6f4;
  color: var(--accent-dark);
}

.photo-assist-card {
  display: grid;
  gap: 14px;
  width: min(1120px, calc(100vw - 28px));
  padding: 18px;
}

.photo-assist-header,
.photo-assist-tools,
.photo-assist-entry {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.photo-assist-header h2 {
  margin: 0;
}

.photo-assist-tools label,
.photo-assist-entry label {
  min-width: 170px;
}

.photo-assist-stage {
  position: relative;
  height: min(68vh, 680px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11181c;
  cursor: grab;
  touch-action: none;
}

.photo-assist-stage:active {
  cursor: grabbing;
}

.photo-assist-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center;
  transition: filter 120ms ease;
  user-select: none;
  pointer-events: none;
}

.focus-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(72%, 680px);
  height: min(24%, 180px);
  transform: translate(-50%, -50%);
  border: 2px solid #f8d24a;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  pointer-events: none;
}

.workspace {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.meters-panel {
  padding: 18px;
  position: sticky;
  top: 16px;
}

.panel-title,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-title {
  margin-bottom: 14px;
}

.icon-button {
  inline-size: 42px;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
}

.meter-list {
  display: grid;
  gap: 10px;
}

.meter-card {
  width: 100%;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.meter-card.active {
  border-color: var(--accent);
  background: #e8f6f4;
}

.meter-card strong,
.meter-card span {
  display: block;
}

.meter-card span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
}

.detail-panel {
  padding: 22px;
  min-width: 0;
}

#active-unit {
  margin: 5px 0 0;
  color: var(--muted);
}

.context-note {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 48rem;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: min(420px, 100%);
}

.tab {
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(31, 41, 55, 0.08);
}

.tab-panel {
  display: none;
  margin-top: 22px;
}

.tab-panel.active {
  display: block;
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 16px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tariff-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(250px, 0.9fr) minmax(150px, 0.6fr) minmax(250px, 0.9fr) minmax(250px, 0.9fr) auto;
  align-items: end;
}

.payment-form {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
}

.form-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
}

.date-pair {
  min-width: 230px;
}

.price-pair {
  min-width: 240px;
}

.price-binding-field {
  min-width: 150px;
}

.water-tariff-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border: 1px solid #cfe4e1;
  border-radius: 8px;
  background: #eef8f6;
}

.water-tariff-fields[hidden] {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  height: 42px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #cfd8dc;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}

.primary {
  padding: 0 16px;
  height: 42px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
}

.primary:hover,
.icon-button:hover {
  background: var(--accent-dark);
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

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

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

th {
  background: #f8fafb;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

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

.row-action {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 850;
}

.muted {
  color: var(--muted);
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.analysis-grid article {
  padding: 18px;
}

.period-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.period-item {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  align-items: center;
}

.period-item small {
  color: var(--muted);
}

dialog {
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  width: min(440px, calc(100vw - 28px));
  padding: 22px;
}

.dialog-card .eyebrow {
  color: var(--accent-dark);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-actions .ghost {
  background: var(--soft);
  color: var(--ink);
  border-color: var(--line);
}

@media (max-width: 980px) {
  .meters-panel {
    position: static;
  }

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

  .detail-header,
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    width: 100%;
  }

  .entry-form,
  .tariff-form,
  .payment-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .photo-import,
  .photo-result,
  .gas-conversion {
    grid-template-columns: 1fr;
  }

  .form-pair,
  .water-tariff-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .summary-strip,
  .analysis-grid,
  .entry-form,
  .tariff-form,
  .payment-form,
  .form-pair,
  .water-tariff-fields,
  .period-item {
    grid-template-columns: 1fr;
  }

  .layout {
    padding-inline: 10px;
  }

  .detail-panel,
  .meters-panel {
    padding: 14px;
  }

  .tabs {
    grid-template-columns: 1fr;
  }

  .photo-controls {
    justify-content: stretch;
  }

  .photo-controls > * {
    width: 100%;
  }

  .ai-key-setup {
    grid-template-columns: 1fr;
  }

  .photo-result img {
    width: 100%;
  }

  .photo-assist-stage {
    height: 58vh;
  }
}
