:root {
  /* Surface tokens */
  --bg: #f6f1ea;
  --surface: #fffaf3;
  --surface-strong: #f0e4d5;

  /* Text tokens (contrast-checked: text 13.1:1, muted 5.1:1 on --bg) */
  --text: #2b211b;
  --muted: #5f5346;
  --line: #dfd1c0;

  /* Brand / semantic color tokens */
  --coffee: #5b3421;
  --coffee-2: #7b4b2a;
  --espresso: #3c2415;
  --caramel: #b7833d;
  --cream: #fff7e8;
  --green: #2c4d3d;
  --green-soft: #dce7df;
  --danger: #9b3d35;
  --danger-soft: #fbe9e6;
  --success: #2c4d3d;

  /* Elevation scale (consistent across cards / sheets / modals) */
  --shadow-sm: 0 4px 14px rgba(64, 43, 26, 0.08);
  --shadow: 0 18px 48px rgba(64, 43, 26, 0.12);
  --shadow-hover: 0 22px 56px rgba(64, 43, 26, 0.18);

  /* Type scale (12 / 13 / 14 / 16 / 18 / 24 / 32 / 40) */
  --font-display: "Fraunces", "Noto Sans TC", "Segoe UI", system-ui, sans-serif;
  --font-body: "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius: 8px;
  --ease: cubic-bezier(0.2, 0.65, 0.3, 1);

  /* 4/8px spacing rhythm tokens */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

* {
  box-sizing: border-box;
}

*:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

::selection {
  background: rgba(183, 131, 61, 0.35);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--coffee-2);
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  letter-spacing: 0;
}

h1,
h2,
h3,
.brand strong,
.score {
  font-family: var(--font-display);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 250, 243, 0.9), rgba(246, 241, 234, 0.95)),
    repeating-linear-gradient(90deg, rgba(123, 75, 42, 0.035) 0 1px, transparent 1px 72px);
}

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

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

img {
  max-width: 100%;
  display: block;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input,
select,
textarea {
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--coffee-2);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(49, 84, 67, 0.28);
  border-color: var(--green);
}

label {
  display: grid;
  gap: 7px;
  color: #4a3d33;
  font-size: 0.92rem;
  font-weight: 650;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: rgba(255, 250, 243, 0.94);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand strong {
  display: block;
  color: var(--coffee);
  font-size: 1.05rem;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: var(--radius);
  border: 1px solid rgba(91, 52, 33, 0.2);
  background:
    radial-gradient(circle at 50% 34%, #f3d8ac 0 18%, transparent 19%),
    linear-gradient(160deg, #5b3421 0 46%, #315443 47% 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 250, 243, 0.5);
}

.nav {
  display: grid;
  gap: 5px;
}

.nav a,
.mobile-nav a {
  display: flex;
  align-items: center;
  min-height: 44px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
  padding: 11px 12px;
  color: #574a40;
  font-weight: 700;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease), border-color 0.15s var(--ease);
}

.nav a:hover {
  background: rgba(220, 231, 223, 0.55);
  color: var(--green);
  transform: translateX(2px);
}

.nav a:active {
  transform: translateX(0) scale(0.98);
}

.nav a.active,
.mobile-nav a.active {
  background: var(--green-soft);
  color: var(--green);
  border-left-color: var(--green);
}

.logout-form {
  margin-top: auto;
}

.main {
  padding: 28px;
  max-width: 1500px;
  width: 100%;
  animation: fade-in 0.25s var(--ease);
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 2rem;
  line-height: 1.15;
  color: var(--coffee);
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions,
.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.button-row.end {
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.ghost-button,
.map-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease), filter 0.15s var(--ease);
}

button:disabled,
.primary-button[aria-disabled="true"],
.secondary-button[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.map-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(64, 43, 26, 0.16);
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.map-button:active {
  transform: translateY(0);
  box-shadow: none;
}

.primary-button {
  background: var(--coffee);
  color: var(--cream);
}

.primary-button:hover {
  filter: brightness(1.08);
}

.secondary-button {
  background: var(--green);
  color: #f4fbf5;
}

.secondary-button:hover {
  filter: brightness(1.08);
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--coffee);
}

.ghost-button:hover {
  background: var(--surface-strong);
}

.map-button,
.map-link {
  background: #ecf4ee;
  border-color: #bdd2c3;
  color: var(--green);
  transition: background-color 0.15s var(--ease);
}

.map-button:hover,
.map-link:hover {
  background: #dcebe0;
}

.map-link {
  border-radius: 6px;
  display: inline-flex;
  padding: 6px 9px;
  font-weight: 800;
}

.full {
  width: 100%;
}

.panel,
.metric-card,
.item-card,
.empty-state,
.login-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 243, 0.96);
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease), border-color 0.2s var(--ease);
}

