/* ============ Tokeny ============ */
:root {
  --fog: #e6ebf0;      /* pozadí */
  --paper: #fafbfc;    /* karty */
  --ink: #141b24;      /* text */
  --slate: #5b6675;    /* vedlejší text */
  --line: #d3dae2;     /* linky, prázdné segmenty */
  --cell: #edf1f5;     /* prázdný den */
  --cobalt: #3557e6;   /* hlavní akce */
  --on-cobalt: #ffffff;
  --danger: #d63a2f;
  --ok: #2f8f4e;

  --f-display: "Bricolage Grotesque", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-card: 22px;
  --r-cell: 14px;
  --gap: 5px;
  --shadow: 0 1px 2px rgba(20, 27, 36, .04), 0 8px 28px rgba(20, 27, 36, .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fog: #11161d;
    --paper: #1a212b;
    --ink: #e9eef4;
    --slate: #95a1b0;
    --line: #2a3441;
    --cell: #222b36;
    --cobalt: #6e8bff;
    --on-cobalt: #0b1020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  }
}

/* ============ Základ ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.5;
  background: var(--fog);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
code { font-size: .9em; background: var(--cell); padding: 1px 6px; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; border-radius: 8px; }

.h-hero, .h-display, .wordmark, .streak b {
  font-family: var(--f-display);
  font-optical-sizing: auto;
}
.h-hero {
  font-size: clamp(3rem, 8vw, 5.75rem);
  font-weight: 800;
  font-stretch: 78%;
  line-height: .92;
  letter-spacing: -.02em;
  margin: 0;
}
.h-display { font-size: 1.6rem; font-weight: 700; font-stretch: 85%; line-height: 1.1; margin: 0 0 6px; letter-spacing: -.01em; }
.wordmark { font-weight: 800; font-size: 1.35rem; font-stretch: 80%; letter-spacing: -.02em; }
.wordmark::before {
  content: ""; display: inline-block; width: 26px; height: 12px; margin-right: 8px;
  border-radius: 6px; background: linear-gradient(90deg, var(--cobalt) 62%, var(--line) 62%);
  vertical-align: 1px;
}
.muted { color: var(--slate); margin: 0 0 20px; }
.lead { font-size: 1.15rem; color: var(--slate); max-width: 30rem; margin: 24px 0 36px; }

.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.panel {
  background: var(--paper);
  border-radius: var(--r-card);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  color: var(--ink);
}

/* Načítání: tři články řetězu */
.loader { display: flex; gap: 4px; }
.loader i { width: 22px; height: 22px; border-radius: 7px; background: var(--line); animation: load 1.2s infinite; }
.loader i:nth-child(2) { animation-delay: .15s; }
.loader i:nth-child(3) { animation-delay: .3s; }
@keyframes load { 30% { background: var(--cobalt); } 60% { background: var(--line); } }

/* ============ Tlačítka a pole ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 1.5px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 12px; padding: 11px 18px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--cobalt); border-color: var(--cobalt); color: var(--on-cobalt); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-google { width: 100%; }
.btn-google:hover:not(:disabled) { border-color: var(--slate); }
.btn-block { width: 100%; margin-top: 6px; }
.link { background: none; border: none; color: var(--cobalt); cursor: pointer; padding: 0; font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.field em { font-style: normal; font-weight: 400; color: var(--slate); }
input[type="text"], input[type="email"], input[type="password"] {
  display: block; width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  font: inherit; background: var(--paper); color: var(--ink);
  transition: border-color .15s;
}
input::placeholder { color: var(--slate); opacity: .8; }
input:focus { outline: none; border-color: var(--cobalt); }

.msg { font-size: .9rem; margin: 0 0 12px; font-weight: 500; }
.msg-error { color: var(--danger); }
.msg-ok { color: var(--ok); }

.divider { display: flex; align-items: center; gap: 12px; color: var(--slate); font-size: .8rem; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1.5px; background: var(--line); }

.tabs { display: flex; gap: 4px; background: var(--cell); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tab { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--slate); cursor: pointer; }
.tab.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 27, 36, .1); }
#btn-forgot { margin-top: 16px; font-size: .9rem; }

/* ============ Přihlašovací stránka ============ */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  align-items: center;
  gap: 48px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 48px 32px;
}
.auth-intro .wordmark { display: block; margin-bottom: 48px; }
.auth-form { display: flex; justify-content: center; }

