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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242837;
  --border: #2e3345;
  --text: #e4e6ed;
  --text2: #8b8fa3;
  --text3: #5c6070;
  --accent: #6c8cff;
  --accent2: #4a6adf;
  --green: #34c759;
  --green2: #2ba84a;
  --danger: #ff5c5c;
  --radius: 12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Fade transitions ──────────────────────────────────────────────── */
.page-content {
  opacity: 1;
  transition: opacity 0.2s ease;
  min-height: calc(100dvh - 56px);
}

.page-content.fade-out { opacity: 0; }
.page-content.fade-in {
  animation: fadeIn 0.25s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Center card (login/setup) ─────────────────────────────────────── */
.center-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
  text-align: center;
}

.center-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text2);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.center-card form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.error {
  background: rgba(255, 92, 92, 0.15);
  color: var(--danger);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* ── Inputs ────────────────────────────────────────────────────────── */
input[type="password"],
input[type="search"],
input[type="datetime-local"],
textarea,
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

input[type="datetime-local"] { color-scheme: dark; }

textarea { resize: vertical; }

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8fa3' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s, opacity 0.15s, transform 0.15s;
}

button[type="submit"] {
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
}
button[type="submit"]:hover { background: var(--accent2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Header ────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  height: 56px;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.header-btn {
  background: none;
  color: var(--text2);
  padding: 0.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-btn:hover { background: var(--surface2); color: var(--text); }

/* ── List toolbar ──────────────────────────────────────────────────── */
.list-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.list-toolbar input[type="search"] {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.list-toolbar select {
  width: auto;
  min-width: 90px;
  padding: 0.55rem 2rem 0.55rem 0.75rem;
  font-size: 0.9rem;
}

/* ── Symptom list ──────────────────────────────────────────────────── */
.symptom-list {
  padding: 0 1.25rem;
  padding-bottom: 100px;
}

/* ── Date groups ───────────────────────────────────────────────────── */
.date-group {
  margin-top: 0.25rem;
}

.date-header {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.9rem 0 0.4rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  background: var(--bg);
  z-index: 5;
}

/* ── Symptom cards ─────────────────────────────────────────────────── */
.symptom-card {
  display: flex;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(46, 51, 69, 0.5);
}

.symptom-card:last-child { border-bottom: none; }

.card-time-col {
  flex-shrink: 0;
  width: 62px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text2);
  padding-top: 0.1rem;
  text-align: right;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-main {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.card-symptom {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
}

.card-notes {
  margin-top: 0.25rem;
  font-size: 0.82rem;
  color: var(--text2);
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: var(--text3);
}

.card-category {
  background: var(--surface2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: capitalize;
  color: var(--text2);
}

.card-severity { font-weight: 600; }
.sev-low  { color: #4cce8a; }
.sev-mid  { color: #e0a830; }
.sev-high { color: #f06060; }

.delete-btn {
  background: none;
  color: var(--text3);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.symptom-card:hover .delete-btn,
.symptom-card:active .delete-btn { opacity: 1; }
.delete-btn:hover { color: var(--danger); }

@media (hover: none) {
  .delete-btn { opacity: 0.4; }
}

.empty {
  text-align: center;
  color: var(--text2);
  padding: 4rem 1rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ── Pagination ────────────────────────────────────────────────────── */
#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 1.25rem 6rem;
}

.page-btn {
  background: var(--surface2);
  color: var(--text);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}
.page-btn:hover { background: var(--border); }

.page-info {
  font-size: 0.85rem;
  color: var(--text2);
}

/* ── FAB ───────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(52, 199, 89, 0.35);
  z-index: 20;
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.15s;
}

.fab:hover { background: var(--green2); transform: scale(1.06); }
.fab:active { transform: scale(0.95); }

.fab-hidden {
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}

/* ── Add view ──────────────────────────────────────────────────────── */
.add-view {
  padding: 0 1.25rem 2rem;
}

.add-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0;
}

.add-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.back-btn {
  background: none;
  color: var(--text2);
  padding: 0.3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn:hover { background: var(--surface2); color: var(--text); }

.add-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text2);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.optional {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--text3);
}

.field-row {
  display: flex;
  gap: 0.75rem;
}
.field-half { flex: 1; }

.severity-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.severity-num {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  min-width: 1.5rem;
  text-align: center;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.submit-btn {
  margin-top: 0.5rem;
  padding: 0.85rem;
  font-size: 1rem;
  border-radius: var(--radius);
}

/* ── Spinner ───────────────────────────────────────────────────────── */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .field-row { flex-direction: column; }
  .list-toolbar { flex-direction: column; }
}

/* ── Safe area (notch phones) ──────────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  header { padding-top: calc(0.9rem + env(safe-area-inset-top)); height: auto; }
  .fab { bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
  .symptom-list { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .center-card { padding-top: calc(2rem + env(safe-area-inset-top)); }
  .add-form { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Desktop max width ─────────────────────────────────────────────── */
@media (min-width: 600px) {
  .page-content, header {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }
  .fab {
    right: calc(50% - 280px + 1.5rem);
  }
}
