:root {
  --bg: #f5efe6;
  --bg-strong: #efe1cf;
  --surface: #fffaf3;
  --surface-strong: #fff;
  --ink: #1f1711;
  --muted: #6e5c4d;
  --line: rgba(31, 23, 17, 0.08);
  --line-strong: rgba(31, 23, 17, 0.16);
  --brand: #ca8f45;
  --brand-deep: #8d5e20;
  --accent: #dcb27a;
  --ok: #246a4a;
  --warn: #b7611f;
  --danger: #c24343;
  --shadow: 0 14px 32px rgba(43, 29, 17, 0.08);
  --radius: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(220, 178, 122, 0.28), transparent 28%),
    radial-gradient(circle at top right, rgba(31, 23, 17, 0.06), transparent 26%),
    var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", "Noto Sans Thai", sans-serif;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

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

a {
  color: inherit;
  text-decoration: none;
}

.screen {
  min-height: 100vh;
  padding: 12px 12px calc(82px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.auth-screen {
  display: grid;
  place-items: center;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, rgba(255, 250, 243, 0.98), rgba(255, 255, 255, 0.94));
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 20px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(202, 143, 69, 0.14);
  color: var(--brand-deep);
  font-size: 12px;
  font-weight: 700;
}

.brand-badge img {
  width: 22px;
  height: 22px;
}

.auth-title,
.page-title {
  margin: 12px 0 4px;
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.auth-subtitle,
.page-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.form-stack {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.search-bar input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

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

.button,
.range-button,
.nav-item {
  border: none;
  cursor: pointer;
}

.button {
  min-height: 48px;
  border-radius: 14px;
  padding: 0 16px;
  font-weight: 700;
}

.button-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: white;
  box-shadow: 0 10px 18px rgba(141, 94, 32, 0.22);
}

.button-secondary {
  background: rgba(31, 23, 17, 0.06);
  color: var(--ink);
}

.button-danger {
  background: rgba(194, 67, 67, 0.14);
  color: var(--danger);
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.notice {
  margin-top: 16px;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.notice-error {
  background: rgba(194, 67, 67, 0.12);
  color: #8f2b2b;
}

.notice-success {
  background: rgba(36, 106, 74, 0.12);
  color: var(--ok);
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  min-width: 0;
  width: 100%;
}

.topbar {
  display: grid;
  gap: 12px;
  margin-bottom: 10px;
}

.topbar-card {
  background: linear-gradient(160deg, #241a12 0%, #4a331f 58%, #71502b 100%);
  color: #fff9f0;
  border-radius: 20px;
  padding: 12px 14px;
  box-shadow: 0 18px 34px rgba(36, 26, 18, 0.2);
  min-width: 0;
  max-width: 100%;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
}

.topbar-row > * {
  min-width: 0;
}

.topbar-meta {
  display: grid;
  gap: 4px;
}

.topbar-title {
  font-size: 13px;
  opacity: 0.78;
}

.topbar-name {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  font-size: 11px;
}

.page {
  display: grid;
  gap: 14px;
  min-width: 0;
  max-width: 100%;
}

.page-head {
  display: grid;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
  max-width: 100%;
}

.stats-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  display: grid;
  gap: 8px;
  min-height: 114px;
}

.stat-card-clickable {
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  appearance: none;
  -webkit-appearance: none;
}

.stat-card-clickable:active {
  transform: translateY(1px);
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--brand-deep);
}

.stat-meta {
  font-size: 11px;
  color: var(--brand-deep);
  overflow-wrap: anywhere;
}

.range-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.range-button {
  white-space: nowrap;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 23, 17, 0.05);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.range-button.is-active {
  background: rgba(202, 143, 69, 0.18);
  color: var(--brand-deep);
}

.chart-card {
  display: grid;
  gap: 10px;
}

.chart-title {
  font-size: 15px;
  font-weight: 700;
}

.chart-svg {
  width: 100%;
  height: 206px;
  display: block;
  overflow: visible;
}

.chart-svg [data-action] {
  cursor: pointer;
}

.chart-readout {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 23, 17, 0.06);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 700;
}

.list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.list-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  min-width: 0;
  max-width: 100%;
}

.list-item-button {
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface);
  appearance: none;
  -webkit-appearance: none;
}

