/* ============================================================
   tobedone — структурные стили (топбар, грид, плитки, модалка)
   ============================================================ */

body { position: relative; }
body > * { position: relative; z-index: 1; }

/* ── Topbar ─────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-spacer { flex: 1; }

.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px;
  background: var(--accent-terra);
  color: #fffaf0;
  border-radius: 8px;
  font-weight: 700; font-size: 14px;
  letter-spacing: -1px;
  transform: rotate(-3deg);
  box-shadow: var(--shadow-sm);
}
.brand-text {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.4px;
  color: var(--ink);
}

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  padding: 7px 12px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  min-width: 220px;
  max-width: 320px;
  flex: 0 1 280px;
}
.search input {
  border: none; background: transparent; outline: none;
  flex: 1; font-size: 13px; color: var(--ink);
  min-width: 0;
}
.search input::placeholder { color: var(--ink-faint); }

.iconbtn, .avatar {
  width: 34px; height: 34px;
  border-radius: var(--radius-button);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
}
.avatar {
  border-radius: 999px;
  background: var(--accent-indigo);
  color: #fffaf0;
  font-weight: 600; font-size: 12px;
  letter-spacing: 0.5px;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-button);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  font-weight: 500; font-size: 13px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.btn:hover { background: var(--surface); }
.btn-primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.btn-primary:hover { background: var(--ink); opacity: 0.92; }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(196, 62, 47, 0.4);
}
.btn-danger:hover { background: rgba(196, 62, 47, 0.08); }
.btn-block { width: 100%; justify-content: center; }

/* ── Sync indicator ─────────────────────────────────────────── */

.sync {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: none; padding: 4px 6px; border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.3px;
}
.sync-bubble {
  position: relative;
  display: inline-grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 999px;
  background: color-mix(in oklab, currentColor 12%, transparent);
}
.sync[data-state="synced"]  { color: var(--accent-olive); }
.sync[data-state="syncing"] { color: var(--accent-indigo); }
.sync[data-state="offline"] { color: var(--ink-faint); }
.sync[data-state="error"]   { color: var(--accent-terra); }
.sync-label { text-transform: uppercase; opacity: 0.85; }
.sync-pulse {
  position: absolute; top: -1px; right: -1px;
  width: 8px; height: 8px; border-radius: 999px;
  background: currentColor;
  animation: sync-pulse 1.1s ease-in-out infinite;
}
.sync[data-state="syncing"] .sync-icon { animation: sync-spin 1.1s linear infinite; display: inline-flex; }
@keyframes sync-spin { to { transform: rotate(360deg); } }
@keyframes sync-pulse { 0%, 100% { transform: scale(0.6); opacity: 0.4; } 50% { transform: scale(1.2); opacity: 1; } }

/* ── User menu ──────────────────────────────────────────────── */

.user-menu {
  position: absolute;
  top: 58px;
  right: 16px;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 20;
}
.user-menu-name { font-weight: 600; }
.user-menu-email { color: var(--ink-soft); font-size: 12px; margin-top: 2px; word-break: break-all; }
.user-menu-divider { height: 1px; background: var(--border); margin: 10px 0; }
.user-menu-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
}
.user-menu-item:hover { background: var(--surface-2); }

/* ── App layout ─────────────────────────────────────────────── */

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.section-header { margin-bottom: 22px; }
.section-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
}
.section-title {
  margin: 0;
  font-weight: 600;
  font-size: 38px;
  letter-spacing: -0.8px;
}

.empty {
  margin-top: 60px;
  text-align: center;
  color: var(--ink-soft);
}
.empty p { margin-bottom: 16px; }

/* ── Tile grid (bento) ──────────────────────────────────────── */

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 132px;
  /* Намеренно НЕ используем grid-auto-flow: dense — он переставляет плитки
     визуально не по DOM-порядку, что ломает индексацию SortableJS. */
  gap: 16px;
}
.tile-grid .tile--s    { grid-column: span 1; grid-row: span 1; }
.tile-grid .tile--m    { grid-column: span 2; grid-row: span 1; }
.tile-grid .tile--wide { grid-column: span 3; grid-row: span 1; }
.tile-grid .tile--l    { grid-column: span 2; grid-row: span 2; }

/* tablet */
@media (max-width: 1100px) {
  .tile-grid { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 124px; gap: 14px; }
  .tile-grid .tile--wide { grid-column: span 3; }
  .section-title { font-size: 32px; }
}

