/*
  Visual Hierarchy Processing Speed
  1. Shapes / Icons  — primary recognition (Gestalt chunks)
  2. Colors          — emotional cue (limbic)
  3. Text            — logical decode last (Wernicke)
*/

:root {
  --ink: #1a2433;
  --ink-soft: #5a6578;
  --paper: #f7f4ef;
  --surface: rgba(255, 252, 248, 0.92);
  --line: #d8d0c4;

  /* Semantic color — felt before read */
  --signal: #c45c26;          /* action / attention */
  --signal-deep: #9a4118;
  --trust: #2a6f6b;           /* calm input / focus */
  --trust-soft: #d7ebe8;
  --ok: #1f7a4d;
  --ok-bg: #e4f5eb;
  --warn: #b42318;
  --warn-bg: #fde8e6;

  --shape-size: 44px;
  --radius-field: 16px;
  --font-display: "Be Vietnam Pro", "Sarabun", sans-serif;
  --font-body: "Sarabun", "Be Vietnam Pro", sans-serif;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  position: relative;
  overflow-x: hidden;
}

/* Atmosphere: shape + color plane before any text */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 45% at 50% -10%, rgba(196, 92, 38, 0.14), transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 80%, rgba(42, 111, 107, 0.12), transparent 50%),
    radial-gradient(ellipse 40% 35% at 0% 60%, rgba(196, 92, 38, 0.06), transparent 45%),
    linear-gradient(165deg, #f3efe8 0%, var(--paper) 45%, #ebe6dc 100%);
}
.atmosphere::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg width='48' height='48' viewBox='0 0 48 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 24h48M24 0v48' stroke='%23c4b8a8' stroke-width='0.6' fill='none'/%3E%3C/svg%3E");
  mask-image: linear-gradient(180deg, rgba(0,0,0,.5), transparent 70%);
}

.page-shell {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 40px 20px 64px;
}

.page-shell--wide {
  width: min(100%, 1100px);
}

.login-surface form {
  display: grid;
  gap: 14px;
}

.login-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 252, 248, 0.85);
  border: 1px solid rgba(216, 208, 196, 0.8);
}

.login-user {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.logout-btn {
  border: 0;
  border-radius: 10px;
  min-height: 36px;
  padding: 0 12px;
  background: #efeae2;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.logout-btn:hover {
  background: #f6e6db;
  color: var(--signal-deep);
}

/* ——— 1. SHAPE: brand mark leads the viewport ——— */
.brand-block {
  text-align: center;
  margin-bottom: 20px;
  animation: rise-in 0.55s ease both;
}

.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: var(--signal);
  animation: mark-pop 0.7s cubic-bezier(.2, .8, .2, 1) both;
}

.brand-icon {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 8px 16px rgba(196, 92, 38, 0.22));
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4.5vw, 2.15rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-sub {
  margin: 8px 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-weight: 400;
}

/* ——— Back to menu ——— */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--ink-soft);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  transition: color 0.18s ease;
}

.back-link:hover {
  color: var(--signal-deep);
}

