:root {
  --bg: #F3F6F6;
  --surface: #FFFFFF;
  --ink: #1E2A2E;
  --ink-soft: #5B6E70;
  --line: #E1E8E7;
  --teal: #2F6F6B;
  --teal-deep: #1F4F4C;
  --teal-tint: #E3EFEE;
  --good: #3F8A64;
  --good-tint: #E7F3EB;
  --watch: #B97F1F;
  --watch-tint: #FBF1DF;
  --high: #B04A3B;
  --high-tint: #FBE9E6;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font-ui: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --font-display: "Fraunces", "Vazirmatn", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.muted { color: var(--ink-soft); }

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, var(--teal-tint), transparent 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(30,42,46,0.06), 0 12px 32px rgba(30,42,46,0.08);
}

.login-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 28px;
  line-height: 1;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card p {
  margin: 0 0 20px;
  font-size: 14px;
}

.login-card input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px;
  margin-bottom: 14px;
  text-align: center;
  letter-spacing: 2px;
}

.login-card input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.login-card button {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--teal);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.login-card button:active { background: var(--teal-deep); }

.error { color: var(--high); font-size: 13px; margin-top: 12px; margin-bottom: 0; }

/* ---------- App shell ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  background: var(--bg);
}

.topbar-title {
  font-weight: 700;
  font-size: 17px;
}

.topbar-username {
  font-weight: 400;
  font-size: 13px;
  color: var(--ink-soft);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 999px;
}
.icon-btn:active { background: var(--line); }

main {
  flex: 1;
  padding: 4px 20px 28px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- Status / big number ---------- */
.status-card {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(30,42,46,0.05), 0 10px 24px rgba(30,42,46,0.06);
}

.status-ring {
  flex-shrink: 0;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: var(--good-tint);
  border: 3px solid var(--good);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.25s, border-color 0.25s;
}

.status-ring.watch { background: var(--watch-tint); border-color: var(--watch); }
.status-ring.high { background: var(--high-tint); border-color: var(--high); }
.status-ring.neutral { background: var(--teal-tint); border-color: var(--teal); }

#status-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.status-unit {
  font-size: 10px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.status-label {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.status-time {
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Form ---------- */
.reading-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
}

fieldset.field {
  border: none;
  padding: 0;
  margin: 0;
}

.value-input-row {
  position: relative;
  display: flex;
  align-items: center;
}

#value-input {
  width: 100%;
  padding: 16px 60px 16px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  color: var(--ink);
}

.value-unit {
  position: absolute;
  left: 16px;
  color: var(--ink-soft);
  font-size: 13px;
}

#value-input:focus, #time-input:focus, #note-input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

#time-input, #note-input {
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  color: var(--ink);
}

.tag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  position: relative;
}

.tag-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.tag-chip span {
  display: inline-block;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--ink-soft);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.tag-chip input:checked + span {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.primary-btn {
  margin-top: 6px;
  padding: 15px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--teal);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.primary-btn:active { background: var(--teal-deep); }

/* ---------- History ---------- */
.trend-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px 18px 8px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(30,42,46,0.05), 0 10px 24px rgba(30,42,46,0.06);
}

.trend-header {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.trend-svg {
  width: 100%;
  height: 90px;
  display: block;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.history-day-label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 8px;
  padding-right: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(30,42,46,0.04);
}

.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--good);
}
.history-dot.watch { background: var(--watch); }
.history-dot.high { background: var(--high); }
.history-dot.neutral { background: var(--teal); }

.history-main {
  flex: 1;
  min-width: 0;
}

.history-value {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 12px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 18px;
  padding: 4px 6px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  font-size: 14px;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
}

.nav-btn.active { color: var(--teal); font-weight: 600; }
.nav-icon { font-size: 18px; line-height: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* ---------- Reduced motion / focus ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
