:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --panel: #ffffff;
  --ink: #1e2722;
  --muted: #64706a;
  --line: #dbe2da;
  --brand: #177245;
  --brand-dark: #0f5634;
  --accent: #f0b429;
  --danger: #bd3b31;
  --soft-green: #e8f5ee;
  --soft-yellow: #fff7df;
  --shadow: 0 18px 55px rgba(31, 47, 38, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eef5ef 0%, var(--bg) 45%, #ffffff 100%);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.public-note {
  display: grid;
  gap: 8px;
  width: min(360px, 100%);
  margin-left: auto;
}

.public-note label {
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
}

.public-note textarea {
  min-height: 118px;
  resize: vertical;
}

.public-note-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

body:not(.is-admin) .hero-actions {
  display: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(32px, 4vw, 54px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.subhead {
  max-width: 660px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.hero-actions,
.row-actions,
.toolbar,
.backup-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-button,
.primary-button,
.text-button,
.small-button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.file-button {
  cursor: pointer;
}

#importFile {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--soft-yellow);
  color: #7a5200;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.mode-pill.admin {
  background: var(--soft-green);
  color: var(--brand-dark);
}

.admin-login {
  margin: 18px 0 0;
}

.login-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 320px) 140px;
  align-items: end;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 35px rgba(31, 47, 38, 0.08);
}

.login-form h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

.login-form p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.login-button {
  height: 44px;
}

.login-error {
  grid-column: 2 / -1;
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.summary-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.summary-card strong {
  display: block;
  font-size: 26px;
}

.summary-card.accent {
  background: var(--soft-green);
  border-color: #bde5cd;
}

.summary-card.warning {
  background: var(--soft-yellow);
  border-color: #f4daa0;
}

.workbench {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-tools,
.order-form,
.order-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 35px rgba(31, 47, 38, 0.08);
}

.admin-tools {
  display: grid;
  gap: 16px;
  padding: 22px;
  position: sticky;
  top: 16px;
}

.order-form {
  display: grid;
  gap: 16px;
  padding: 0;
  border: 0;
  box-shadow: none;
}

.backup-actions {
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 96px;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 114, 69, 0.14);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.image-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 12px;
  align-items: end;
}

.paste-box {
  display: grid;
  align-content: center;
  min-height: 68px;
  padding: 10px;
  border: 1px dashed var(--brand);
  border-radius: 6px;
  background: var(--soft-green);
  color: var(--brand-dark);
  cursor: pointer;
  text-align: center;
}

.paste-box:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 114, 69, 0.18);
}

.paste-box strong,
.paste-box span {
  display: block;
}

.paste-box strong {
  font-size: 14px;
}

.paste-box span {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.check-line input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--brand);
}

.image-preview {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf8;
}

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

.image-preview img {
  width: 100%;
  max-height: 220px;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
}

.primary-button {
  width: 100%;
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.text-button {
  min-height: auto;
  padding: 8px 0;
  background: transparent;
  color: var(--brand);
}

.order-panel {
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(460px, 100%);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.search-box span {
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.search-box input {
  border: 0;
  box-shadow: none;
  padding-inline: 0;
}

.search-box input:focus {
  box-shadow: none;
}

.toolbar select {
  width: 180px;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 15px;
  font-weight: 400;
  text-transform: none;
  white-space: nowrap;
}

td {
  line-height: 1.45;
}

.order-code,
.tracking-code,
.product-name {
  font-weight: 400;
}

.order-date {
  white-space: nowrap;
}

.product-name {
  max-width: 180px;
  word-break: break-word;
}

.note-cell {
  max-width: 240px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.image-cell {
  width: 104px;
}

.order-thumb-button {
  display: inline-flex;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: zoom-in;
  overflow: hidden;
}

.order-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 28, 22, 0.76);
}

.image-modal[hidden] {
  display: none !important;
}

.image-modal img {
  max-width: min(96vw, 1100px);
  max-height: 90vh;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.35);
  object-fit: contain;
}

.image-modal-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

body.modal-open {
  overflow: hidden;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.status-paid {
  background: var(--soft-green);
  color: var(--brand-dark);
}

.status-unpaid {
  background: var(--soft-yellow);
  color: #8a5a00;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  background: #eef2ef;
  color: var(--ink);
}

.small-button.delete {
  background: #fbe9e7;
  color: var(--danger);
}

.empty-state {
  display: none;
  padding: 52px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 20px;
}

body:not(.is-admin) .admin-only {
  display: none;
}

body:not(.is-admin) .workbench {
  grid-template-columns: 1fr;
}

body.is-admin .admin-login {
  display: none;
}

@media (max-width: 900px) {
  .hero,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .public-note {
    width: 100%;
    margin-left: 0;
  }

  .hero-actions {
    flex-wrap: wrap;
  }

  .summary-grid,
  .workbench {
    grid-template-columns: 1fr;
  }

  .admin-tools {
    position: static;
  }

  .login-form {
    grid-template-columns: 1fr;
  }

  .login-error {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .hero,
  .admin-tools,
  .order-form {
    padding: 18px;
  }

  .order-form {
    padding: 0;
  }

  .summary-grid {
    gap: 10px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .image-input-row {
    grid-template-columns: 1fr;
  }

  .toolbar select {
    width: 100%;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }

  td {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 12px;
    padding: 8px 0;
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
  }

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

  .row-actions {
    flex-wrap: wrap;
  }
}