/* ============ Řetěz (podpis celého designu) ============ */
.chain { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--gap); }
.cell {
  position: relative;
  height: 58px;
  border: none;
  border-radius: var(--r-cell);
  background: var(--cell);
  color: var(--slate);
  font: inherit;
  padding: 0;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
  transition: background .18s, color .18s;
}
.cell .dow { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.cell .num { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cell:hover:not(.on) { background: color-mix(in srgb, var(--c) 14%, var(--cell)); }
.cell.today:not(.on) { box-shadow: inset 0 0 0 2px var(--c); color: var(--ink); }
.cell.on { background: var(--c); color: #fff; }
/* Spojení sousedních splněných dnů do jednoho článku */
.cell.on.jl { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cell.on.jr { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.cell.on.jl::before {
  content: "";
  position: absolute; top: 0; bottom: 0;
  left: calc(-1 * var(--gap) - 1px);
  width: calc(var(--gap) + 2px);
  background: var(--c);
}
.cell.pop { animation: pop .34s cubic-bezier(.3, 1.7, .5, 1); }
@keyframes pop { from { transform: scaleY(.78); filter: brightness(1.25); } to { transform: none; filter: none; } }

/* Ukázkový řetěz na přihlašovací stránce se postupně vyplní */
.demo { --c: var(--cobalt); max-width: 30rem; }
.demo .cell { cursor: default; }
.demo .cell.on { animation: fill .3s ease both; animation-delay: calc(var(--i) * 170ms + 400ms); }
.demo .cell.on.jl::before { animation: fill .3s ease both; animation-delay: calc(var(--i) * 170ms + 400ms); }
.demo .cell.today { animation: ring 1.6s ease-in-out infinite; animation-delay: 1.6s; }
@keyframes fill { from { background: var(--cell); color: var(--slate); } }
@keyframes ring { 50% { box-shadow: inset 0 0 0 2px var(--c), 0 0 0 5px color-mix(in srgb, var(--c) 22%, transparent); } }

/* ============ Aplikace ============ */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 760px; margin: 0 auto; padding: 20px 20px 0;
}
.user { position: relative; }
.avatar-btn {
  display: flex; align-items: center; gap: 10px; background: none; border: none;
  font: inherit; color: var(--slate); cursor: pointer; padding: 4px; border-radius: 999px;
}
.user-name { font-size: .9rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--paper); font-weight: 700; font-size: .95rem;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow), 0 0 0 1px var(--line);
  display: flex; flex-direction: column; min-width: 200px; padding: 6px;
}
.menu button { background: none; border: none; text-align: left; padding: 10px 12px; border-radius: 9px; font: inherit; color: var(--ink); cursor: pointer; }
.menu button:hover { background: var(--cell); }
.menu .danger { color: var(--danger); }

.container { max-width: 760px; margin: 0 auto; padding: 8px 20px 80px; }
.banner {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between;
  background: color-mix(in srgb, #e09a00 16%, var(--paper)); border-radius: 14px;
  padding: 12px 16px; margin: 20px 0 0; font-size: .92rem;
}

.today-head { padding: 44px 0 28px; }
.h-date { font-size: clamp(2.6rem, 7.5vw, 4.5rem); }
.h-date::first-letter { text-transform: uppercase; }
.progress { display: flex; align-items: center; gap: 16px; margin-top: 22px; }
.segments { display: flex; gap: 4px; flex: 1; max-width: 320px; }
.segments i { flex: 1; height: 10px; border-radius: 5px; background: var(--line); transition: background .25s; }
.progress-text { font-size: .92rem; color: var(--slate); font-weight: 500; white-space: nowrap; }

.habits { display: flex; flex-direction: column; gap: 14px; }
.habit {
  background: var(--paper); border-radius: var(--r-card); padding: 18px 18px 14px;
  box-shadow: var(--shadow);
}
.habit-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.habit-name { flex: 1; min-width: 0; padding-top: 4px; }
.name-text {
  display: inline-block; max-width: 100%; font-size: 1.12rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top;
  cursor: text; border-radius: 6px; padding: 0 4px; margin-left: -4px;
}
.name-text:hover { background: var(--cell); }
.name-input { font-size: 1.05rem !important; padding: 4px 10px !important; }
.streak { text-align: right; line-height: 1; flex: none; }
.streak b { display: block; font-size: 2.1rem; font-weight: 800; font-stretch: 80%; color: var(--c); font-variant-numeric: tabular-nums; }
.streak b.zero { color: var(--line); }
.streak span { font-size: .75rem; color: var(--slate); font-weight: 500; }
.meta { display: flex; justify-content: space-between; align-items: center; margin: 12px 0 0; font-size: .82rem; color: var(--slate); font-variant-numeric: tabular-nums; }
.del {
  background: none; border: none; color: var(--slate); cursor: pointer;
  padding: 4px 6px; border-radius: 8px; font: inherit; font-size: .82rem;
  opacity: 0; transition: opacity .15s, color .15s;
}
.habit:hover .del, .habit:focus-within .del { opacity: 1; }
.del:hover { color: var(--danger); background: var(--cell); }
@media (hover: none) { .del { opacity: 1; } }

.empty {
  text-align: center; color: var(--slate); margin: 0; padding: 36px 24px;
  border: 2px dashed var(--line); border-radius: var(--r-card);
}

.add { margin-top: 24px; padding: 18px; border-radius: var(--r-card); border: 2px dashed var(--line); }
.add-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 10px; }
.add-row { display: flex; gap: 10px; }
.add-row input { flex: 1; min-width: 0; }
.colors { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; border: none; cursor: pointer; padding: 0;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.1); }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--fog), 0 0 0 5px var(--ink); }

