/* ============ teme ============ */

:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --card: #ffffff;
  --soft: #eff2f7;
  --line: #e1e6ed;
  --line2: #c3cbd7;
  --fg: #0d1117;
  --mut: #57616f;
  --faint: #78828f;
  --acc: #e03131;
  --acc-ink: #c92a2a;
  --acc-soft: #fff1f1;
  --acc-line: #f3c2c2;
  --ok: #0ca678;
  --ok-ink: #087f5b;
  --top: rgba(244, 246, 249, .85);
  --sh-1: 0 1px 2px rgba(16, 24, 40, .06);
  --sh-2: 0 2px 4px rgba(16, 24, 40, .05), 0 12px 28px rgba(16, 24, 40, .09);
  --ring: rgba(224, 49, 49, .35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0e13;
    --card: #151a22;
    --soft: #1d242e;
    --line: #2b3441;
    --line2: #3f4a5b;
    --fg: #eef2f7;
    --mut: #a6b1c2;
    --faint: #8a96a8;
    --acc: #ff6b6b;
    --acc-ink: #ff8f8f;
    --acc-soft: #2b1619;
    --acc-line: #5e2b2d;
    --ok: #38d9a9;
    --ok-ink: #63e6be;
    --top: rgba(11, 14, 19, .85);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-2: 0 2px 6px rgba(0, 0, 0, .45), 0 14px 34px rgba(0, 0, 0, .5);
    --ring: rgba(255, 107, 107, .4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e13;
  --card: #151a22;
  --soft: #1d242e;
  --line: #2b3441;
  --line2: #3f4a5b;
  --fg: #eef2f7;
  --mut: #a6b1c2;
  --faint: #8a96a8;
  --acc: #ff6b6b;
  --acc-ink: #ff8f8f;
  --acc-soft: #2b1619;
  --acc-line: #5e2b2d;
  --ok: #38d9a9;
  --ok-ink: #63e6be;
  --top: rgba(11, 14, 19, .85);
  --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
  --sh-2: 0 2px 6px rgba(0, 0, 0, .45), 0 14px 34px rgba(0, 0, 0, .5);
  --ring: rgba(255, 107, 107, .4);
}

/* ============ bază ============ */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
input { min-width: 0; }
::placeholder { color: var(--faint); opacity: 1; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 6px; }
h2 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--mut); margin: 0; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--mut); }
.tiny { font-size: 12px; }
.grow { flex: 1; }
.center { text-align: center; }

/* ============ boot / gate ============ */

.boot, .gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 20; padding: 20px; }
.boot span { letter-spacing: .3em; color: var(--mut); font-size: 13px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.gate-box, .fatal { width: min(380px, 100%); text-align: center; display: grid; gap: 14px; justify-items: center; }
.fatal .tiny { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; word-break: break-word; }
.logo { font-weight: 800; letter-spacing: .2em; font-size: 19px; display: inline-flex; align-items: center; gap: 10px; }
.logo::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--acc); box-shadow: 0 0 0 4px var(--acc-soft); }
.logo.sm { font-size: 12.5px; letter-spacing: .16em; }
.gbtn { display: flex; justify-content: center; min-height: 44px; }
.link { background: none; border: 0; color: var(--mut); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; padding: 6px; }
.link:hover { color: var(--fg); }

/* ============ header ============ */

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--top);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.weeknav { display: flex; align-items: center; gap: 4px; }
.week { min-width: 0; text-align: center; line-height: 1.2; padding: 0 2px; }
.week strong { display: block; font-size: 13.5px; font-weight: 650; white-space: nowrap; }
.week .muted { font-size: 11px; white-space: nowrap; }
.icon {
  width: 32px; height: 32px; flex: none; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  cursor: pointer; display: grid; place-items: center; font-size: 17px; padding: 0;
  box-shadow: var(--sh-1); transition: border-color .15s, transform .08s;
}
.icon:hover { border-color: var(--line2); }
.icon:active { transform: scale(.94); }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--mut);
  border-radius: 99px; padding: 5px 11px; font-size: 11.5px; cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--fg); border-color: var(--line2); }