.back-shape {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(255, 252, 248, 0.9);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.back-shape svg {
  width: 16px;
  height: 16px;
}

.back-link:hover .back-shape {
  background: #fff7f1;
  border-color: rgba(196, 92, 38, 0.35);
  color: var(--signal);
}

/* ——— menu.html: Shape → Color → Text ——— */
.menu-container {
  padding: 22px !important;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.menu-btn {
  display: grid;
  grid-template-columns: 56px 1fr 28px;
  align-items: center;
  gap: 14px;
  padding: 18px 18px;
  border-radius: 18px;
  text-decoration: none;
  color: #fff;
  transition: transform 0.18s ease, box-shadow 0.2s ease;
}

.menu-btn:hover {
  transform: translateY(-2px);
}

.menu-btn:active {
  transform: translateY(0);
}

.menu-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

.menu-icon svg {
  width: 28px;
  height: 28px;
}

.menu-text {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.menu-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.25;
}

.menu-desc {
  font-size: 0.88rem;
  opacity: 0.88;
  font-weight: 400;
}

.menu-arrow {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  opacity: 0.85;
}

.menu-arrow svg {
  width: 18px;
  height: 18px;
}

.menu-form {
  background: linear-gradient(135deg, var(--signal) 0%, var(--signal-deep) 100%);
  box-shadow: 0 10px 24px rgba(196, 92, 38, 0.28);
}

.menu-form:hover {
  box-shadow: 0 14px 30px rgba(196, 92, 38, 0.36);
}

.menu-history {
  background: linear-gradient(135deg, #2a6f6b 0%, #1f5754 100%);
  box-shadow: 0 10px 24px rgba(42, 111, 107, 0.28);
}

.menu-history:hover {
  box-shadow: 0 14px 30px rgba(42, 111, 107, 0.36);
}

/* ——— Form surface: interaction container ——— */
.form-surface {
  background: var(--surface);
  border: 1px solid rgba(216, 208, 196, 0.7);
  border-radius: 24px;
  padding: 28px 24px 24px;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 40px rgba(26, 36, 51, 0.08);
  animation: rise-in 0.65s ease 0.08s both;
}

/* ——— History list ——— */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.history-filters {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 252, 248, 0.92);
  border: 1px solid rgba(216, 208, 196, 0.8);
}

.history-filters[hidden] {
  display: none !important;
}

.history-filter-row {
  display: flex;
  align-items: flex-start;
  gap: 10px 14px;
}

.history-filter-label {
  flex: 0 0 42px;
  padding-top: 8px;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.history-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.history-filter-chip {
  border: 1px solid rgba(216, 208, 196, 0.95);
  border-radius: 999px;
  min-height: 34px;
  padding: 6px 12px;
  background: #fff;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.history-filter-chip:hover {
  border-color: var(--signal);
  color: var(--signal-deep);
}

.history-filter-chip.is-active {
  border-color: var(--signal);
  background: linear-gradient(135deg, var(--signal) 0%, var(--signal-deep) 100%);
  color: #fff;
}

.history-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.history-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid rgba(216, 208, 196, 0.85);
  border-radius: 16px;
  background: rgba(255, 252, 248, 0.8);
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.history-nav-shape {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #efeae2;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.history-nav-shape svg {
  width: 18px;
  height: 18px;
}

.history-nav-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.history-nav-title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: inherit;
}

.history-nav-count {
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.85;
}

.history-nav-item.is-active {
  color: var(--signal-deep);
  border-color: rgba(196, 92, 38, 0.35);
  background: #fff7f1;
  box-shadow: 0 6px 16px rgba(196, 92, 38, 0.12);
}

.history-nav-item.is-active .history-nav-shape {
  color: #fff;
  background: var(--signal);
}

.accept-btn {
  margin-top: 8px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #2a6f6b 0%, #1f5754 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(42, 111, 107, 0.22);
}

.accept-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.accept-shape {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
}

.accept-shape svg {
  width: 14px;
  height: 14px;
}

.accept-btn.is-loading .accept-shape {
  animation: spin 0.8s linear infinite;
}

.analyze-btn {
  margin-top: 0;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--signal) 0%, var(--signal-deep) 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(196, 92, 38, 0.22);
}

.analyze-btn .accept-shape {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.analyze-btn .accept-shape svg {
  width: 14px;
  height: 14px;
}

.analyze-btn--production {
  background: linear-gradient(135deg, #3d6e8c 0%, #2b5268 100%);
  box-shadow: 0 8px 18px rgba(43, 82, 104, 0.22);
}

.analyze-btn--maintenance {
  background: linear-gradient(135deg, #6b5a3e 0%, #4f432f 100%);
  box-shadow: 0 8px 18px rgba(79, 67, 47, 0.22);
}

.qa-result {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #e8f4f2;
  border: 1px solid #c7e2dd;
}

.qa-result--production {
  background: #e8f0f5;
  border-color: #c5d7e3;
}

.qa-result--production .qa-result-label {
  color: #2b5268;
}

.qa-result--maintenance {
  background: #f3eee6;
  border-color: #ddd0bc;
}

.qa-result--maintenance .qa-result-label {
  color: #4f432f;
}

.qa-result-label {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  color: #1f5754;
}

.qa-result-text {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #24363a;
  white-space: pre-wrap;
}

.qa-result-text + .qa-result-text {
  margin-top: 6px;
}

.qa-result-time {
  margin: 8px 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.analysis-collapse {
  margin-top: 4px;
  border: 1px solid rgba(216, 208, 196, 0.85);
  border-radius: 14px;
  background: rgba(255, 252, 248, 0.92);
  overflow: hidden;
}

.analysis-collapse-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  user-select: none;
}

.analysis-collapse-summary::-webkit-details-marker {
  display: none;
}

.analysis-collapse-hint {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

.analysis-collapse-hint::after {
  content: "ย่ออยู่";
}

.analysis-collapse[open] .analysis-collapse-hint {
  color: var(--trust);
}

.analysis-collapse[open] .analysis-collapse-hint::after {
  content: "ขยายแล้ว";
}

.analysis-collapse-body {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.print-report-btn {
  margin-top: 0;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #1f5754 0%, #164542 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(31, 87, 84, 0.22);
}

.print-report-btn .accept-shape {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.print-report-btn .accept-shape svg {
  width: 14px;
  height: 14px;
}

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

.qa-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
}

.qa-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 36, 51, 0.45);
  backdrop-filter: blur(3px);
}

.qa-modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  max-height: min(92vh, 720px);
  overflow: auto;
  background: #fffdf9;
  border-radius: 20px;
  padding: 22px 18px 16px;
  box-shadow: 0 20px 40px rgba(26, 36, 51, 0.2);
  border: 1px solid rgba(216, 208, 196, 0.8);
}

.qa-modal-head {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.qa-modal-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--signal-deep);
  background: #f6e6db;
}

.qa-modal-icon svg {
  width: 22px;
  height: 22px;
}

.qa-modal-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.35;
}

.qa-modal-sub {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.qa-modal-card label {
  display: block;
  margin-bottom: 6px;
}

.analysis-na-option {
  display: flex !important;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(216, 208, 196, 0.85);
  background: rgba(255, 252, 248, 0.92);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}

.analysis-na-option input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--signal);
  cursor: pointer;
}