.exception-item-card {
  gap: 12px;
}

.exception-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.exception-item-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 5px;
}

.exception-title-strong {
  color: var(--brand-deep);
  font-weight: 700;
}

.exception-item-summary {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(202, 143, 69, 0.12);
  color: var(--brand-deep);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 700;
}

.exception-contact-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.exception-contact-chip {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(31, 23, 17, 0.04);
  min-width: 0;
}

.exception-contact-chip strong {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-all;
}

.exception-contact-label {
  font-size: 11px;
  color: var(--muted);
}

.exception-detail-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.exception-detail-card {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(31, 23, 17, 0.04);
  min-width: 0;
}

.exception-detail-card-wide {
  grid-column: 1 / -1;
}

.exception-detail-label {
  font-size: 11px;
  color: var(--muted);
}

.exception-detail-value {
  font-size: 13px;
  line-height: 1.5;
  font-weight: 700;
  word-break: break-all;
}

.exception-scan-card {
  gap: 10px;
}

.exception-console-card .detail-value {
  font-size: 15px;
}

.stat-card-active {
  border: 1px solid rgba(202, 143, 69, 0.54);
  box-shadow: 0 10px 22px rgba(202, 143, 69, 0.2);
}

.exception-control-bar .detail-item {
  background: rgba(202, 143, 69, 0.1);
}

.exception-summary-card {
  gap: 8px;
}

.exception-row-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.exception-member-name {
  font-size: 16px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.exception-scan-row {
  gap: 6px;
}

.cleanup-run-row {
  gap: 6px;
}

.auto-fix-card {
  gap: 6px;
}

.auto-fix-card-muted {
  background: rgba(31, 23, 17, 0.03);
}

.cleanup-run-metrics {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.cleanup-run-metrics-compact .pill {
  padding: 6px 9px;
  font-size: 11px;
}

.cleanup-item-card {
  gap: 10px;
}

.cleanup-voucher-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cleanup-voucher-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 23, 17, 0.04);
}

.cleanup-voucher-entry {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(31, 23, 17, 0.14);
}

.cleanup-voucher-entry:first-of-type {
  margin-top: 2px;
  padding-top: 0;
  border-top: 0;
}

.cleanup-voucher-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.cleanup-voucher-id {
  font-size: 13px;
  font-weight: 800;
  word-break: break-all;
}

.cleanup-voucher-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.stamp-agg-card {
  gap: 10px;
}

.stamp-agg-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stamp-agg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(202, 143, 69, 0.22);
  color: var(--brand-deep);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  flex-shrink: 0;
}

.stamp-agg-head-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 4px;
}

.stamp-agg-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.stamp-agg-total {
  color: var(--brand-deep);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stamp-agg-total-manual {
  color: var(--warn);
}

.stamp-agg-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.stamp-agg-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--ink);
  flex-wrap: wrap;
}