/* phone */
@media (max-width: 700px) {
  .topbar { padding: 12px 14px; gap: 8px; flex-wrap: wrap; }
  .search { display: none; }
  .sync-label { display: none; }
  .hide-on-phone { display: none; }
  .app-main { padding: 18px 14px 80px; }
  .section-title { font-size: 26px; }
  .tile-grid { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 116px; gap: 12px; }
  .tile-grid .tile--wide { grid-column: span 2; }
  .tile-grid .tile--m    { grid-column: span 2; }
  .tile-grid .tile--l    { grid-column: span 2; grid-row: span 2; }
}

/* ── Tile ───────────────────────────────────────────────────── */

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-tile);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: #fffaf0;
  cursor: grab;
  user-select: none;
  transition: transform 220ms cubic-bezier(.2,.7,.3,1.4), box-shadow 200ms, opacity 200ms;
}
.tile:active { cursor: grabbing; }
.tile.dragging, .tile.sortable-ghost {
  opacity: 0.6;
}
.tile.sortable-chosen { box-shadow: var(--shadow-lg); }

.tile-bg-terra   { background: var(--accent-terra); }
.tile-bg-indigo  { background: var(--accent-indigo); }
.tile-bg-olive   { background: var(--accent-olive); }
.tile-bg-mustard { background: var(--accent-mustard); color: #1f1a14; }
.tile-bg-rose    { background: var(--accent-rose); }
.tile-bg-clay    { background: var(--accent-clay); }

.tile-body {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 10px;
  z-index: 2;
}

.tile-head {
  display: flex; align-items: center; gap: 8px;
}
.tile-check {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 1.6px solid currentColor;
  background: transparent;
  color: inherit;
  padding: 0;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.tile-check.done { background: currentColor; }
.tile-check.done svg { color: var(--accent-terra); }
.tile-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  opacity: 0.78;
}
.tile-due-short {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.78;
  white-space: nowrap;
}

.tile-title {
  margin: 0;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.18;
  letter-spacing: -0.2px;
}
.tile.tile--l .tile-title { font-size: 22px; }
.tile.tile--wide .tile-title { font-size: 19px; }
.tile.tile--s .tile-title { font-size: 15px; }
.tile.done .tile-title { text-decoration: line-through; }
.tile.done { opacity: 0.55; }

.tile-note {
  margin: 0;
  font-size: 13px;
  opacity: 0.82;
  line-height: 1.35;
}
.tile.tile--s .tile-note { display: none; }

.tile-footer {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.85;
  display: inline-flex; align-items: center; gap: 4px;
}

.tile-heat {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 1;
}

.tile-del {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  border: none;
  display: grid; place-items: center;
  opacity: 0; transition: opacity 160ms, transform 160ms, background 160ms;
  z-index: 5;
  padding: 0;
}
.tile:hover .tile-del,
.tile:focus-within .tile-del { opacity: 1; }
.tile-del:hover { background: rgba(0,0,0,0.28); transform: scale(1.08); }

.tile-meter {
  position: relative;
  height: 10px;
  background: rgba(0, 0, 0, 0.18);
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  overflow: hidden;
}
.tile-meter-fill {
  position: absolute; inset: 0;
  width: 0%;
  transition: width 600ms ease, background 200ms;
}
.tile-meter-fill.overdue {
  background: repeating-linear-gradient(45deg,
    rgb(196, 62, 47) 0 6px, rgba(255, 255, 255, 0.25) 6px 12px) !important;
}

/* ── Modal ──────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 14, 8, 0.45);
  z-index: 100;
  backdrop-filter: blur(2px);
}

.task-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  border: none;
  background: var(--surface);
  color: var(--ink);
  border-radius: 14px;
  padding: 22px;
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100dvh - 40px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  z-index: 101;
}
.task-modal::backdrop { background: rgba(20, 14, 8, 0.45); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-close {
  border: none; background: transparent; color: var(--ink-soft);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-2); }

.modal-footer {
  display: flex; gap: 10px; align-items: center;
  margin-top: 16px;
}

/* ── Form ───────────────────────────────────────────────────── */

.field {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 12px;
}
.field > span {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.field input, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field textarea:focus {
  border-color: var(--accent-terra);
  background: var(--surface);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.sw.selected { border-color: var(--ink); }
.sw-terra   { background: var(--accent-terra); }
.sw-indigo  { background: var(--accent-indigo); }
.sw-olive   { background: var(--accent-olive); }
.sw-mustard { background: var(--accent-mustard); }
.sw-rose    { background: var(--accent-rose); }
.sw-clay    { background: var(--accent-clay); }

.sizes { display: flex; gap: 6px; }
.sizes > button {
  flex: 1;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
}
.sizes > button.selected {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

/* ── Auth screens ───────────────────────────────────────────── */

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 22px;
}
.auth-title {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.6px;
}
.auth-sub {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 14px;
}
.auth-error {
  background: rgba(196, 62, 47, 0.08);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.auth-alt {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
}
