*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #0c1124;
  --fg: #e4eaf4;
  --muted: #9aa8c2;
  --accent: #78a6ff;
  --card: #141c38;
  --stroke: #2a3a5c;
  --shadow: 0 8px 20px rgba(4, 10, 30, 0.45);
  --surface: #0a1022;
  --input-bg: #1a2544;
  --warn-bg: #2a2210;
  --warn-border: #6b5a2a;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  color: var(--fg);
  background: radial-gradient(120% 80% at 50% 0%, #121a35 0%, var(--surface) 45%, #080c18 100%);
  min-height: 100vh;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: radial-gradient(100% 60% at 50% 0%, #101736 0%, var(--bg) 80%, #070b19 100%);
  border-bottom: 1px solid var(--stroke);
  box-shadow: var(--shadow);
}
.site-header a { color: var(--accent); text-decoration: none; }
.site-header a:hover { text-decoration: underline; color: var(--fg); }
.brand {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--fg);
  text-decoration: none;
}
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.inline-logout { display: inline; margin: 0; }
.inline-logout .linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

.container { max-width: 720px; margin: 0 auto; padding: 1.25rem; }
.container a { color: var(--accent); }
h1 { font-size: 1.5rem; margin-top: 0; color: var(--fg); }
.muted { color: var(--muted); font-size: 0.95rem; }
.muted.small { font-size: 0.85rem; }
fieldset.card { border: 1px solid var(--stroke); border-radius: 10px; margin: 0; }
fieldset.card legend { padding: 0 0.35rem; }
.error { color: #ff8a8a; }

.notice {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.notice-success {
  background: #0f2418;
  border: 1px solid #2d6a4a;
  color: #c8efd8;
}
.notice-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #f0e6c8;
}

input:not([type="checkbox"]):not([type="submit"]):not([type="button"]),
textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.6rem;
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--stroke);
  border-radius: 8px;
}

.stack { display: flex; flex-direction: column; gap: 0.75rem; align-items: flex-start; }
.stack.row, .row {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}
.row .check { align-self: center; }

.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.btn.primary {
  background: #1e3a5f;
  border-color: var(--accent);
}
.btn.danger {
  background: #3a1515;
  border-color: #8b3a3a;
}
.linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.pad { padding: 1rem; }

.slot-list { list-style: none; padding: 0; margin: 0; }
.slot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.85rem 1rem;
}
.slot .time { font-size: 1.1rem; color: var(--accent); }
.pill {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
}
.pill.taken {
  background: #0f2418;
  border: 1px solid #2d6a4a;
  color: #c8efd8;
}

