:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-soft: #f2f5f1;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9ded7;
  --wine: #7a1f35;
  --wine-dark: #5e1728;
  --leaf: #28715b;
  --amber: #a15c1b;
  --blue: #2563a8;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(122, 31, 53, 0.08), transparent 260px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--wine);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--ink);
  line-height: 1.15;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--wine);
  font-size: 24px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--line);
}

.primary-icon {
  background: var(--wine);
  color: #fff;
  box-shadow: none;
}

.subtle-icon {
  background: #f4f5f7;
  color: var(--muted);
  box-shadow: none;
}

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

.metric {
  min-width: 0;
  min-height: 92px;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-value {
  display: block;
  overflow-wrap: anywhere;
  color: var(--wine);
  font-size: 22px;
  font-weight: 850;
  line-height: 1.15;
}

.metric-label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.view {
  display: none;
}

.ios-install-tip {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid #ead4dc;
  border-radius: 8px;
  background: #fff6f8;
}

.ios-install-tip strong,
.ios-install-tip span {
  display: block;
}

.ios-install-tip strong {
  color: var(--wine);
  font-size: 14px;
  font-weight: 850;
}

.ios-install-tip span {
  margin-top: 5px;
  color: #475467;
  font-size: 13px;
  line-height: 1.5;
}

.tip-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 20px;
  font-weight: 800;
}

.active-view {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 44px;
  margin-left: 8px;
  border: 0;
  outline: 0;
  background: transparent;
}

.text-btn,
.solid-btn,
.ghost-btn,
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 750;
  text-align: center;
}

.text-btn,
.ghost-btn {
  background: var(--surface);
  color: var(--wine);
  box-shadow: inset 0 0 0 1px var(--line);
}

.solid-btn {
  background: var(--wine);
  color: #fff;
}

.solid-btn:active,
.primary-icon:active {
  background: var(--wine-dark);
}

.filter-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #fbfcfb;
  color: var(--ink);
}

input,
select {
  height: 46px;
  padding: 0 12px;
}

textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(122, 31, 53, 0.55);
  box-shadow: 0 0 0 3px rgba(122, 31, 53, 0.12);
}

.filter-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wine-list,
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wine-card,
.history-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.wine-card {
  position: relative;
  display: grid;
  gap: 13px;
  overflow: hidden;
  text-align: left;
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.07);
}

.wine-card::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--wine), var(--leaf));
  content: "";
}

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

.wine-card button {
  text-align: inherit;
}

.wine-title-row,
.history-title-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.wine-name,
.history-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 18px;
  font-weight: 850;
  line-height: 1.25;
}

.wine-subtitle,
.history-subtitle {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.wine-subline {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin-top: 8px;
}

.wine-subline .wine-subtitle {
  margin-top: 0;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.type-red {
  background: #7a1f35;
  color: #ffffff;
}

.type-white {
  border-color: #e6d28c;
  background: #fff8d8;
  color: #7a5a12;
}

.type-sparkling {
  border-color: #b8d7d7;
  background: #e7f6f6;
  color: #286c73;
}

.type-rose {
  background: #f7d7df;
  color: #9b2747;
}

.type-sweet {
  background: #f9e7ae;
  color: #7b5511;
}

.type-fortified {
  background: #6a3a2b;
  color: #fff5ec;
}

.type-other,
.type-unknown {
  background: #eef0f3;
  color: #475467;
}

.wine-identity {
  display: grid;
  gap: 8px;
  margin-top: 13px;
}

.wine-identity-item {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid #edf0ec;
  border-radius: 8px;
  background: #fbfcfb;
}

.wine-identity-label {
  color: var(--wine);
  font-size: 12px;
  font-weight: 850;
}

.wine-identity-value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: #26323b;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.4;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill-ready {
  background: #e5f4ec;
  color: var(--leaf);
}

.pill-aging {
  background: #eaf1fb;
  color: var(--blue);
}

.pill-past {
  background: #fff0df;
  color: var(--amber);
}

.pill-unknown {
  background: #eef0f3;
  color: #475467;
}

.wine-meta,
.history-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #eef0f3;
  color: #344054;
  font-size: 13px;
}