dialog.panel { border: none; padding: 28px; }
dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ============ Mobil ============ */
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; gap: 36px; padding: 28px 18px 40px; min-height: 0; }
  .auth-intro .wordmark { margin-bottom: 28px; }
  .lead { margin: 16px 0 24px; font-size: 1.05rem; }
  .auth-form { justify-content: stretch; }
  .auth-form .panel { max-width: none; }
}
@media (max-width: 520px) {
  :root { --gap: 4px; }
  .panel { padding: 24px 20px; }
  .container { padding: 4px 12px 60px; }
  .topbar { padding: 16px 14px 0; }
  .user-name { display: none; }
  .today-head { padding: 28px 4px 20px; }
  .habit { padding: 16px 12px 12px; }
  .cell { height: 54px; border-radius: 12px; }
  .cell .dow { font-size: .62rem; }
}

/* ============ Drobnosti ============ */
.pw { position: relative; }
.pw input { padding-right: 92px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font: inherit; font-size: .82rem; font-weight: 600;
  color: var(--slate); padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.pw-toggle:hover { color: var(--ink); background: var(--cell); }

.empty p { margin: 0 0 16px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 7px 14px 7px 10px; font: inherit; font-size: .9rem; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: border-color .15s, transform .1s;
}
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip:hover:not(:disabled) { border-color: var(--c); }
.chip:active:not(:disabled) { transform: scale(.97); }
.chip:disabled { opacity: .5; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  max-width: calc(100vw - 24px); width: max-content;
  padding: 12px 14px 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--paper);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  font-size: .95rem; font-weight: 500;
  animation: toast-in .22s ease-out;
}
.toast-error { background: var(--danger); color: #fff; }
.toast-milestone { padding-left: 14px; }
.toast-milestone::before {
  content: ""; flex: none; width: 34px; height: 14px; border-radius: 7px;
  background: linear-gradient(90deg, var(--c) 0 30%, transparent 30% 35%, var(--c) 35% 65%, transparent 65% 70%, var(--c) 70%);
}
.toast-action {
  flex: none; background: none; border: none; font: inherit; font-weight: 700;
  color: inherit; text-decoration: underline; text-underline-offset: 3px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer;
}
.toast-action:focus-visible { outline-color: var(--paper); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