.data {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
.data th, .data td {
  border: 1px solid var(--stroke);
  padding: 0.5rem 0.65rem;
  text-align: left;
}
.data th { background: var(--card); }

.dose-times { list-style: none; padding: 0; }
.dose-times li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.dose-times .inline { display: inline; margin: 0; }

.danger-zone { margin-top: 1.5rem; }
.recipient-block { margin-bottom: 1rem; position: relative; }
.recipient-block .inline-delete {
  margin-top: 0.5rem;
}

code {
  background: var(--input-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.stack-row { margin: 0.75rem 0; }
.h2-tight { margin-top: 1.5rem; font-size: 1.15rem; }

.round-dots {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.round-dots .dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--stroke);
}
.round-dots .dot.todo { color: var(--muted); background: var(--surface); }
.round-dots .dot.done { background: #0f2418; border-color: #2d6a4a; color: #c8efd8; }

.round-block { margin-bottom: 1rem; }
.instruct { margin-bottom: 1rem; white-space: normal; }
.ex-links { margin: 1rem 0; }

select {
  width: 100%;
  max-width: 28rem;
  padding: 0.45rem 0.6rem;
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--stroke);
  border-radius: 8px;
}

form.inline { display: inline; }
.nowrap { white-space: nowrap; }
.upcoming-list { margin: 0.5rem 0 1rem; padding-left: 1.25rem; }
.upcoming-list li { margin-bottom: 0.35rem; }

.patient-flag-banner {
  border: 1px solid #8b6914;
  background: linear-gradient(135deg, #2a2210 0%, #1a1530 100%);
  margin-bottom: 1.25rem;
}
.flag-list { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.flag-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-top: 1px solid var(--stroke);
}
.flag-item:first-child { border-top: none; padding-top: 0; }
.flag-note {
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  background: rgba(120, 166, 255, 0.12);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.flag-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.patient-mark-form { width: 100%; max-width: 22rem; }
.patient-time-input { max-width: 11rem; min-height: 2.5rem; }
.patient-mark-form textarea { max-width: 22rem; }
.patient-mark-form.tight { gap: 0.5rem; margin-top: 0.5rem; }
.patient-up-next {
  border: 1px solid var(--accent);
  background: linear-gradient(160deg, #1a2544 0%, #141c38 100%);
  margin-bottom: 1.25rem;
}
.up-next-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.up-next-med { font-size: 1.25rem; font-weight: 700; margin: 0 0 0.25rem; }
.up-next-time { font-size: 1.5rem; color: var(--accent); margin: 0 0 0.75rem; }
.btn-large { font-size: 1.05rem; padding: 0.6rem 1.1rem; }
.patient-soon-list { list-style: none; padding: 0; margin: 0; }
.patient-soon-item { margin-bottom: 0.75rem; }
.patient-soon-head .time { font-size: 1.05rem; color: var(--accent); margin-top: 0.25rem; }
.pill.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #f0e6c8;
  margin-left: 0.35rem;
}
.patient-hint { max-width: 36rem; }
.notice.small { font-size: 0.9rem; padding: 0.5rem 0.75rem; }

.h2-first { margin-top: 0; }
.show-taken-row { margin: 0.75rem 0 1rem; }
.slot-overdue {
  border-color: var(--warn-border);
  background: linear-gradient(160deg, #2a2210 0%, #141c38 100%);
}
.slot-taken-row { opacity: 0.92; }
.slot-mark-form { margin: 0; }
.slot-actions .slot-unmark-form { display: block; margin-top: 0.35rem; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
}
.table-scroll .data { min-width: 32rem; }

.upcoming-details { margin: 1rem 0; }
.upcoming-summary {
  cursor: pointer;
  font-weight: 600;
  list-style-position: outside;
  padding: 0.35rem 0;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.upcoming-details[open] .upcoming-summary { margin-bottom: 0.5rem; }

.touch-btn { min-height: 2.75rem; touch-action: manipulation; }
.patient-up-next-overdue { border-color: var(--warn-border); }
.patient-soon-overdue { border-color: rgba(107, 90, 42, 0.6); }
.patient-footer-links { margin-top: 1.25rem; }
.patient-soon-head strong { word-break: break-word; }
.up-next-med { word-break: break-word; }

@media (max-width: 640px) {
  .container { padding: 1rem 0.85rem; }
  .site-header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem 0.75rem;
  }
  .nav {
    width: 100%;
    gap: 0.5rem 0.85rem;
    row-gap: 0.4rem;
  }
  .brand { font-size: 1rem; }
  input:not([type="checkbox"]):not([type="submit"]):not([type="button"]),
  textarea,
  select {
    font-size: 16px;
    max-width: 100%;
  }
  .patient-mark-form,
  .patient-mark-form textarea {
    max-width: 100%;
  }
  .slot {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .slot-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .slot-actions .btn,
  .slot-actions .btn.primary {
    width: 100%;
    min-height: 2.75rem;
    text-align: center;
  }
  .slot-actions .linkish,
  .slot-edit {
    text-align: center;
    padding: 0.35rem 0;
  }
  .slot-actions form.inline {
    display: block;
  }
  .btn {
    min-height: 2.6rem;
    padding: 0.5rem 1rem;
  }
  .data th,
  .data td {
    font-size: 0.88rem;
    padding: 0.45rem 0.5rem;
  }
  h1 { font-size: 1.35rem; }
  .up-next-time { font-size: 1.35rem; }
}
