:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-alt: #eef1e9;
  --text: #38423a;
  --muted: #67715f;
  --line: #d7d0c2;
  --accent: #4f5e49;
  --accent-strong: #38423a;
  --sage: #a8b39c;
  --khaki: #c9b79c;
  --shadow: 0 18px 45px rgba(36, 48, 42, 0.12);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(rgba(245, 241, 232, 0.82), rgba(245, 241, 232, 0.93)),
    url("https://images.unsplash.com/photo-1608571423902-eed4a5ad8108?auto=format&fit=crop&w=1800&q=80") center / cover fixed;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  min-height: calc(100vh - 48px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 4px 22px;
  border-top: 6px solid transparent;
}

body[data-role="owner"] .topbar,
body[data-role="admin"] .topbar {
  border-top-color: #d6a800;
}

body[data-role="therapist"] .topbar {
  border-top-color: #007bff;
}

body[data-role="viewer"] .topbar {
  border-top-color: #343a40;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  line-height: 1.1;
}

.brand-line {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

h2 {
  font-size: 1.05rem;
}

.topbar-actions,
.form-actions,
.report-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 460px) minmax(360px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid rgba(216, 221, 211, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel,
.report-panel,
.history-panel {
  padding: 18px;
}

.form-panel {
  display: grid;
  gap: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

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

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
  margin-top: 4px;
}

.checkbox-label span {
  line-height: 1.45;
}

.compact-checkbox {
  align-self: end;
  min-height: 42px;
}

.consent-row {
  border-color: rgba(214, 168, 0, 0.45);
  background: rgba(255, 248, 220, 0.72);
}

.client-tools {
  align-items: end;
  grid-template-columns: minmax(160px, 1fr) minmax(190px, 1.2fr) minmax(120px, 0.8fr);
}

label span,
legend {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.oil-description,
.field-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
}

.oil-description {
  padding: 10px 0 0;
  border-top: 1px solid rgba(215, 208, 194, 0.72);
}

.field-note {
  display: block;
  min-height: 1.6em;
}

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

input,
select {
  min-height: 42px;
  padding: 8px 11px;
}

textarea {
  resize: vertical;
  min-height: 82px;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 109, 87, 0.14);
}

input[readonly] {
  color: var(--accent-strong);
  background: #f8f6f0;
  font-weight: 800;
}

.oil-block {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
}

.ratio-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.formula-summary {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid rgba(79, 94, 73, 0.25);
  border-radius: 8px;
  background: #f7f5ee;
  color: var(--muted);
  line-height: 1.55;
}

.formula-summary strong {
  color: var(--accent-strong);
}

.formula-summary em {
  color: #9a4f2d;
  font-style: normal;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.secondary-link,
.icon-button,
.text-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
}

.primary-button {
  flex: 1;
  padding: 0 18px;
  color: white;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  padding: 0 16px;
  color: var(--accent-strong);
  border-color: var(--line);
  background: #fff;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  color: var(--accent-strong);
  border-color: var(--line);
  background: rgba(255, 253, 248, 0.92);
  text-decoration: none;
  white-space: nowrap;
}

.secondary-link:hover,
.secondary-button:hover {
  border-color: var(--accent);
}

.icon-button {
  width: 42px;
  color: var(--accent-strong);
  border-color: rgba(47, 109, 87, 0.26);
  background: rgba(255, 253, 248, 0.92);
  font-size: 1.2rem;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--accent-strong);
  background: transparent;
}

.status-text {
  color: var(--muted);
  font-size: 0.86rem;
}

.report-panel {
  min-height: calc(100vh - 144px);
}

.report-output {
  padding-top: 16px;
  line-height: 1.75;
  position: relative;
}

.report-output::after {
  content: "植感生活 NaturalAromaLife";
  position: absolute;
  right: 16px;
  bottom: 12px;
  color: rgba(79, 94, 73, 0.13);
  font-size: 1rem;
  font-weight: 800;
  pointer-events: none;
}

.report-output h3 {
  margin: 0 0 18px;
  font-size: 1.35rem;
}

.report-output h4 {
  margin: 22px 0 8px;
  font-size: 1.04rem;
}

.report-output p {
  margin: 7px 0;
}

.report-output ul {
  margin: 8px 0 0;
  padding-left: 1.3rem;
}

.placeholder {
  display: grid;
  place-items: center;
  min-height: 360px;
  color: var(--muted);
  text-align: center;
}

.history-panel {
  margin-top: 16px;
}

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

.history-empty {
  color: var(--muted);
  line-height: 1.6;
}

.history-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  cursor: pointer;
  list-style: none;
}

.history-group summary::-webkit-details-marker {
  display: none;
}

.history-group summary::before {
  content: "▸";
  color: var(--accent);
  font-size: 0.9rem;
  transition: transform 0.18s ease;
}

.history-group[open] summary::before {
  transform: rotate(90deg);
}

.history-group summary:hover {
  background: #f8f6f0;
}

.history-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.84rem;
}

.history-records {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.history-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 11px;
  text-align: left;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-item:hover {
  border-color: var(--accent);
}

.history-name {
  font-weight: 800;
}

.history-date {
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 800;
}

.history-meta {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.source-strip {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.5;
}

.source-strip strong {
  color: var(--accent-strong);
}

.admin-panel {
  margin-top: 16px;
  padding: 18px;
}

.admin-layout {
  display: grid;
  gap: 16px;
}

.auth-grid,
.backend-settings {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding-top: 14px;
}

.admin-controls {
  display: grid;
  gap: 14px;
  padding-top: 18px;
}

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

.user-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.user-item strong {
  color: var(--accent-strong);
}

.history-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-detail summary {
  display: grid;
  grid-template-columns: minmax(100px, 140px) 1fr;
  gap: 10px;
  padding: 11px;
  cursor: pointer;
  list-style: none;
}

.history-detail summary::-webkit-details-marker {
  display: none;
}

.history-detail summary:hover {
  background: #f8f6f0;
}

.history-report {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
  color: var(--text);
  line-height: 1.65;
}

.history-report p {
  margin: 0;
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(320px, 430px) minmax(360px, 1fr);
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .layout,
  .ratio-grid,
  .auth-grid,
  .backend-settings,
  .source-strip {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: flex-start;
  }

  .form-actions {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .secondary-link {
    width: 100%;
    justify-content: center;
  }
}
