:root {
  --bg: #0d0d2b;
  --panel: #14143a;
  --line: #2b2b66;
  --text: #e8e0c8;
  --muted: #a9a3bd;
  --cyan: #40e8e8;
  --amber: #e8c040;
  --magenta: #ff5cc8;
  --font: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
}

.shell { max-width: 60rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; max-width: 68ch; }
.muted { color: var(--muted); }

.brand { font-size: 1.1rem; color: var(--cyan); font-weight: 700; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-bottom: 1.25rem; }

/* Profile tabs: the active tab opens into the panel below it. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.35rem;
  border-bottom: 2px solid var(--cyan);
}
.tab {
  font: inherit;
  color: var(--muted);
  background: transparent;
  border: 2px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  padding: 0.55rem 1rem;
  min-height: 44px;
  cursor: pointer;
}
.tab:hover { color: var(--text); border-color: var(--cyan); }
.tab[aria-current="true"] {
  color: var(--cyan);
  font-weight: 700;
  background: var(--panel);
  border-color: var(--cyan);
  margin-bottom: -2px;
  padding-bottom: calc(0.55rem + 2px);
}
.tab-add { border-style: dashed; margin-left: auto; }

.panel {
  background: var(--panel);
  border: 2px solid var(--cyan);
  border-radius: 6px;
  padding: 1.5rem;
}
.panel-attached { border-top: 0; border-radius: 0 0 6px 6px; min-height: 16rem; }

.person-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.person-notes { white-space: pre-wrap; margin-bottom: 1.5rem; }
.meds { border-top: 2px solid var(--line); padding-top: 1.25rem; }
.meds h3 { margin-bottom: 0.75rem; }

.empty { padding: 2rem 0; }
.empty h2 { margin-bottom: 0.75rem; }

/* Sign in / setup */
.auth { max-width: 26rem; margin: 8vh auto 0; }
.auth .brand { margin-bottom: 1rem; }
.auth-panel { border-radius: 6px; }
.auth-panel h2 { margin-bottom: 0.75rem; }

/* Forms */
label { display: block; margin: 0 0 0.35rem; font-weight: 700; }
input, textarea {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 1rem;
}
input:hover, textarea:hover { border-color: var(--muted); }
textarea { resize: vertical; }
::placeholder { color: #7f7a99; }

.error { color: var(--amber); font-weight: 700; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: 2px solid var(--line);
  border-radius: 4px;
  padding: 0.6rem 1.1rem;
  min-height: 44px;
  cursor: pointer;
}
.btn:hover { border-color: var(--text); }
.btn-primary { color: var(--bg); background: var(--cyan); border-color: var(--cyan); }
.btn-primary:hover { background: #7ff2f2; border-color: #7ff2f2; }
.btn-danger { color: var(--magenta); border-color: var(--magenta); }
.btn-danger:hover { color: var(--bg); background: var(--magenta); border-color: var(--magenta); }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.75rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.btn-primary:focus-visible { outline-color: var(--text); }

/* Dialogs */
dialog {
  width: min(30rem, calc(100vw - 2rem));
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--cyan);
  border-radius: 6px;
  padding: 1.5rem;
}
dialog::backdrop { background: rgba(5, 5, 20, 0.75); }
dialog h2 { margin-bottom: 1rem; }

@media (max-width: 34rem) {
  .panel { padding: 1.1rem; }
  .tab-add { margin-left: 0; }
}

/* Medications */
.meds-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.med { display: grid; grid-template-columns: 96px 1fr; gap: 1rem; padding: 1.25rem 0; }
.med + .med { border-top: 2px solid var(--line); }
.med-photo {
  width: 96px; height: 96px; padding: 0; border: 2px solid var(--line); border-radius: 4px;
  background: var(--bg); overflow: hidden; cursor: pointer; display: block;
}
.med-photo:hover { border-color: var(--cyan); }
.med-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.med-photo-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 2rem; font-weight: 700; cursor: default;
}
.med-photo-empty:hover { border-color: var(--line); }
.med-body h4 { margin: 0 0 0.5rem; font-size: 1.1rem; line-height: 1.3; overflow-wrap: anywhere; }
.med-facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.15rem 1rem; margin: 0 0 0.75rem; }
.med-facts dt { color: var(--muted); }
.med-facts dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.med-desc { color: var(--muted); margin-bottom: 0.75rem; }
.med-stopped { color: var(--amber); font-weight: 700; margin-bottom: 0.75rem; }
.med.is-stopped .med-body h4 { color: var(--muted); }
.stopped-meds { margin-top: 1rem; border-top: 2px solid var(--line); }
.stopped-meds summary { cursor: pointer; color: var(--muted); padding: 0.85rem 0; min-height: 44px; }
.stopped-meds summary:hover { color: var(--text); }

/* Medication dialog */
dialog { max-height: calc(100dvh - 2rem); overflow-y: auto; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.photo-field { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; }
.photo-preview { width: 96px; height: 96px; object-fit: cover; border: 2px solid var(--line); border-radius: 4px; flex: none; }
.photo-controls { flex: 1; min-width: 0; }
.photo-controls input[type="file"] { margin-bottom: 0.75rem; padding: 0.5rem; border-style: dashed; }
.image-dialog { width: min(44rem, calc(100vw - 2rem)); text-align: right; }
.image-dialog img { display: block; width: 100%; max-height: 70dvh; object-fit: contain; margin-bottom: 1rem; background: var(--bg); border-radius: 4px; }

@media (max-width: 34rem) {
  .med { grid-template-columns: 72px 1fr; gap: 0.85rem; }
  .med-photo { width: 72px; height: 72px; }
  .med-photo-empty { font-size: 1.6rem; }
  .field-pair { grid-template-columns: 1fr; }
}

input[type="file"]::file-selector-button {
  font: inherit; font-weight: 700; color: var(--text); background: transparent;
  border: 2px solid var(--line); border-radius: 4px; padding: 0.35rem 0.8rem;
  margin-right: 0.75rem; cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--text); }