.wine-meta span,
.history-meta span {
  overflow-wrap: anywhere;
}

.wine-meta span {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f7f8f6;
}

.wine-meta strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  line-height: 1.25;
}

.wine-meta small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eef0f3;
}

.history-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
  box-shadow: inset 0 0 0 1px rgba(180, 35, 24, 0.45);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 56px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 19px;
}

.empty-state .solid-btn {
  margin-top: 8px;
}

.backup-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.backup-panel p {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.6;
}

.offline-status {
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid #d7e4dc;
  border-radius: 8px;
  background: #f4faf6;
}

.offline-status strong,
.offline-status span {
  display: block;
}

.offline-status strong {
  color: var(--leaf);
  font-size: 14px;
  font-weight: 850;
}

.offline-status span {
  margin-top: 5px;
  color: #475467;
  font-size: 13px;
  line-height: 1.5;
}

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

.file-btn {
  background: var(--surface-soft);
  color: var(--wine);
  box-shadow: inset 0 0 0 1px var(--line);
}

.file-btn input {
  display: none;
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.tab {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-height: 54px;
  min-width: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.tab span:first-child {
  font-size: 20px;
  line-height: 1;
}

.active-tab {
  background: #f7e8ec;
  color: var(--wine);
}

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

.stats-overview article,
.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stats-overview article {
  min-height: 82px;
  padding: 14px;
}

.stats-overview strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--wine);
  font-size: 22px;
  line-height: 1.15;
}

.stats-overview span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.chart-card {
  margin-bottom: 12px;
  padding: 16px;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.chart-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.donut-layout {
  display: grid;
  grid-template-columns: 138px 1fr;
  gap: 16px;
  align-items: center;
}

.donut-chart {
  position: relative;
  display: grid;
  place-items: center;
  width: 138px;
  height: 138px;
  border-radius: 999px;
  background: #eef0f3;
}

.donut-chart::after {
  position: absolute;
  width: 86px;
  height: 86px;
  border-radius: 999px;
  background: var(--surface);
  content: "";
}

.donut-chart span {
  position: relative;
  z-index: 1;
  color: var(--wine);
  font-size: 24px;
  font-weight: 850;
}

.chart-legend {
  display: grid;
  gap: 9px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  color: #344054;
  font-size: 13px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

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

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-info {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

.bar-info span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef0f3;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--wine), var(--leaf));
}

.chart-empty {
  padding: 14px 0;
  color: var(--muted);
  text-align: center;
}

.sheet {
  width: min(100% - 24px, 720px);
  max-height: calc(100dvh - 24px);
  margin: auto auto 12px;
  padding: 0;
  border: 0;
  border-radius: 12px 12px 8px 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sheet::backdrop {
  background: rgba(17, 24, 39, 0.46);
}

.sheet form,
#detailDialog {
  color: var(--ink);
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

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

.full-field {
  grid-column: 1 / -1;
}

.sheet-primary {
  width: calc(100% - 32px);
  margin: 0 16px 16px;
}

.detail-hero {
  padding: 16px;
}

.detail-stock {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.detail-stock div {
  min-height: 74px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.detail-stock strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--wine);
  font-size: 18px;
}

.detail-stock span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 16px;
}

.danger-btn,
.hard-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-weight: 750;
}

.hard-delete-btn {
  background: #ffffff;
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(180, 35, 24, 0.45);
}

.detail-rows {
  padding: 0 16px 16px;
}

.detail-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid #eef0f3;
}

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

.detail-value {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-weight: 700;
}

.out-panel {
  margin: 0 16px 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.out-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.out-panel textarea {
  margin-top: 12px;
}

.out-panel .danger-btn {
  width: 100%;
  margin-top: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  left: 20px;
  z-index: 30;
  width: fit-content;
  max-width: min(420px, calc(100% - 40px));
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(31, 41, 51, 0.94);
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 390px) {
  .summary-grid {
    gap: 8px;
  }

  .metric {
    padding: 12px 10px;
  }

  .metric-value {
    font-size: 20px;
  }

  .wine-meta,
  .history-meta,
  .detail-stock {
    grid-template-columns: 1fr;
  }
}