.stamp-agg-source {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.list-row > * {
  min-width: 0;
}

.list-title {
  font-size: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.list-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.member-avatar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.member-avatar {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  object-fit: cover;
  background: rgba(202, 143, 69, 0.18);
  flex-shrink: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(31, 23, 17, 0.06);
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.pill-risk {
  background: rgba(183, 97, 31, 0.16);
  color: var(--warn);
}

.pill-ok {
  background: rgba(36, 106, 74, 0.12);
  color: var(--ok);
}

.detail-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

.detail-item {
  background: rgba(31, 23, 17, 0.03);
  border-radius: 16px;
  padding: 12px;
  min-width: 0;
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
}

.detail-value {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 700;
  word-break: break-word;
}

.section-title {
  margin: 0 0 10px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 18px;
  border-radius: 16px;
  background: rgba(31, 23, 17, 0.04);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.search-bar {
  display: flex;
  gap: 10px;
}

.search-bar input {
  flex: 1;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(245, 239, 230, 0), rgba(245, 239, 230, 0.92) 28%, rgba(245, 239, 230, 0.98));
  backdrop-filter: blur(10px);
  max-width: 100%;
  overflow-x: hidden;
}

.bottom-nav-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 8px;
  border-radius: 22px;
}

.nav-item {
  min-height: 56px;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
}

.nav-item.is-active {
  background: rgba(202, 143, 69, 0.18);
  color: var(--brand-deep);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 15, 10, 0.48);
  display: grid;
  place-items: end center;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
}

.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: min(88vh, 920px);
  overflow: auto;
  background: white;
  border-radius: 24px;
  box-shadow: 0 26px 42px rgba(20, 15, 10, 0.28);
  padding: 18px;
  min-width: 0;
}

.modal-card-sheet {
  max-width: 760px;
  max-height: min(86vh, 920px);
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-actions {
  position: sticky;
  bottom: -18px;
  margin: 12px -18px -18px;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.94) 34%, rgba(255, 255, 255, 1));
  border-top: 1px solid rgba(31, 23, 17, 0.08);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.modal-preview {
  margin-top: 12px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(202, 143, 69, 0.1);
  border: 1px solid rgba(202, 143, 69, 0.18);
}

.modal-preview strong {
  font-size: 18px;
}

.table-lite {
  display: grid;
  gap: 10px;
}

.exception-scan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.exception-scan-metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 23, 17, 0.04);
  font-size: 12px;
}

.exception-scan-metric strong {
  font-size: 14px;
  color: var(--brand-deep);
}

.table-lite-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.table-lite-row strong {
  text-align: right;
  word-break: break-word;
}

.table-lite-row-highlight {
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(202, 143, 69, 0.14);
  color: var(--brand-deep);
}

.badge-number {
  min-width: 30px;
  border-radius: 999px;
  background: rgba(202, 143, 69, 0.16);
  color: var(--brand-deep);
  display: inline-grid;
  place-items: center;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.helper-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.page-title,
.page-subtitle,
.auth-title,
.auth-subtitle,
.exception-item-summary,
.cleanup-voucher-label,
.cleanup-voucher-meta,
.cleanup-voucher-id {
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (min-width: 780px) {
  .screen {
    padding-left: 18px;
    padding-right: 18px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-grid-2 {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-svg {
    height: 220px;
  }
}

@media (max-width: 460px) {
  .exception-contact-row,
  .exception-detail-grid,
  .exception-scan-grid,
  .cleanup-voucher-grid {
    grid-template-columns: 1fr;
  }

  .modal-card {
    border-radius: 20px;
    padding: 14px;
  }

  .modal-card .auth-title {
    font-size: 20px;
    margin-top: 10px;
  }

  .modal-card .auth-subtitle {
    font-size: 12px;
  }

  .drawer-actions {
    bottom: -14px;
    margin: 10px -14px -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }

  .search-bar {
    flex-direction: column;
  }

  .search-bar .button {
    width: 100%;
  }
}

.auth-debug-panel {
  position: fixed;
  right: 12px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: min(320px, calc(100vw - 24px));
  border-radius: 16px;
  background: rgba(31, 23, 17, 0.94);
  color: #fff8ef;
  box-shadow: 0 18px 34px rgba(15, 10, 6, 0.26);
  padding: 12px;
  z-index: 80;
  pointer-events: none;
}

.auth-debug-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(255, 248, 239, 0.74);
  margin-bottom: 8px;
}

.auth-debug-grid {
  display: grid;
  gap: 8px;
}

.auth-debug-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  line-height: 1.4;
}

.auth-debug-row span {
  color: rgba(255, 248, 239, 0.72);
  flex: 0 0 88px;
}

.auth-debug-row strong {
  flex: 1;
  text-align: right;
  word-break: break-word;
  font-weight: 700;
}
