/* ===========================================================================
   Baddie Drücker System — design system
   =========================================================================== */

:root {
  --bg: #f3f4f8;
  --bg-elev: #ffffff;
  --bg-soft: #f7f7fb;
  --text: #1c1d2b;
  --text-muted: #6b6d80;
  --border: #e6e7ef;
  --primary: #6c5ce7;
  --primary-strong: #5b4bd6;
  --primary-soft: rgba(108, 92, 231, 0.12);
  --success: #21b573;
  --danger: #e5484d;
  --gold: #f5b301;
  --silver: #aab1c4;
  --bronze: #cd7f32;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(20, 20, 50, 0.08);
  --shadow-lg: 0 16px 48px rgba(20, 20, 50, 0.16);
  --heat-0: #ecedf3;
}

html[data-theme="dark"] {
  --bg: #0f1117;
  --bg-elev: #181a23;
  --bg-soft: #1f2230;
  --text: #eef0f6;
  --text-muted: #9aa0b4;
  --border: #272a37;
  --primary: #8b7bff;
  --primary-strong: #a596ff;
  --primary-soft: rgba(139, 123, 255, 0.16);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  --heat-0: #20232f;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.app-container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- Auth ---- */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 8vh auto;
  max-width: 420px;
  background-color: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo { font-size: 40px; display: block; }
.auth-container h2 { margin: 8px 0 0; font-size: 1.4rem; }

.tabs { display: flex; width: 100%; margin-bottom: 22px; gap: 6px; background: var(--bg-soft); padding: 5px; border-radius: var(--radius-sm); }
.tab {
  flex: 1; text-align: center; padding: 10px; cursor: pointer;
  border-radius: 8px; color: var(--text-muted); font-weight: 600;
  transition: background 0.2s, color 0.2s;
}
.tab.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

.auth-form { width: 100%; display: none; }
.auth-form.active { display: block; }

/* --------------------------------------------------------------- Forms ---- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.9rem; }
.form-group small { display: block; color: var(--text-muted); font-size: 0.78rem; margin-top: 0.3rem; }

input[type="text"],
input[type="password"],
input[type="datetime-local"],
input[type="file"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type="file"] { padding: 0.5rem; }

/* ------------------------------------------------------------- Buttons ---- */
.btn {
  background-color: var(--primary);
  border: none;
  color: #fff;
  padding: 0.7rem 1.2rem;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.2s, transform 0.05s;
  width: 100%;
}
.btn:hover { background-color: var(--primary-strong); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

.btn-success { background-color: var(--success) !important; }

.icon-btn {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.05s;
}
.icon-btn:hover { background: var(--primary-soft); }
.icon-btn:active { transform: translateY(1px); }

.logout-btn { background-color: transparent; color: var(--danger); border: 1px solid var(--border); width: auto; }
.logout-btn:hover { background-color: rgba(229, 72, 77, 0.1); }

/* -------------------------------------------------------------- Header ---- */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; }
.brand h1 { font-size: 1.3rem; margin: 0; }

.nav {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  padding: 5px;
  border-radius: var(--radius-sm);
  margin: 0 auto;
}
.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.nav-btn.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

.header-actions { display: flex; align-items: center; gap: 8px; }

/* --------------------------------------------------------------- Views ---- */
.view { display: none; animation: fade-in 0.25s ease; }
.view.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-title { margin: 0 0 4px; font-size: 1.3rem; }
.view-subtitle { margin: 0 0 20px; color: var(--text-muted); font-size: 0.9rem; }
.view-subtitle:empty { margin: 0; }
.view-quote {
  margin: 0 0 20px;
  padding: 10px 16px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.45;
}

.loading { text-align: center; padding: 40px; font-size: 1rem; color: var(--text-muted); }

/* ------------------------------------------------------------ Cards ------- */
.container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
}

.card {
  position: relative;
  background-color: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card.is-leader { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 12px 32px rgba(245, 179, 1, 0.25); }
.card.is-self { outline: 2px solid var(--primary-soft); }

.crown { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: 28px; z-index: 2; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25)); }

.card-header { margin-bottom: 14px; text-align: center; }
.user-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px;
  overflow: hidden;
  color: #fff; font-size: 1.8rem; font-weight: 700;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.card-header h3 { margin: 0; font-size: 1.05rem; }

.counter-container {
  text-align: center;
  margin: 8px 0 16px;
  width: 100%;
}
.counter-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 4px; }
.counter-value { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }

/* ------------------------------------------------------- Leaderboard ------ */
.lb-toggle {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-soft);
  padding: 5px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.lb-toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.lb-toggle-btn.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }

.leaderboard { display: flex; flex-direction: column; gap: 10px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.lb-rank { font-size: 1.1rem; font-weight: 800; width: 34px; text-align: center; color: var(--text-muted); }
.lb-row.rank-1 { border-color: var(--gold); }
.lb-row.rank-1 .lb-rank, .lb-row.rank-2 .lb-rank, .lb-row.rank-3 .lb-rank { font-size: 1.4rem; }
.lb-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; overflow: hidden; flex-shrink: 0;
}
.lb-avatar img { width: 100%; height: 100%; object-fit: cover; }
.lb-name { font-weight: 600; flex: 1; }
.lb-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-muted); }

/* ---------------------------------------------------------- Profile ------- */
.profile-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.profile-summary .lb-avatar { width: 64px; height: 64px; font-size: 1.4rem; }
.profile-stats { display: flex; gap: 28px; margin-left: auto; flex-wrap: wrap; }
.stat { text-align: center; }
.stat-value { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.75rem; color: var(--text-muted); }

.heatmap-title { font-size: 1rem; margin: 0 0 12px; }
.heatmap-wrap { width: 100%; padding-bottom: 8px; }
.heat-cell { cursor: default; transition: outline 0.1s; }
.heat-cell:hover { outline: 1px solid var(--text-muted); outline-offset: 1px; }

.heatmap-tooltip {
  position: absolute;
  z-index: 70;
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.heatmap-tooltip[hidden] { display: none; }
.heatmap-tooltip .tip-date { display: block; opacity: 0.7; font-size: 0.72rem; margin-top: 1px; }
.heatmap-tooltip::after {
  content: '';
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
}

.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, auto);
  grid-auto-columns: 1fr;
  gap: 3px;
  width: 100%;
}
.heat-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--heat-0); }
/* Inside the grid, cells flex to fill the available width and stay square. */
.heatmap .heat-cell { width: 100%; height: auto; aspect-ratio: 1 / 1; }
.heat-cell[data-level="1"] { background: rgba(108, 92, 231, 0.35); }
.heat-cell[data-level="2"] { background: rgba(108, 92, 231, 0.55); }
.heat-cell[data-level="3"] { background: rgba(108, 92, 231, 0.78); }
.heat-cell[data-level="4"] { background: var(--primary); }
.heat-clickable { cursor: pointer; }
.heatmap-legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 10px; font-size: 0.75rem; color: var(--text-muted); }
.heatmap-legend .heat-cell { display: inline-block; }
.heatmap-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.heatmap-nav .heatmap-range { font-size: 0.85rem; font-weight: 600; color: var(--text); min-width: 150px; text-align: center; }
.heatmap-nav .icon-btn { font-size: 1.3rem; line-height: 1; }
.heatmap-nav .icon-btn:disabled { opacity: 0.3; cursor: default; }
@media (max-width: 640px) {
  .heatmap { gap: 2px; }

  /* Stack the stats below the avatar/name and lay them out in a compact grid
     so they no longer sit beside the profile and eat vertical space. */
  .profile-summary { flex-wrap: wrap; gap: 12px 14px; padding: 16px; }
  .profile-summary .lb-avatar { width: 48px; height: 48px; font-size: 1.1rem; }
  .profile-stats {
    order: 3;
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px 10px;
  }
  .stat { text-align: left; }
  .stat-value { font-size: 1.05rem; }
  .stat-label { font-size: 0.68rem; }
}

/* ------------------------------------------------------- Day editor ------- */
.day-nav { position: relative; display: flex; align-items: center; gap: 10px; }
.day-nav h2 { margin: 0; font-size: 1.05rem; min-width: 0; cursor: pointer; }
.day-nav h2:hover { text-decoration: underline dotted; }
/* Hidden native date input; kept in-flow (0×0) so the picker anchors to the title. */
.day-date-picker {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.day-jump { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.btn-sm { width: auto; padding: 0.4rem 0.7rem; font-size: 0.78rem; }
.day-events { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 40vh; overflow-y: auto; }
.day-event {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.day-event-icon { font-size: 1.1rem; }
.day-event-time { flex: 1; }
.day-event-del { width: 34px; height: 34px; font-size: 0.95rem; flex-shrink: 0; }
.day-event-del:hover { background: rgba(229, 72, 77, 0.12); }
#day-add { margin-bottom: 14px; }

/* ---------------------------------------------------------- Modal --------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 9, 18, 0.55); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 0; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 18px 22px 22px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { width: auto; flex: 1; }

/* --------------------------------------------------------- Messages ------- */
.error-message {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  text-align: center;
  padding: 6px 8px;
  background-color: rgba(229, 72, 77, 0.1);
  border-radius: 8px;
}
.error-message:empty { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: toast-in 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
/* Keeps the horizontal centering (translateX(-50%)) while it fades in, so the
   toast doesn't appear off-centre and then snap to the middle. */
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.toast-action {
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.toast-action:hover { opacity: 0.85; }

/* --------------------------------------------------------- Responsive ----- */
@media (max-width: 640px) {
  .header { gap: 10px; }
  .brand h1 { font-size: 1.1rem; }
  .nav { order: 3; width: 100%; margin: 0; justify-content: space-between; }
  .nav-btn { flex: 1; }
  .header-actions { margin-left: auto; }
  .logout-btn { display: none; }
}