.qa-modal-card textarea {
  width: 100%;
  min-height: 88px;
  margin-bottom: 14px;
}

.qa-modal-card textarea:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  background: #efeae2;
}

#qaSingleFields textarea {
  min-height: 120px;
}

.qa-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 8px;
}

.qa-cancel,
.qa-submit {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
}

.qa-cancel {
  background: #efeae2;
  color: var(--ink-soft);
}

.qa-submit {
  background: linear-gradient(135deg, var(--signal) 0%, var(--signal-deep) 100%);
  color: #fff;
}

.qa-submit:disabled {
  opacity: 0.7;
  cursor: wait;
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}

.refresh-btn:hover {
  border-color: var(--trust);
  color: var(--trust);
  background: var(--trust-soft);
}

.refresh-shape {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
}

.refresh-shape svg {
  width: 16px;
  height: 16px;
}

.refresh-btn.is-loading .refresh-shape {
  animation: spin 0.8s linear infinite;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-list.is-grouped {
  gap: 22px;
}

.history-month-group {
  display: grid;
  gap: 10px;
}

.history-month-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 2px;
  border-bottom: 1px solid rgba(216, 208, 196, 0.85);
}

.history-month-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  text-transform: capitalize;
}

.history-month-count {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
}

.history-month-list {
  display: grid;
  gap: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border-radius: var(--radius-field);
  border: 1px solid rgba(216, 208, 196, 0.7);
  background: rgba(255, 255, 255, 0.7);
  animation: rise-in 0.4s ease both;
}

.history-media {
  display: grid;
  place-items: start;
}

.history-media-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  width: calc(var(--shape-size) * 2 + 6px);
  max-width: 100%;
}

