:root {
  color-scheme: light;
  --ink: #251314;
  --muted: #756266;
  --line: #ead9dc;
  --panel: #ffffff;
  --page: #fff7f4;
  --brand: #d6001c;
  --brand-dark: #a90016;
  --brand-soft: #fff0f1;
  --brand-line: #ffc8cf;
  --gold: #d99a22;
  --red: #d6001c;
  --blue: #9a1b30;
  --success: #137a54;
  --shadow: 0 20px 60px rgba(90, 18, 24, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(214, 0, 28, 0.08), rgba(255, 247, 244, 0) 360px),
    var(--page);
  color: var(--ink);
  font-family:
    Inter, "Noto Sans Thai", "PingFang SC", "Microsoft YaHei",
    "Noto Sans CJK SC", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  border: 1px solid var(--brand-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  padding: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
  color: #1f1112;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
}

.store-badge {
  display: inline-block;
  margin: 12px 0 0;
  border: 1px solid var(--brand-line);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--ink);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(150deg, rgba(214, 0, 28, 0.13), rgba(255, 255, 255, 0.62) 46%, rgba(217, 154, 34, 0.12)),
    var(--page);
}

.login-panel {
  width: min(480px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--brand-line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  padding: 30px;
  position: relative;
  overflow: hidden;
}

.login-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 6px;
  background: linear-gradient(90deg, var(--brand), #ff4054, var(--gold));
}

.login-panel h1 {
  font-size: clamp(28px, 6vw, 38px);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 112px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  min-height: 34px;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

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

h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.top-actions,
.filters,
.field-row,
.section-title,
.panel-heading {
  display: flex;
  gap: 12px;
}

.top-actions,
.section-title,
.panel-heading {
  align-items: center;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.primary-button,
.ghost-button,
.text-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
  line-height: 1.22;
}

.primary-button {
  background: linear-gradient(180deg, #e60022, var(--brand));
  color: white;
  box-shadow: 0 10px 20px rgba(214, 0, 28, 0.22);
}

.primary-button:hover {
  background: linear-gradient(180deg, #c9001b, var(--brand-dark));
}

.ghost-button {
  background: white;
  color: var(--ink);
  border-color: var(--brand-line);
}

.ghost-button:hover,
.icon-button:hover,
.password-toggle:hover {
  background: var(--brand-soft);
  border-color: #ff9aa6;
}

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

.wide {
  width: 100%;
}

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

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

.metric {
  padding: 18px;
  position: relative;
  overflow: hidden;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--brand), #ff7c82);
}

.metric span,
label span,
.computed-strip span,
.filters span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin: 8px 0 6px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
  color: var(--ink);
}

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

.metric:hover {
  transform: translateY(-1px);
  box-shadow: 0 22px 56px rgba(90, 18, 24, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.entry-panel,
.report-panel {
  padding: 22px;
  border-top: 4px solid var(--brand);
}

.entry-panel {
  position: sticky;
  top: 16px;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input[readonly] {
  background: #fff1f2;
  color: var(--ink);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(214, 0, 28, 0.13);
}

.file-picker input {
  padding: 9px;
}

.image-preview {
  display: grid;
  gap: 10px;
}

.image-preview img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.hidden {
  display: none !important;
}

textarea {
  resize: vertical;
}

.field-row {
  align-items: start;
}

.field-row > label {
  flex: 1;
  min-width: 0;
}

.section-box,
.delivery-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, #fffafa, #fff5f4);
}

.section-title {
  justify-content: space-between;
}

.section-title span {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.section-title h3 {
  color: var(--ink);
}

.platform-card {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.platform-card:first-of-type {
  border-top: none;
  padding-top: 0;
}

.platform-card h4 {
  margin: 0;
  font-size: 15px;
  color: var(--ink);
}

.three-cols {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.computed-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.computed-strip div {
  border-radius: 8px;
  background: #fff0f1;
  border: 1px solid var(--brand-line);
  padding: 12px;
}

.computed-strip strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.report-heading {
  align-items: end;
}

.report-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.filters label {
  min-width: 150px;
}

.chart-wrap {
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
  margin-bottom: 16px;
}

canvas {
  width: 100%;
  height: 100%;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

table {
  width: 100%;
  min-width: 1560px;
  border-collapse: collapse;
  background: white;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-size: 14px;
}

td {
  background: rgba(255, 255, 255, 0.78);
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff0f1;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

tbody tr:hover {
  background: #fff8f8;
}

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

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  border: 1px solid var(--brand-line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 7px 10px;
  font-weight: 700;
}

.icon-button.danger {
  color: var(--red);
  border-color: #ffc8cf;
  background: #fff8f8;
}

.profit-negative {
  color: #8a1824;
}

.profit-positive {
  color: var(--success);
}

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

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(24, 32, 39, 0.62);
  padding: 24px;
}

.image-modal-panel {
  width: min(900px, 100%);
  max-height: min(860px, 92vh);
  overflow: auto;
  border-radius: 8px;
  background: white;
  padding: 18px;
  box-shadow: var(--shadow);
}

.image-modal-panel img {
  display: block;
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.empty-state {
  display: none;
  margin: 16px 0 0;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .entry-panel {
    position: static;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 18px;
  }

  .topbar,
  .report-heading,
  .filters,
  .field-row {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-grid,
  .computed-strip,
  .three-cols {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .top-actions button {
    width: 100%;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-title span {
    text-align: left;
  }
}

@media print {
  body {
    background: white;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .top-actions,
  .entry-panel,
  .no-print,
  .chart-wrap {
    display: none !important;
  }

  .workspace {
    display: block;
  }

  .metric,
  .report-panel {
    box-shadow: none;
  }

  table {
    min-width: 0;
  }

  th,
  td {
    font-size: 9px;
    padding: 6px 4px;
  }
}
