:root {
  color-scheme: light;
  --bg: #f6f8f6;
  --ink: #18211d;
  --muted: #657269;
  --line: #dfe7e1;
  --panel: #ffffff;
  --green: #1f7a4d;
  --green-soft: #e7f4ed;
  --blue: #2369a8;
  --blue-soft: #e8f1fb;
  --amber: #a66000;
  --amber-soft: #fff2d9;
  --red: #b3261e;
  --red-soft: #fde8e7;
  --shadow: 0 16px 40px rgba(34, 49, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 14px;
}

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

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.12;
}

h2 {
  font-size: 18px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: end;
  gap: 10px;
}

.time-control {
  min-width: 132px;
}

.time-control input {
  min-height: 42px;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

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

.summary-tile {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  display: grid;
  align-content: space-between;
  box-shadow: var(--shadow);
}

.summary-tile span {
  color: var(--muted);
  font-size: 14px;
}

.summary-tile strong {
  font-size: 34px;
  line-height: 1;
}

.summary-tile.danger strong {
  color: var(--red);
}

.summary-tile.warn strong {
  color: var(--amber);
}

.summary-tile.soon strong {
  color: var(--blue);
}

.summary-tile.ok strong {
  color: var(--green);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-top: 14px;
}

.panel-heading {
  min-height: 58px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 14px;
}

.alert-list {
  display: grid;
  gap: 10px;
  padding: 14px 18px 18px;
}

.empty-state {
  color: var(--muted);
  padding: 14px 0;
}

.alert-item {
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--amber-soft);
  border: 1px solid #f2d29b;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.alert-item.expired {
  background: var(--red-soft);
  border-color: #f2b8b5;
}

.alert-item strong,
.alert-item span {
  display: block;
}

.alert-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.medicine-list {
  display: grid;
}

.medicine-row {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.medicine-row:last-child {
  border-bottom: 0;
}

.row-main {
  display: grid;
  grid-template-columns: minmax(170px, 1.25fr) minmax(140px, 0.9fr) minmax(150px, 1fr) minmax(170px, 1.1fr) 42px;
  gap: 12px;
  align-items: end;
}

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

label span {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 3px solid rgba(31, 122, 77, 0.16);
  border-color: var(--green);
}

.shelf-life-field {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(88px, 0.75fr);
  gap: 10px;
}

.medicine-row[data-mode="date"] .shelf-life-field,
.medicine-row[data-mode="shelf"] .expire-date-field {
  display: none;
}

.calculated-expiry {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--red);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.row-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  min-height: 30px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
}

.status-badge.ok {
  color: var(--green);
  background: var(--green-soft);
}

.status-badge.soon {
  color: var(--blue);
  background: var(--blue-soft);
}

.status-badge.warn {
  color: var(--amber);
  background: var(--amber-soft);
}

.status-badge.danger {
  color: var(--red);
  background: var(--red-soft);
}

.next-reminder {
  color: var(--muted);
  font-size: 14px;
}

.reminder-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.reminder-pill {
  min-height: 50px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 7px 9px;
  background: #fbfcfb;
  overflow: hidden;
}

.reminder-pill strong,
.reminder-pill span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reminder-pill strong {
  font-size: 12px;
  color: var(--muted);
}

.reminder-pill span {
  margin-top: 3px;
  font-size: 13px;
}

.reminder-pill.due {
  border-color: #f2d29b;
  background: var(--amber-soft);
}

.reminder-pill.past {
  border-color: #f1c5c2;
  background: #fff7f6;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 22px, 760px);
    padding-top: 18px;
  }

  .topbar,
  .panel-heading,
  .alert-item {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .primary-button,
  .ghost-button {
    flex: 1;
  }

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

  .row-main {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 100%;
  }

  .reminder-strip {
    grid-template-columns: 1fr;
  }
}
