:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #596574;
  --line: #c9d1db;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #b42318;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.app {
  min-height: 100vh;
  padding: 18px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px 18px;
  align-items: end;
  max-width: 1320px;
  margin: 0 auto 16px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid #dbe2ea;
  border-radius: 8px;
}

.title-block h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.title-block p,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.offline-status {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  padding: 9px 11px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  background: #eff6ff;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.offline-status.error {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--danger);
}

.settings {
  display: flex;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #283747;
}

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

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 92px;
}

textarea.attention {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.speech-box,
.actions,
.status,
.offline-status {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #8ba0b5;
}

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

.table-shell {
  max-width: 1320px;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid #dbe2ea;
  border-radius: 8px;
  overflow: hidden;
}

.invoice-panel {
  max-width: 1320px;
  margin: 16px auto 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid #dbe2ea;
  border-radius: 8px;
}

.invoice-head,
.invoice-form,
.invoice-grid {
  display: grid;
  gap: 14px;
}

.invoice-head {
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  margin-bottom: 14px;
}

.invoice-head h2,
.invoice-grid h3 {
  margin: 0 0 4px;
}

.invoice-head h2 {
  font-size: 20px;
}

.invoice-grid h3 {
  font-size: 16px;
}

.invoice-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.invoice-form {
  grid-template-columns: minmax(180px, 320px) 1fr;
  align-items: start;
}

.invoice-actions {
  grid-column: 1 / -1;
}

.invoice-grid {
  grid-template-columns: 1fr 1fr;
  margin-top: 16px;
}

.checklist,
.invoice-list {
  display: grid;
  gap: 8px;
}

.selected-invoice-list {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.selected-invoice-card {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid #dbe2ea;
  border-radius: 6px;
  background: #fff;
}

.selected-invoice-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.selected-invoice-card button {
  min-height: 34px;
}

.check-item,
.invoice-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid #dbe2ea;
  border-radius: 6px;
  background: #fff;
}

.invoice-item {
  grid-template-columns: 72px 1fr auto;
}

.invoice-item img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: zoom-in;
}

.check-mark {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.check-mark.ok {
  background: var(--accent);
}

.check-mark.partial {
  background: #b7791f;
}

.check-mark.missing {
  background: var(--danger);
}

.item-title {
  font-weight: 700;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  padding: 10px 0;
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(8, 12, 20, 0.92);
}

.image-preview[hidden] {
  display: none;
}

.image-preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #ffffff;
}

.image-preview-stage {
  overflow: auto;
  padding: 12px;
  display: grid;
  place-items: start center;
}

.image-preview-stage img {
  max-width: none;
  width: min(1200px, 180vw);
  height: auto;
  background: #fff;
}

.table-scroll {
  overflow-x: auto;
}

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

th,
td {
  border: 1px solid #1f2933;
  padding: 7px 6px;
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
  line-height: 1.25;
  word-break: break-word;
}

th {
  background: #f8fafc;
  font-weight: 700;
}

td[contenteditable="true"] {
  background: #fff;
  cursor: text;
}

td[contenteditable="true"]:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  outline-offset: -2px;
}

tfoot td {
  font-weight: 700;
  background: #f8fafc;
}

.row-delete-button {
  min-height: 32px;
  padding: 0 10px;
  border-color: #f1b4ae;
  color: var(--danger);
}

@media (max-width: 760px) {
  .app {
    padding: 10px;
  }

  .toolbar {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .title-block h1 {
    font-size: 20px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .invoice-head,
  .invoice-form,
  .invoice-grid {
    grid-template-columns: 1fr;
  }

  .invoice-item {
    grid-template-columns: 64px 1fr;
  }

  .invoice-item button {
    grid-column: 1 / -1;
  }

  button {
    padding: 0 10px;
  }
}
