@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@500;700;800;900&family=Karla:wght@400;500;600;700&display=swap');

:root {
  --bg: #faf6f0;
  --bg-elevated: #ffffff;
  --ink: #2b2420;
  --ink-soft: #746a60;
  --ink-faint: #a89c8f;
  --accent: #c9781f;
  --accent-soft: #f3d9b8;
  --accent-ink: #6b3f0f;
  --good: #4f9d5c;
  --good-soft: #dcefdd;
  --miss: #d9714e;
  --miss-soft: #fbe2d8;
  --pause: #8b7fc7;
  --pause-soft: #e6e1f7;
  --line: #ece3d8;
  --shadow-sm: 0 1px 2px rgba(43, 36, 32, 0.06), 0 1px 1px rgba(43, 36, 32, 0.04);
  --shadow-md: 0 8px 24px rgba(43, 36, 32, 0.10), 0 2px 6px rgba(43, 36, 32, 0.06);
  --shadow-lg: 0 20px 48px rgba(43, 36, 32, 0.16), 0 6px 16px rgba(43, 36, 32, 0.08);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font-display: 'Nunito', system-ui, sans-serif;
  --font-body: 'Karla', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1613;
    --bg-elevated: #241f1b;
    --ink: #f2ece4;
    --ink-soft: #b7ab9d;
    --ink-faint: #7d7267;
    --accent: #e2954a;
    --accent-soft: #4a3a24;
    --accent-ink: #f6d9ac;
    --good: #6cbf78;
    --good-soft: #253a29;
    --miss: #e08a68;
    --miss-soft: #402a22;
    --pause: #a99cea;
    --pause-soft: #322c4a;
    --line: #362f29;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; }

.app { min-height: 100%; }
.screen { width: 100%; }

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #b8631a);
  color: #fff9f1;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { box-shadow: var(--shadow-md); }

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}
.btn-ghost:hover { background: var(--line); color: var(--ink); }

.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 8px; }
.btn-big { padding: 16px 26px; font-size: 16px; }

.btn-primary.is-given {
  background: linear-gradient(135deg, var(--good), #3d8248);
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, var(--accent-soft) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, var(--good-soft) 0%, transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 32px;
  text-align: center;
}

.login-photo {
  width: 128px;
  height: 128px;
  margin: -80px auto 14px;
  border-radius: 50%;
  overflow: hidden;
  border: 5px solid var(--bg-elevated);
  box-shadow: var(--shadow-md);
  background: var(--accent-soft);
}
.login-photo img { width: 100%; height: 100%; object-fit: cover; }

.login-title {
  font-size: 30px;
  font-weight: 900;
  color: var(--ink);
}
.login-title .dot { color: var(--accent); }

.login-subtitle {
  margin: 2px 0 24px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.login-form { text-align: left; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline span { white-space: nowrap; }
.field-inline input { width: 84px; text-align: center; }

.login-hint {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-faint);
  margin: 0;
}

.login-error {
  background: var(--miss-soft);
  color: var(--miss);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  margin: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-cat { font-size: 24px; }
.topbar-title { font-family: var(--font-display); font-weight: 900; font-size: 17px; line-height: 1.1; }
.topbar-subtitle { font-size: 11.5px; color: var(--ink-soft); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.me-name { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

/* ---------- Content ---------- */

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 18px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Photo gallery ---------- */

.gallery {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 18px 0 10px;
}
.gallery-photo {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--bg-elevated);
  box-shadow: var(--shadow-md);
  background: var(--accent-soft);
}
.gallery-photo.r-1 { transform: rotate(-8deg) translateY(6px); }
.gallery-photo.r-2 { width: 100px; height: 100px; transform: translateY(-6px); z-index: 1; }
.gallery-photo.r-3 { transform: rotate(8deg) translateY(6px); }

/* ---------- Break banner ---------- */

.break-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--pause-soft);
  color: var(--accent-ink);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.break-banner-text { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.break-banner-text strong { color: var(--pause); font-size: 14px; }

/* ---------- Today card ---------- */

.today-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 22px 22px;
  box-shadow: var(--shadow-md);
}
.today-label { font-size: 13px; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.today-status { font-size: 19px; font-weight: 800; margin-top: 4px; font-family: var(--font-display); }
.today-status.given { color: var(--good); }
.today-status.pending { color: var(--ink-faint); }

/* ---------- Stats ---------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stat-tile {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-value { font-family: var(--font-display); font-size: 22px; font-weight: 900; color: var(--accent); }
.stat-label { font-size: 10.5px; color: var(--ink-soft); font-weight: 600; margin-top: 2px; line-height: 1.3; }

/* ---------- Panels ---------- */

.panel {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px 20px 22px;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.panel-header h2 { font-size: 16px; font-weight: 800; }
.panel-text { font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; margin: 0 0 14px; }

.chart-legend { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-soft); font-weight: 600; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.legend-dot:first-child { margin-left: 0; }
.legend-given { background: var(--good); }
.legend-missed { background: var(--miss); }
.legend-break { background: var(--pause); }

.chart-wrap { position: relative; width: 100%; }

/* ---------- Calendar ---------- */

.calendar-nav { display: flex; gap: 4px; }
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--bg);
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, background 0.15s ease;
}
.cal-day:active { transform: scale(0.92); }
.cal-day.empty { visibility: hidden; cursor: default; }
.cal-day.future { color: var(--ink-faint); cursor: default; opacity: 0.5; }
.cal-day.today { box-shadow: 0 0 0 2px var(--accent) inset; }
.cal-day.given { background: var(--good-soft); color: var(--good); }
.cal-day.missed { background: var(--miss-soft); color: var(--miss); }
.cal-day.on-break { background: var(--pause-soft); color: var(--pause); }
.cal-day .dose-count {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 8.5px;
  font-weight: 800;
  opacity: 0.8;
}
.calendar-hint { font-size: 12px; color: var(--ink-faint); margin: 12px 0 0; }

/* ---------- User list ---------- */

.user-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.user-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
}
.user-list .u-count { color: var(--accent); font-weight: 800; }
.user-list-empty { color: var(--ink-faint); font-size: 13.5px; padding: 6px 0; }

/* ---------- Event log ---------- */

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}
.event-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.event-item:last-child { border-bottom: none; }
.event-icon { font-size: 15px; line-height: 1.4; }
.event-text { flex: 1; line-height: 1.4; }
.event-text b { font-weight: 700; }
.event-time { color: var(--ink-faint); font-size: 11.5px; white-space: nowrap; padding-top: 2px; }
.event-list-empty { color: var(--ink-faint); font-size: 13.5px; padding: 6px 4px; }

/* ---------- Break form ---------- */

.break-form { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* ---------- Footer ---------- */

.app-footer {
  text-align: center;
  color: var(--ink-faint);
  font-size: 12px;
  padding: 10px 0 30px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(0);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.toast-error { background: var(--miss); color: #fff; }

/* ---------- Responsive ---------- */

@media (max-width: 420px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .today-card { flex-direction: column; align-items: stretch; text-align: center; }
  .today-card .btn-big { width: 100%; }
}
