:root {
  --ink: #1f2a2e;
  --muted: #5b6b6f;
  --line: #dfe6e6;
  --bg: #f6f8f8;
  --panel: #ffffff;
  --accent: #3b7a72;
  --accent-dark: #2c5b55;
  --accent-bg: #e9f2f0;
  --danger: #b3432b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent-dark); }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}

.auth-card p.sub {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 4px;
}

.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.tabs button.active {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 14px 0 6px;
}

input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.primary {
  margin-top: 20px;
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: 11px 0;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.6; cursor: wait; }

.save-box {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}
.save-box h3 { font-size: 0.92rem; margin: 0; }
.save-box .optional { font-weight: 400; color: var(--muted); }
.save-box label { margin-top: 10px; }
.editing-note {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--accent-dark);
  background: var(--accent-bg);
  padding: 6px 8px;
  border-radius: 6px;
}
.btn-row { display: flex; gap: 8px; }
button.secondary {
  flex: 1;
  border: 1px solid var(--accent);
  background: var(--accent-bg);
  color: var(--accent-dark);
  padding: 9px 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
button.ghost-wide {
  margin-top: 12px;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 0;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 10px;
  min-height: 1em;
}

/* --- Portal layout --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  font-weight: 700;
  color: var(--accent-dark);
}

.topbar .who {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.topbar button.ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.main-tabs {
  display: flex;
  gap: 6px;
  padding: 14px 24px 0;
}

.main-tabs button {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.main-tabs button.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  padding: 20px 24px 40px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.panel h2 {
  font-size: 1rem;
  margin: 0 0 14px;
}

.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filters input { width: auto; flex: 2; min-width: 200px; }
.filters select { width: auto; flex: 1; min-width: 140px; }

.ex-list { max-height: 60vh; overflow-y: auto; }

.ex-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}

.ex-row:last-child { border-bottom: none; }

.ex-row .info { flex: 1; min-width: 0; }

.row-actions { display: flex; gap: 6px; }

.ex-row .name { font-weight: 600; }

.ex-row .meta { color: var(--muted); font-size: 0.8rem; }

.ex-row .row-actions button {
  border: 1px solid var(--accent);
  color: var(--accent-dark);
  background: var(--accent-bg);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
}

/* Illustrations are shown whole (contain), never cropped. */
.thumb {
  width: 56px;
  height: 44px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.thumb-lg {
  width: 100%;
  height: 150px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 8px;
  display: block;
}

.ex-row .row-actions .details-btn {
  border-color: var(--line);
  background: var(--panel);
  color: var(--muted);
}

.ex-row .details {
  flex-basis: 100%;
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.detail-img {
  width: 100%;
  height: 170px;
  margin-bottom: 10px;
  display: block;
}

.detail-dose { font-weight: 600; color: var(--accent-dark); margin-bottom: 6px; }
.detail-note, .rx-note { color: var(--muted); font-style: italic; margin-top: 6px; }
.rx-note { font-size: 0.8rem; margin: 2px 0 6px; }

.rx-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.rx-item .name { font-weight: 600; margin-bottom: 6px; }

.dose-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.7fr;
  gap: 6px;
  margin-bottom: 6px;
}

.dose-grid label {
  font-size: 0.7rem;
  margin: 0 0 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.dose-grid input { padding: 6px 8px; font-size: 0.85rem; }

.rx-item .remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0;
}

.rx-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
}

.rx-list-item .title { font-weight: 600; }
.rx-list-item .sub { color: var(--muted); font-size: 0.8rem; }

.rx-list-item .actions { display: flex; gap: 8px; }
.rx-list-item .actions button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.8rem;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 30px 10px;
  font-size: 0.9rem;
}

.hint {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  margin-top: 6px;
  margin-bottom: 4px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }
