
/* ========================================
   MEDAWARE | Medicine Management
   Main stylesheet
======================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

/* ---------- Theme ---------- */

:root {
  --ink: #20332b;
  --muted: #6b7b71;
  --green: #28664f;
  --green-dark: #1e503c;
  --mint: #e8f2e9;
  --paper: #f5f7f2;
  --line: #e0e7df;
  --white: #ffffff;
  --danger: #a7372b;
  --shadow: 0 10px 30px rgba(24, 59, 37, 0.06);
}

/* ---------- Reset and base ---------- */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.6 'DM Sans', sans-serif;
}

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

button {
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid #a5cfb1;
  outline-offset: 2px;
}

h1,
h2,
h3 {
  font-family: 'Manrope', sans-serif;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

h2 {
  margin-top: 0;
  font-size: 1.4rem;
}

p {
  margin: 8px 0 14px;
}

small {
  font-size: 0.82rem;
}

.hidden,
[hidden] {
  display: none !important;
}

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

/* ---------- Header ---------- */

.site-header,
header {
  min-height: 70px;
  padding: 12px 5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.brand:first-letter {
  color: var(--green);
}

/* ---------- Main layout ---------- */

main {
  width: min(1160px, 92vw);
  margin: 34px auto 60px;
}

.auth-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr;
  align-items: center;
  gap: 8vw;
  min-height: 65vh;
}

.hero {
  padding: 20px 0;
}

.hero em {
  color: var(--green);
  font-style: normal;
}

.hero ul {
  padding-left: 22px;
  color: var(--green);
  font-weight: 600;
  line-height: 2;
}

.hero small {
  display: block;
  max-width: 480px;
  margin-top: 25px;
}

.eyebrow {
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.13em;
}

/* ---------- Panels and cards ---------- */

.panel {
  min-width: 0;
  padding: 24px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.columns {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  align-items: start;
  gap: 16px;
}

.form,
.list {
  min-width: 0;
}

/* ---------- Tabs and buttons ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.tabs button,
button {
  padding: 10px 13px;
  color: var(--ink);
  background: #f2f5f1;
  border: 1px solid var(--line);
  border-radius: 9px;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.tabs button {
  flex: 1;
}

.tabs button:hover,
button:hover {
  border-color: #b6cdbb;
}

.tabs button.active {
  color: var(--white);
  background: var(--green);
  border-color: var(--green);
}

.primary {
  color: var(--white);
  background: var(--green);
  border-color: var(--green);
  font-weight: 700;
}

.primary:hover {
  color: var(--white);
  background: var(--green-dark);
}

.full {
  width: 100%;
  margin-top: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 15px;
}

/* ---------- Forms ---------- */

label {
  display: block;
  margin: 13px 0 5px;
  font-size: 0.85rem;
  font-weight: 700;
}

input,
textarea,
select {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid #d5dfd5;
  border-radius: 9px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #7da98b;
  outline: 2px solid #c5e0cc;
}

input::placeholder,
textarea::placeholder {
  color: #89968d;
}

textarea {
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-block;
  width: auto;
}

/* ---------- Status messages ---------- */

.msg {
  min-height: 1em;
  color: var(--green);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.msg.error {
  color: var(--danger);
}

.notice {
  margin: 16px 0;
  padding: 13px 16px;
  color: #6d5318;
  background: #fff4db;
  border: 1px solid #edd9a6;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.reminder-status {
  margin: 16px 0 6px;
  padding: 11px 14px;
  color: var(--green-dark);
  background: var(--mint);
  border: 1px solid #cfe1d1;
  border-radius: 10px;
}

.reminder-disclaimer {
  display: block;
  max-width: 850px;
}

/* ---------- Dashboard welcome ---------- */

.welcome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.welcome h1 {
  margin: 8px 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

/* ---------- Statistics ---------- */

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

.stats .panel {
  padding: 17px 20px;
}

.stats small {
  display: block;
}

.stats strong {
  display: block;
  font: 800 2rem 'Manrope', sans-serif;
}

/* ---------- Dashboard navigation ---------- */

.main-tabs {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.main-tabs button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.content {
  margin-top: 20px;
}

/* ---------- Medicine and prescription lists ---------- */

.empty {
  padding: 25px 5px;
  color: var(--muted);
  text-align: center;
}

.record {
  margin: 10px 0;
  padding: 14px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.record-title {
  margin: 0;
  font-weight: 700;
}

.record-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.record-actions button {
  padding: 6px 9px;
  font-size: 0.8rem;
}

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

/* ---------- Medication tracking ---------- */

.tracker {
  margin-top: 18px;
}

.doseform {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px auto;
  align-items: end;
  gap: 12px;
}

/* ---------- Medicine information ---------- */

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

.info-card {
  padding: 20px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 13px;
}

.tag {
  display: inline-block;
  padding: 3px 9px;
  color: var(--green);
  background: var(--mint);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Checkbox rows in the email-reminder form (kept out of inline styles for the CSP) */
.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input.check-input {
  width: auto;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Guided medicine chat ---------- */

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

.chat-header h2 {
  margin: 0;
}

.chat-restart {
  flex: none;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.chat-log {
  position: relative; /* bubble offsetTop is measured from the log */
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 460px;
  margin: 12px 0;
  padding: 12px;
  overflow-y: auto;
  background: var(--surface-tint, #f6f4ff);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.chat-msg p,
.chat-msg ul {
  margin: 6px 0 0;
}

.chat-msg ul {
  padding-left: 20px;
}

.chat-user {
  align-self: flex-end;
  color: #fff;
  background: var(--accent-strong, #5444a3);
}

.chat-bot {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--line);
}

.chat-title {
  display: block;
}

.chat-tag {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  color: #6d5318;
  background: #fff4db;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
}

.chat-cite {
  color: var(--muted);
  font-size: 0.8rem;
}

.chat-warn {
  padding: 7px 10px;
  color: #6d5318;
  background: #fff4db;
  border-radius: 8px;
  font-size: 0.85rem;
}

.chat-urgent {
  padding: 9px 12px;
  color: #7a1a12;
  background: #fde4e0;
  border: 1px solid #f2b8b0;
  border-radius: 8px;
  font-weight: 700;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chat-actions .chat-chip {
  width: auto;
  padding: 5px 11px;
  color: var(--accent-text, #6352b3);
  background: var(--surface-tint, #f6f4ff);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
}

.chat-form {
  display: flex;
  gap: 8px;
}

@media (max-width: 600px) {
  .chat-bot {
    max-width: 100%;
  }

  .chat-log {
    padding: 8px;
  }
}

.chat-form input {
  flex: 1;
}

.chat-form button {
  flex: none;
}

.info-group-heading {
  margin: 26px 0 0;
}

.book-source {
  font-size: 0.85rem;
}

#medicineInfoResults {
  align-items: start;
}

.medicine-info-card h3 {
  margin-bottom: 4px;
}

.tag.tag-unreviewed {
  color: #6d5318;
  background: #fff4db;
}

.book-section {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.book-section summary {
  cursor: pointer;
  font-weight: 700;
}

.book-section ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.book-cite {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.book-section ul + .book-cite {
  margin-top: 12px;
}

.book-pages {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.book-dose-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.book-flag,
.book-update {
  margin: 10px 0 0;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.book-flag {
  color: #6d5318;
  background: #fff4db;
}

.book-update {
  margin-bottom: 10px;
  color: #7a2e1d;
  background: #fdebe6;
}

.book-update a {
  color: inherit;
}

.book-update-source {
  display: block;
  margin-top: 4px;
}

/* ---------- Footer ---------- */

footer {
  margin-top: 32px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- Toast notifications ---------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  max-width: min(400px, 90vw);
  padding: 13px 17px;
  color: var(--white);
  background: #203d30;
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

.toast.toast-error {
  background: var(--danger) !important;
}

/* ---------- Tablet ---------- */

@media (max-width: 780px) {
  .auth-layout,
  .columns {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-layout {
    gap: 20px;
    padding: 20px 0;
  }

  .stats {
    gap: 8px;
  }

  .stats .panel {
    padding: 13px;
  }

  .stats strong {
    font-size: 1.6rem;
  }

  .welcome {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .doseform button {
    grid-column: 1 / -1;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 500px) {
  body {
    font-size: 14px;
  }

  header > span {
    display: none;
  }

  main {
    width: 92vw;
    margin-top: 22px;
  }

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

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

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

  .panel {
    padding: 18px;
  }

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

  .doseform button {
    grid-column: auto;
  }

  .tabs {
    gap: 6px;
  }
}

/* ---------- Reduced motion accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

.tabs a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px;
  border-radius: 10px;
  text-decoration: none;
  font: inherit;
  color: inherit;
  background: #f1f5f1;
  border: 1px solid #dce6dc;
  box-sizing: border-box;
}

.tabs a:hover {
  opacity: 0.9;
}

/* ---------- Today's schedule ---------- */

.today {
  margin: 26px 0 8px;
}

.today-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}

.today-head h2,
.today-head p {
  margin: 0;
}

.today-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 16px;
  margin-top: 14px;
}

.today-grid.empty {
  display: block;
  background: var(--white);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.medicine-card {
  padding: 20px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

.medicine-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  font-size: 1.4rem;
  background: var(--mint);
  border-radius: 12px;
}

.medicine-name {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.medicine-dosage {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.medicine-time {
  margin: 0 0 12px;
  color: var(--green-dark);
  font-weight: 700;
}

.medicine-status {
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.status-logged {
  color: #1e6b2f;
  background: #e6f4ea;
}

.status-upcoming {
  color: var(--green-dark);
  background: var(--mint);
}

.status-due {
  color: #7a4100;
  background: #fff1dc;
}

.today-note {
  margin: 10px 0 0;
  font-size: 0.85rem;
}

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

.today-stats .panel {
  padding: 17px 20px;
}

.today-stats small {
  display: block;
}

.today-stats strong {
  display: block;
  font: 800 2rem 'Manrope', sans-serif;
}

@media (max-width: 500px) {
  .today-stats {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* "Forgot password?" link under the login password field */
.forgot-link {
  display: block;
  width: fit-content;
  margin: 8px 0 0 auto;
  color: var(--green);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Short "not medical advice / privacy" line under the login and sign-up forms */
.legal-note {
  margin-top: 14px;
  font-size: 0.8rem;
  text-align: center;
}

.legal-note a,
footer a {
  color: var(--accent-text, #6352b3);
}

/* Cloudflare Turnstile security check (shown only when a site key is configured) */
.captcha-box {
  min-height: 65px;
  margin: 10px 0;
}