.metric-card:hover,
.item-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: rgba(123, 75, 42, 0.32);
}

.panel {
  padding: 20px;
}

.panel h2,
.item-card h2 {
  margin: 0 0 12px;
  color: var(--coffee);
  line-height: 1.25;
}

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

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

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

.metric-card {
  padding: 16px;
}

.metric-card span,
.summary-list span {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin: 8px 0 4px;
  color: var(--coffee);
  font-size: 1.8rem;
  line-height: 1;
}

.metric-card small,
.simple-list small {
  color: var(--muted);
}

.overview-grid,
.split-layout,
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 18px;
  margin-bottom: 18px;
}

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

.wide-panel {
  grid-column: span 1;
}

.summary-list {
  display: grid;
  gap: 14px;
}

.summary-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.summary-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.summary-list strong {
  text-align: right;
  color: var(--coffee);
}

.recent-visit {
  display: grid;
  gap: 10px;
}

.recent-visit strong {
  color: var(--coffee);
  font-size: 1.25rem;
}

.chart-canvas {
  width: 100%;
  min-height: 260px;
  height: 260px;
}

.filter-panel {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 243, 0.92);
  padding: 14px;
}

.card-grid,
.note-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.item-card,
.empty-state {
  padding: 18px;
}

.item-card-main,
.detail-hero {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.item-card h2 a:hover,
.simple-list a:hover,
td a:hover {
  color: var(--green);
}

.score {
  display: inline-flex;
  min-width: 56px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--coffee);
  font-weight: 900;
}

.score.large {
  min-width: 76px;
  min-height: 64px;
  font-size: 1.4rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0;
}

.tag-row span,
.flavor-cloud span {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: #efe0cd;
  color: #5d3d27;
  font-size: 0.82rem;
  font-weight: 800;
  transition: transform 0.15s var(--ease), background-color 0.15s var(--ease);
}

.tag-row span:hover,
.flavor-cloud span:hover {
  transform: translateY(-1px);
  background: #e6d2b8;
}

.tag-row.compact {
  margin: 0;
}

.tag-row.compact span {
  padding: 4px 8px;
  font-size: 0.78rem;
}

.detail-panel {
  display: grid;
  gap: 18px;
}

.side-stack {
  display: grid;
  gap: 18px;
  align-content: start;
}

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

.info-grid div,
.compact-info div {
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

dd {
  margin: 4px 0 0;
  color: var(--coffee);
  font-weight: 850;
}

.compact-info {
  display: grid;
  gap: 8px;
  margin: 0;
}

.note-block {
  background: #fffdf8;
  border-left: 4px solid var(--caramel);
  border-radius: var(--radius);
  padding: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.link-list,
.simple-list {
  display: grid;
  gap: 10px;
}

.link-list a,
.simple-list a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  padding: 11px 12px;
  font-weight: 800;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.link-list a:hover,
.simple-list a:hover {
  border-color: var(--green);
  background: var(--green-soft);
  transform: translateX(2px);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  border-left: 3px solid var(--green);
  background: #fffdf8;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 14px;
}

.timeline-item p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

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

.photo-grid img {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

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

.form-grid .wide {
  grid-column: 1 / -1;
}

.stack-form {
  display: grid;
  gap: 18px;
}

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

.checkbox-grid label,
.switch-line {
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  padding: 10px 12px;
  font-weight: 750;
}

.checkbox-grid input,
.switch-line input {
  width: auto;
  min-height: auto;
}

.quick-form h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.subform {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  padding: 14px;
}

.subform summary {
  cursor: pointer;
  color: var(--coffee);
  font-weight: 900;
}

.subform[open] summary {
  margin-bottom: 14px;
}

.sticky-submit {
  position: sticky;
  bottom: 16px;
  padding-top: 6px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.responsive-table {
  overflow-x: auto;
}

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

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

th {
  background: var(--surface-strong);
  color: var(--coffee);
  font-size: 0.82rem;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  background: rgba(255, 253, 248, 0.72);
  transition: background-color 0.12s var(--ease);
}

tbody tr:hover td {
  background: var(--green-soft);
}

.prose-panel {
  min-height: 420px;
}

.prose {
  line-height: 1.8;
}

.prose h1,
.prose h2,
.prose h3 {
  color: var(--coffee);
}

.prose code {
  background: var(--surface-strong);
  border-radius: 5px;
  padding: 2px 5px;
}

.prose pre {
  overflow-x: auto;
  background: #2b211b;
  color: #fff7e8;
  border-radius: var(--radius);
  padding: 14px;
}

.flavor-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.flavor-cloud span {
  background: #fffdf8;
  color: var(--tag-color);
  border: 1px solid var(--tag-color);
}

.flavor-cloud small {
  margin-left: 6px;
  color: var(--muted);
}

.export-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inline-upload {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.alert {
  border: 1px solid rgba(155, 61, 53, 0.25);
  border-radius: var(--radius);
  background: #fff0ed;
  color: var(--danger);
  padding: 12px 14px;
  font-weight: 750;
  margin-bottom: 14px;
}

.alert.success {
  border-color: rgba(49, 84, 67, 0.28);
  background: #edf6ef;
  color: var(--green);
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  justify-items: start;
  gap: 10px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  padding: 28px;
}

.login-panel h1 {
  margin: 26px 0 6px;
  color: var(--coffee);
}

.login-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.login-brand {
  align-items: center;
}

.mobile-nav {
  display: none;
}

@media (max-width: 1180px) {
  .stats-grid,
  .card-grid,
  .note-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

@media (max-width: 860px) {
  body {
    padding-bottom: 74px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 18px 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .topbar h1 {
    font-size: 1.55rem;
  }

  .stats-grid,
  .overview-grid,
  .split-layout,
  .detail-layout,
  .chart-grid,
  .card-grid,
  .note-grid,
  .filter-panel,
  .form-grid,
  .checkbox-grid,
  .rating-grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .filter-panel {
    gap: 10px;
  }

  .item-card-main,
  .detail-hero {
    align-items: stretch;
  }

  .score {
    align-self: flex-start;
  }

  .panel,
  .item-card,
  .metric-card,
  .empty-state {
    padding: 16px;
  }

  .chart-canvas {
    min-height: 230px;
    height: 230px;
  }

  .button-row,
  .export-links {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button-row a,
  .button-row button,
  .export-links a {
    width: 100%;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 8px;
    background: rgba(255, 250, 243, 0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -12px 34px rgba(64, 43, 26, 0.12);
  }

  .mobile-nav a {
    display: flex;
    justify-content: center;
    padding: 10px 6px;
    font-size: 0.82rem;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .mobile-nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--green);
  }
}

@media (max-width: 520px) {
  .top-actions {
    grid-template-columns: 1fr;
  }

  .metric-card strong {
    font-size: 1.45rem;
  }

  .summary-list div {
    display: grid;
  }

  .summary-list strong {
    text-align: left;
  }
}