.sync { font-size: 11px; color: var(--mut); white-space: nowrap; }
.sync.on { color: var(--ok-ink); }
.sync.err { color: var(--acc-ink); }
.acct {
  display: inline-flex; align-items: center; gap: 7px; min-width: 0; flex: none;
  font-size: 12px; color: var(--mut); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 99px;
  padding: 3px 9px 3px 4px; transition: border-color .15s, color .15s;
}
.acct:hover { border-color: var(--line2); color: var(--fg); }
.acct img, .avatar { width: 23px; height: 23px; border-radius: 50%; flex: none; }
.avatar { background: var(--soft); color: var(--mut); display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.acct .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.acct svg { flex: none; opacity: .7; }

/* meniuri */
.menu {
  position: fixed; z-index: 60; min-width: 196px; max-width: calc(100vw - 16px);
  background: var(--card); border: 1px solid var(--line); border-radius: 13px;
  box-shadow: var(--sh-2); padding: 6px; display: grid; gap: 2px;
}
.menu-head {
  font-size: 11px; color: var(--faint); padding: 7px 10px 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.menu-item {
  text-align: left; border: 0; background: transparent; color: var(--fg);
  padding: 10px 11px; border-radius: 9px; cursor: pointer; font-size: 13.5px;
}
.menu-item:hover { background: var(--soft); }
.menu-item.danger { color: var(--acc); }
.menu-item.danger:hover { background: var(--acc-soft); }

/* comutator temă */
.seg {
  display: inline-flex; flex: none; padding: 2px; gap: 2px;
  background: var(--soft); border: 1px solid var(--line); border-radius: 99px;
}
.seg button {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: transparent; color: var(--mut);
  padding: 4px 9px; border-radius: 99px; cursor: pointer; font-size: 11.5px; line-height: 1;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--fg); box-shadow: var(--sh-1); font-weight: 600; }
.seg svg { display: block; }

/* ============ layout ============ */

main {
  max-width: 760px; margin: 0 auto; padding: 22px 16px 44px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
}
.card {
  min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 14px; box-shadow: var(--sh-1);
}
.cardhead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; min-width: 0; }
.prog { margin-left: auto; display: flex; align-items: center; gap: 9px; font-size: 11px; flex: none; }
.bar { width: 72px; height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 99px; transition: width .25s ease; }
.prog .muted { font-variant-numeric: tabular-nums; }

/* ============ taskuri ============ */

.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: r; min-width: 0; }
.tasks > li { min-width: 0; border-radius: 12px; counter-increment: r; transition: background .12s; }
.tasks > li:hover { background: var(--soft); }
.tasks > li.drag, .subs > li.drag { background: var(--card); box-shadow: var(--sh-2); position: relative; z-index: 3; }
body.dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.dragging .ttl, body.dragging .grip { cursor: grabbing; }

.row { display: flex; align-items: center; gap: 7px; padding: 7px 8px; min-width: 0; }

/* zonă de apucat generoasă, dar cu puncte mici desenate în centru */
.grip {
  flex: none; position: relative; width: 16px; height: 24px; cursor: grab; color: var(--faint);
  user-select: none; touch-action: none; border-radius: 6px;
  opacity: .5; transition: opacity .12s;
}
.grip::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 9px; height: 15px; transform: translate(-50%, -50%);
  background-image: radial-gradient(currentColor 1.2px, transparent 1.4px);
  background-size: 4.5px 5px; background-position: center;
}
.tasks > li:hover .grip, .subs > li:hover .grip, .grip:active { opacity: 1; }
.grip:active { cursor: grabbing; }

.rank {
  flex: none; min-width: 21px; height: 21px; padding: 0 6px; border-radius: 99px;
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  display: grid; place-items: center; background: var(--soft); color: var(--faint);
}
.rank::before { content: counter(r); }
.tasks > li:nth-child(-n+3) .rank { background: var(--acc-soft); color: var(--acc-ink); box-shadow: inset 0 0 0 1px var(--acc-line); }