.history-media-stack .history-thumb-wrap {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.history-media-stack .history-thumb-wrap:only-child {
  grid-column: 1 / -1;
}

.history-actions {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.history-item:nth-child(2) { animation-delay: 0.04s; }
.history-item:nth-child(3) { animation-delay: 0.08s; }
.history-item:nth-child(4) { animation-delay: 0.12s; }

.history-shape {
  width: var(--shape-size);
  height: var(--shape-size);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #a35a1e;
  background: #f6e6db;
  flex-shrink: 0;
}

.history-shape svg {
  width: 22px;
  height: 22px;
}

.history-body {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.history-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.history-subject {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge-pending {
  color: #9a4118;
  background: #f6e6db;
}

.badge-done {
  color: var(--ok);
  background: var(--ok-bg);
}

.badge-progress {
  color: #2a6f6b;
  background: var(--trust-soft);
}

.history-facts {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 252, 248, 0.95);
  border: 1px solid rgba(216, 208, 196, 0.75);
}

.history-fact {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.history-fact--wide,
.history-fact--problem {
  grid-column: 1 / -1;
}

.history-fact dt {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}

.history-fact dd {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  word-break: break-word;
}

.history-fact--problem {
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px dashed rgba(216, 208, 196, 0.9);
}

.history-fact--problem dd {
  font-size: 1.05rem;
  font-weight: 700;
  color: #8a3d14;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.history-meta span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.meta-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #c4b8a8;
}

.history-details {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: #3d4658;
  white-space: pre-wrap;
  word-break: break-word;
}

.history-empty {
  text-align: center;
  padding: 36px 16px 28px;
}

.history-empty[hidden] { display: none; }

.empty-shape {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: #efeae2;
}

.empty-shape svg {
  width: 28px;
  height: 28px;
}

.empty-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}

.empty-sub {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

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

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

/* Field unit: Shape column first, then text/input */
.field {
  display: grid;
  grid-template-columns: var(--shape-size) 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-radius: var(--radius-field);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.55);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.field:focus-within {
  border-color: var(--trust);
  background: #fff;
  box-shadow: 0 0 0 3px var(--trust-soft);
}

.field:focus-within .field-shape {
  color: var(--trust);
  background: var(--trust-soft);
  transform: scale(1.04);
}

.field-shape {
  width: var(--shape-size);
  height: var(--shape-size);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: #efeae2;
  flex-shrink: 0;
  transition: color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.field-shape svg {
  width: 22px;
  height: 22px;
}

/* Soft accent tints — color reads before label */
.accent-date { color: #3d5a80; background: #e4ebf4; }
.accent-area { color: #c45c26; background: #f6e6db; }
.accent-product { color: #2a6f6b; background: #e0efed; }
.accent-lot { color: #6b5b4f; background: #ebe4db; }
.accent-qty { color: #3d5a80; background: #e4ebf4; }
.accent-image { color: #8a4b9a; background: #f3e8f7; }
.accent-details { color: #9a4118; background: #f6e6db; }
.accent-customer { color: #2a6f6b; background: #e0efed; }
.accent-shop { color: #8a5a2b; background: #f3e8d8; }
.accent-district { color: #3d5a80; background: #e4ebf4; }
.accent-phone { color: #2a6f6b; background: #e0efed; }
.accent-email { color: #3d5a80; background: #e4ebf4; }
.accent-subject { color: #c45c26; background: #f6e6db; }

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--signal);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 6px 14px rgba(196, 92, 38, 0.22);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn.danger {
  background: #c0364a;
  box-shadow: 0 6px 14px rgba(192, 54, 74, 0.2);
}

.lot-list {
  display: grid;
  gap: 8px;
}

.field-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

.lot-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.lot-fields {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 8px;
  min-width: 0;
}

.lot-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.lot-mini-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.section-head {
  display: grid;
  grid-template-columns: var(--shape-size) 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 4px;
  padding: 4px 4px 0;
}

.section-shape {
  width: var(--shape-size);
  height: var(--shape-size);
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.section-shape svg {
  width: 22px;
  height: 22px;
}

.section-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.section-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.image-preview-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

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

.image-preview-item {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
}

.image-preview-card {
  position: relative;
}

.image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(192, 54, 74, 0.92);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.thumb-count {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 22px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(26, 36, 51, 0.8);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.history-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 72px));
  gap: 8px;
  justify-content: start;
  margin-top: 2px;
}

.history-gallery a {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 1;
}

.history-gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-drop {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.file-drop:hover {
  border-color: var(--trust);
  background: var(--trust-soft);
  color: var(--trust);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  height: auto;
  border: 0;
  padding: 0;
}

.file-drop-text {
  pointer-events: none;
  text-align: center;
  word-break: break-all;
}

.history-thumb-wrap {
  position: relative;
  width: var(--shape-size);
  height: var(--shape-size);
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  display: block;
  border: 1px solid var(--line);
  background: #efeae2;
}

.history-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.field-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.optional {
  font-weight: 400;
  color: var(--ink-soft);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.18s ease;
}

input {
  height: 48px;
  padding: 0 14px;
}

select {
  height: 48px;
  padding: 0 40px 0 14px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M7 10l5 5 5-5' stroke='%235a6578' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  cursor: pointer;
}

select:disabled {
  opacity: 0.7;
  cursor: wait;
}

textarea {
  min-height: 120px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.45;
}

input::placeholder,
textarea::placeholder {
  color: #9aa3b2;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--trust);
}

input:disabled,
input[readonly] {
  background: #f3efe8;
  color: var(--ink);
  cursor: default;
}


/* ——— CTA: shape + signal color before word ——— */
.cta {
  margin-top: 6px;
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 22px;
  background: linear-gradient(135deg, var(--signal) 0%, var(--signal-deep) 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(196, 92, 38, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.cta:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(196, 92, 38, 0.34);
}

.cta:active:not(:disabled) {
  transform: translateY(0);
}

.cta:disabled {
  opacity: 0.72;
  cursor: wait;
  transform: none;
}

.cta-shape {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: grid;
  place-items: center;
}

.cta-shape svg {
  width: 16px;
  height: 16px;
}

.cta.is-loading .cta-shape {
  animation: spin 0.8s linear infinite;
}

.cta.is-loading .cta-shape svg {
  display: none;
}

.cta.is-loading .cta-shape::after {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
}

/* ——— Status: color + glyph first, then sentence ——— */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  animation: status-in 0.35s ease both;
}

.status[hidden] { display: none; }

.status-shape {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: currentColor;
  mask-size: 16px 16px;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: 16px 16px;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.status.success {
  color: var(--ok);
  background: var(--ok-bg);
}

.status.success .status-shape {
  background: var(--ok);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M5 12.5 10 17.5 19 7' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M5 12.5 10 17.5 19 7' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.status.error {
  color: var(--warn);
  background: var(--warn-bg);
}

.status.error .status-shape {
  background: var(--warn);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M12 7v6.5M12 17.5h.01' stroke='black' stroke-width='2.4' stroke-linecap='round'/%3E%3Ccircle cx='12' cy='12' r='9' stroke='black' stroke-width='2'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M12 7v6.5M12 17.5h.01' stroke='black' stroke-width='2.4' stroke-linecap='round'/%3E%3Ccircle cx='12' cy='12' r='9' stroke='black' stroke-width='2'/%3E%3C/svg%3E");
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes mark-pop {
  0%   { opacity: 0; transform: scale(0.7); }
  70%  { transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes status-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 620px) {
  .page-shell { padding: 28px 14px 48px; }
  .form-surface { padding: 20px 14px 18px; border-radius: 20px; }
  .field-row { grid-template-columns: 1fr; }
  .field,
  .history-item {
    grid-template-columns: 40px 1fr;
    gap: 10px;
    padding: 10px;
  }
  .field-shape,
  .history-shape,
  .history-thumb-wrap { width: 40px; height: 40px; border-radius: 12px; }
  .history-media-stack {
    width: 86px;
    gap: 4px;
  }
  .history-media-stack .history-thumb-wrap {
    width: 100%;
    height: auto;
  }
  .history-facts {
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 10px 12px;
  }
  .brand-mark { width: 64px; height: 64px; }
  .brand-icon { width: 56px; height: 56px; }
  .menu-btn {
    grid-template-columns: 48px 1fr 24px;
    gap: 12px;
    padding: 16px 14px;
  }
  .menu-icon { width: 48px; height: 48px; border-radius: 14px; }
  .menu-icon svg { width: 24px; height: 24px; }
  .menu-title { font-size: 1.05rem; }
  .lot-fields { grid-template-columns: 1fr; }
}

/* Desktop history layout */
@media (min-width: 900px) {
  .page-shell--wide {
    width: min(100% - 48px, 1440px);
    padding: 32px 24px 72px;
  }

  .page-history .history-header h2 {
    font-size: 1.1rem;
  }

  .page-history .history-topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
  }

  .page-history .history-topbar .back-link {
    margin-bottom: 0;
  }

  .page-history .history-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    margin-bottom: 0;
  }

  .page-history .history-brand .brand-mark {
    margin: 0;
    width: 56px;
    height: 56px;
  }

  .page-history .history-brand .brand-icon {
    width: 48px;
    height: 48px;
  }

  .page-history .history-brand-text .brand-title {
    font-size: 1.85rem;
  }

  .page-history .history-brand-text .brand-sub {
    margin-top: 2px;
  }

  .page-history .history-nav {
    grid-template-columns: 1fr 1fr;
    margin-bottom: 18px;
  }

  .page-history .history-nav-item {
    min-height: 64px;
    padding: 12px 18px;
  }

  .page-history .history-panel {
    padding: 28px 32px 28px;
  }

  .page-history .history-filters {
    padding: 14px 16px;
    margin-bottom: 18px;
  }

  .page-history .history-filter-label {
    flex-basis: 48px;
    font-size: 0.88rem;
  }

  .page-history .history-filter-chip {
    min-height: 36px;
    padding: 7px 14px;
    font-size: 0.88rem;
  }

  .page-history .history-list {
    gap: 14px;
  }

  .page-history .history-item {
    grid-template-columns: 168px minmax(0, 1fr) minmax(280px, 340px);
    gap: 24px;
    padding: 22px 24px;
    align-items: stretch;
  }

  .page-history .history-body {
    gap: 14px;
  }

  .page-history .history-subject {
    font-size: 1.28rem;
  }

  .page-history .history-facts {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px 18px;
    padding: 16px 18px;
  }

  .page-history .history-fact--wide {
    grid-column: span 2;
  }

  .page-history .history-fact--problem {
    grid-column: 1 / -1;
  }

  .page-history .history-fact dt {
    font-size: 0.78rem;
  }

  .page-history .history-fact dd {
    font-size: 1.02rem;
  }

  .page-history .history-fact--problem dd {
    font-size: 1.18rem;
  }

  .page-history .history-actions {
    grid-column: auto;
    align-content: start;
    padding-top: 2px;
    gap: 10px;
  }

  .page-history .history-actions .accept-btn,
  .page-history .history-actions .analyze-btn,
  .page-history .history-actions .print-report-btn {
    margin-top: 0;
    width: 100%;
  }

  .page-history .history-actions {
    min-width: 0;
  }

  .page-history .history-media-stack {
    width: 168px;
    gap: 8px;
  }

  .page-history .history-thumb-wrap,
  .page-history .history-shape {
    width: 168px;
    height: 168px;
    border-radius: 16px;
  }

  .page-history .history-media-stack .history-thumb-wrap {
    width: 100%;
    height: auto;
  }

  .page-history .history-shape svg {
    width: 36px;
    height: 36px;
  }

  .page-history .history-empty {
    padding: 64px 32px;
  }

  .page-history .qa-modal-card {
    width: min(100%, 560px);
  }
}

@media (min-width: 1280px) {
  .page-shell--wide {
    width: min(100% - 64px, 1560px);
  }

  .page-history .history-item {
    grid-template-columns: 180px minmax(0, 1fr) minmax(300px, 360px);
    gap: 28px;
    padding: 24px 26px;
  }

  .page-history .history-media-stack {
    width: 180px;
  }

  .page-history .history-thumb-wrap,
  .page-history .history-shape {
    width: 180px;
    height: 180px;
  }

  .page-history .history-media-stack .history-thumb-wrap {
    width: 100%;
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

