:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172338;
  background: #f5f7fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 12% 0%, #e8f4ff 0, transparent 38rem), #f5f7fb;
}

button, input, textarea { font: inherit; }
button, .import-button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
[hidden] { display: none !important; }

.shell {
  width: min(100% - 40px, 1120px);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 44px) 0 42px;
}

.topbar, .brand, .section-heading {
  display: flex;
  align-items: center;
}

.topbar, .section-heading { justify-content: space-between; gap: 18px; }
.topbar { min-height: 64px; margin-bottom: 24px; }
.brand { gap: 14px; min-width: 0; }
.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 17px;
  color: #fff;
  background: #3378e8;
  box-shadow: 0 8px 20px #3378e833;
  font-size: 2rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: clamp(1.05rem, 2vw, 1.25rem); letter-spacing: -.02em; }
.muted, .card-description, .helper-text, footer { color: #718097; line-height: 1.55; }
.muted { margin-bottom: 0; font-size: .9rem; }
.sync-indicator { color: #60728b; font-size: .8rem; text-align: right; }

.tab-nav {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 5px;
  margin: 0 0 20px;
  padding: 6px;
  overflow-x: auto;
  border: 1px solid #e8edf4;
  border-radius: 15px;
  background: #ffffffed;
  box-shadow: 0 8px 24px #19345209;
  backdrop-filter: blur(12px);
}
.tab-button {
  min-height: 42px;
  flex: 1 0 auto;
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  color: #65748b;
  background: transparent;
  font-weight: 650;
}
.tab-button.active { color: #245eb4; background: #edf5ff; }
.page-view { animation: appear 180ms ease-out; }
@keyframes appear { from { opacity: .5; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.card {
  min-width: 0;
  padding: clamp(18px, 3vw, 26px);
  border: 1px solid #e8edf4;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 6px 20px #19345208;
}
.section-heading { margin-bottom: 19px; }
.eyebrow { margin: 0 0 6px; color: #77869b; font-size: .68rem; font-weight: 750; letter-spacing: .1em; }
.count-badge {
  display: grid;
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  place-items: center;
  border-radius: 11px;
  color: #2464c5;
  background: #edf5ff;
  font-weight: 700;
}

.form-grid { display: grid; gap: 14px; }
.medicine-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; color: #47566d; font-size: .86rem; font-weight: 650; }
input, textarea {
  width: 100%;
  min-height: 45px;
  padding: 11px 12px;
  border: 1px solid #dce3ed;
  border-radius: 11px;
  outline: none;
  color: #172338;
  background: #fff;
  font-size: .95rem;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { border-color: #5e96ed; box-shadow: 0 0 0 3px #3378e81b; }
small { color: #8290a4; font-weight: 400; line-height: 1.4; }
.primary-button, .secondary-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  border: 0;
  border-radius: 11px;
  text-align: center;
  text-decoration: none;
  font-weight: 700;
}
.primary-button { color: #fff; background: #3378e8; }
.primary-button:hover { background: #2468d4; }
.secondary-button { color: #2464c5; background: #edf5ff; }
.secondary-button:hover { background: #e0edff; }
.full-width { width: 100%; }

.record-list { display: grid; gap: 10px; margin: 18px 0 0; padding: 0; list-style: none; }
.record-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid #edf0f5;
  border-radius: 13px;
  background: #fbfcfe;
}
.record-content { min-width: 0; }
.record-title { margin: 0 0 4px; overflow-wrap: anywhere; font-weight: 700; }
.record-detail { margin: 0; overflow-wrap: anywhere; color: #718097; font-size: .88rem; line-height: 1.5; white-space: pre-wrap; }
.record-detail + .record-detail { margin-top: 4px; }
.delete-button { flex: 0 0 auto; padding: 6px 9px; border: 0; border-radius: 8px; color: #a34a55; background: #fff0f1; font-size: .78rem; font-weight: 650; }
.empty-state { margin: 18px 0 0; color: #8895a8; font-size: .9rem; text-align: center; }

.records-grid, .account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.account-grid .card:first-child { grid-row: span 2; }
.card-description { margin: 11px 0 18px; font-size: .9rem; }
.consent-block { display: grid; gap: 15px; }
.consent-label { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 10px; color: #526179; font-size: .86rem; font-weight: 450; line-height: 1.5; }
.consent-label input { width: 18px; min-height: 18px; height: 18px; margin: 2px 0 0; accent-color: #3378e8; }
.helper-text { min-height: 1.2em; margin: 12px 0 0; font-size: .86rem; }
.account-status { margin: 16px 0 4px; font-weight: 650; }
.button-stack { display: grid; gap: 10px; margin-top: 17px; }
.button-stack .text-button { justify-self: center; }
.text-button { padding: 8px; border: 0; color: #2464c5; background: transparent; font-weight: 650; }
.sync-choice { display: grid; gap: 10px; margin-top: 16px; }
.sync-choice p { margin: 0 0 3px; color: #526179; font-size: .9rem; line-height: 1.5; }
.privacy-button { padding-left: 0; }
.privacy-panel { margin: 8px 0 14px; color: #65748b; font-size: .84rem; line-height: 1.55; }
.privacy-panel p { margin: 0; }
.import-button { position: relative; }
.import-button input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }

footer { max-width: 780px; margin: 23px auto 0; padding: 0 6px; font-size: .77rem; text-align: center; }
.status-message {
  position: fixed;
  right: max(16px, calc((100vw - 1120px) / 2));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 5;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 16px;
  transform: translateY(16px);
  border-radius: 12px;
  color: #fff;
  background: #172338;
  box-shadow: 0 8px 30px #17233830;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.status-message.visible { transform: translateY(0); opacity: 1; }

@media (min-width: 1000px) {
  .shell { padding-top: 36px; }
  .tab-nav { width: fit-content; min-width: 440px; }
  #page-schedule > .card { max-width: 900px; }
}

@media (max-width: 700px) {
  .shell { width: min(100% - 24px, 560px); padding-top: 15px; }
  .topbar { min-height: 54px; margin-bottom: 17px; }
  .brand { gap: 10px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 14px; }
  .sync-indicator { max-width: 112px; font-size: .72rem; }
  .tab-nav { margin-bottom: 13px; }
  .tab-button { padding-inline: 12px; }
  .records-grid, .account-grid { grid-template-columns: 1fr; gap: 12px; }
  .account-grid .card:first-child { grid-row: auto; }
}

@media (max-width: 420px) {
  .shell { width: min(100% - 20px, 560px); }
  .medicine-form { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 17px; }
  .tab-button { padding-inline: 9px; font-size: .88rem; }
  .record-item { padding: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