.cb {
  flex: none; width: 21px; height: 21px; border-radius: 7px; border: 1.5px solid var(--line2);
  background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0;
  color: #fff; font-size: 13px; line-height: 1; transition: background .12s, border-color .12s, transform .08s;
}
.cb:hover { border-color: var(--ok); }
.cb:active { transform: scale(.9); }
.cb[data-s="1"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.cb[data-s="2"] { border-color: var(--ok); }
.cb[data-s="2"]::after { content: ""; width: 9px; height: 2px; background: var(--ok); border-radius: 2px; }

.ttl {
  flex: 1 1 60px; min-width: 0; width: 100%;
  background: transparent; border: 0; outline: none; color: var(--fg);
  padding: 3px 2px; border-bottom: 1px solid transparent; border-radius: 0;
  font: inherit; resize: none; overflow: hidden; line-height: 1.35;
  display: block; min-height: 22px;
}
.ttl:hover { border-bottom-color: var(--line); }
.ttl:focus { border-bottom-color: var(--acc); }
li.done > .row > .ttl { color: var(--faint); text-decoration: line-through; text-decoration-thickness: 1px; }

.acts { flex: none; display: flex; align-items: center; gap: 2px; }
.cnt {
  flex: none; font-size: 10.5px; font-weight: 600; color: var(--mut); background: var(--soft);
  border-radius: 99px; padding: 2px 8px; cursor: pointer; font-variant-numeric: tabular-nums;
  border: 0; margin-right: 2px;
}
.cnt:hover { color: var(--fg); }
.mini {
  flex: none; height: 28px; min-width: 28px; padding: 0 6px;
  border: 0; background: transparent; color: var(--faint); border-radius: 8px; cursor: pointer;
  font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  transition: background .12s, color .12s;
}
.mini:hover { color: var(--fg); background: var(--soft); }
.mini.del:hover { color: var(--acc); background: var(--acc-soft); }
.mini.on { color: var(--acc); background: var(--acc-soft); }
.mini .n { font-size: 10px; font-weight: 700; }
.mini svg { display: block; }

/* subtaskuri */
.subs {
  list-style: none; margin: 0 0 6px 20px; padding: 0 0 0 14px;
  border-left: 2px solid var(--line); display: grid; gap: 1px; min-width: 0;
}
.subs > li { min-width: 0; border-radius: 10px; transition: background .12s; }
.subs > li:hover { background: var(--soft); }
.subs > li.drag { background: var(--card); box-shadow: var(--sh-2); }
.subs .row { padding: 4px 6px; }
.subs .ttl { font-size: 14px; }

/* comentarii */
.notes {
  margin: 2px 0 8px 34px; padding: 10px 12px; min-width: 0;
  background: var(--soft); border-radius: 12px;
}
.subs .notes { margin-left: 14px; }
.nlist { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 7px; min-width: 0; }
.nlist:empty { display: none; }
.nlist li { display: flex; gap: 9px; align-items: baseline; font-size: 13px; min-width: 0; }
.nlist time { flex: none; color: var(--faint); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.nlist .ntxt { flex: 1 1 60px; min-width: 0; color: var(--fg); white-space: pre-wrap; overflow-wrap: anywhere; }
.nlist .mini { flex: none; height: 24px; min-width: 24px; font-size: 13px; }
.nadd { display: flex; gap: 6px; min-width: 0; }
.nadd input {
  flex: 1 1 auto; min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 10px; font-size: 13px; outline: none; color: var(--fg);
}
.nadd input:focus { border-color: var(--acc); box-shadow: 0 0 0 3px var(--ring); }

.empty { color: var(--mut); font-size: 13.5px; padding: 14px 6px; text-align: center; }

/* adăugare */
.add { display: flex; gap: 8px; margin-top: 12px; min-width: 0; }
.add input {
  flex: 1 1 auto; min-width: 0; background: var(--soft); border: 1px solid transparent;
  border-radius: 12px; padding: 11px 13px; outline: none; color: var(--fg);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.add input:focus { border-color: var(--acc); background: var(--card); box-shadow: 0 0 0 3px var(--ring); }
.add-b { width: 42px; height: 42px; flex: none; font-size: 20px; }

/* acțiuni */
.actions { display: flex; gap: 8px; align-items: center; min-width: 0; }
.actions button {
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 11px; padding: 9px 13px; cursor: pointer; font-size: 13px;
  box-shadow: var(--sh-1); transition: border-color .15s, transform .08s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.actions button:hover { border-color: var(--line2); }
.actions button:active { transform: translateY(1px); }
#btnCarry { flex: 0 1 auto; min-width: 0; }
.actions .more {
  flex: none; padding: 9px 11px; font-size: 12.5px; color: var(--mut);
  background: transparent; box-shadow: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.actions .more:hover { color: var(--fg); background: var(--soft); }
.actions .more svg { opacity: .7; }

/* fereastră cu pași */
.overlay {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(10, 14, 20, .5); padding: 18px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.sheet {
  width: min(400px, 100%); background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: 16px; padding: 18px 18px 16px;
  box-shadow: var(--sh-2); display: grid; gap: 12px;
}
.sheet h3 { margin: 0; font-size: 15px; font-weight: 700; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 9px; font-size: 13.5px; line-height: 1.5; }
.steps li { padding-left: 2px; }
.steps li::marker { color: var(--acc); font-weight: 700; }
.sheet .tiny { line-height: 1.55; }
.sheet-ok {
  justify-self: end; border: 1px solid var(--line); background: var(--soft); color: var(--fg);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; font-size: 13px;
}
.sheet-ok:hover { border-color: var(--line2); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
  padding: 11px 17px; border-radius: 12px; font-size: 13px; z-index: 50;
  box-shadow: var(--sh-2); max-width: calc(100vw - 32px); text-align: center;
}

/* ============ sub 760px ============ */

@media (max-width: 760px) {
  .top {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 10px; align-items: center; padding: 9px 12px;
  }
  .logo.sm { grid-column: 1; grid-row: 1; }
  .seg { grid-column: 2; grid-row: 1; justify-self: end; }
  .weeknav { grid-column: 1; grid-row: 2; justify-content: flex-start; gap: 6px; min-width: 0; }
  .acct { grid-column: 2; grid-row: 2; justify-self: end; }
  .acct .who { max-width: 74px; }
  .grow, .sync { display: none; }
  .seg button .lb { display: none; }
  .seg button { padding: 6px 9px; }
  main { padding: 14px 12px 28px; gap: 12px; }
  .card { padding: 13px 11px; border-radius: 14px; }

  /* 16px e pragul sub care Safari pe iOS dă zoom automat la focus.
     `.subs .ttl` are nevoie de regula lui, altfel specificitatea mai mare
     a selectorului de bază câștigă și subtaskul rămâne la 14px. */
  input, textarea, .ttl, .add input, .nadd input { font-size: 16px; }
  .subs .ttl { font-size: 16px; }

  /* zonă de atingere mai mare pentru deget, punctele rămân mici */
  .grip { width: 30px; height: 34px; opacity: .75; }
  .grip::before { width: 10px; height: 16px; }
}

/* ============ sub 560px: rândul se rupe pe două linii ============ */

@media (max-width: 560px) {
  .row { flex-wrap: wrap; row-gap: 2px; padding: 6px 6px; }
  .ttl { flex: 1 1 60px; }
  .acts { width: 100%; justify-content: flex-end; padding-left: 34px; margin-top: -2px; }
  .subs .acts { padding-left: 24px; }
  .grip { opacity: 1; }
  /* ținte de atingere mai generoase: +, comentariu, × */
  .mini { height: 38px; min-width: 40px; font-size: 17px; }
  .mini svg { width: 17px; height: 17px; }
  .nlist .mini { height: 32px; min-width: 32px; font-size: 15px; }
  .cnt { padding: 4px 11px; font-size: 12px; }
  .acts { gap: 4px; }
  .subs { margin-left: 10px; padding-left: 11px; }
  .notes { margin-left: 18px; padding: 9px 10px; }
  .subs .notes { margin-left: 8px; }
  .nlist li { flex-wrap: wrap; gap: 1px 8px; }
  .nlist time { width: 100%; }
  .prog .bar { width: 52px; }
  .actions { flex-wrap: wrap; }
  #btnCarry { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
