/* WeekBoard — weekly grid planner */

:root {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --cell: #e9ecf4;
  --cell-hover: #e3e7f1;
  --line: #dfe3ee;
  --text: #171a23;
  --muted: #79819a;
  --accent: #4f6ef7;
  --danger: #d9485f;
  --shadow: 0 1px 2px rgba(18, 24, 45, .08), 0 1px 1px rgba(18, 24, 45, .04);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101219;
    --surface: #1a1d27;
    --surface-2: #151821;
    --cell: #20242f;
    --cell-hover: #262b38;
    --line: #2c3140;
    --text: #e9ebf3;
    --muted: #8a92a8;
    --danger: #f27086;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ── Login ─────────────────────────────────────────────── */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(79, 110, 247, .16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(14, 165, 164, .12), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 18px 50px rgba(20, 26, 50, .12);
  text-align: center;
}

.login-card h1 { margin: 14px 0 2px; font-size: 22px; letter-spacing: -.02em; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card .field { text-align: left; }
.login-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(145deg, #5b7bff, #3f57d6);
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: 0 4px 12px rgba(79, 110, 247, .3);
}
.brand-mark svg { width: 20px; height: 20px; fill: #fff; }
.brand-mark svg .dim { fill: rgba(255, 255, 255, .42); }
.brand-mark.big { width: 52px; height: 52px; border-radius: 15px; margin: 0 auto; }
.brand-mark.big svg { width: 32px; height: 32px; }

/* ── App shell ─────────────────────────────────────────── */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }

.weeknav { display: flex; align-items: center; gap: 6px; }
.week-range {
  margin-left: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.tools { margin-left: auto; display: flex; align-items: center; gap: 8px; position: relative; }

.search {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  height: 34px;
  width: 190px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
}
.search svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; flex: none; }
.search input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 13px;
  color: var(--text);
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ── Buttons ───────────────────────────────────────────── */

.icon-btn {
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background .12s, border-color .12s;
}
.icon-btn:hover { background: var(--cell); }

.ghost-btn {
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--surface-2); }

.primary-btn {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(79, 110, 247, .28);
  transition: filter .12s, transform .05s;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.wide { width: 100%; justify-content: center; height: 40px; }
.primary-btn .plus { font-size: 16px; font-weight: 400; margin-top: -1px; }

.text-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 2px;
}
.text-btn.danger { color: var(--danger); }

.menu-btn { font-size: 16px; padding-bottom: 6px; }

.menu {
  position: absolute;
  top: 42px;
  right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 20, 40, .18);
  padding: 6px;
  z-index: 40;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 13.5px;
  cursor: pointer;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ── Grid ──────────────────────────────────────────────── */

.board {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  grid-template-rows: 52px minmax(0, 1fr);
  gap: 6px;
  padding: 10px 0 0 14px;
}

/* Frozen time column and day header live outside the scrolling grid and follow
   it by transform: sticky grid items are clamped to their own grid area and
   would slide away as soon as the row leaves the viewport. */

.corner { border-radius: 10px; }

.day-heads { overflow: hidden; min-width: 0; }
.day-heads-inner {
  display: grid;
  grid-template-columns: repeat(7, minmax(var(--colw, 148px), 1fr));
  gap: 6px;
  padding-right: 14px;
  height: 52px;
  will-change: transform;
}

.day-head {
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 10px;
  user-select: none;
}
.day-head .dow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.day-head .dnum {
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.day-head.today .dow { color: var(--accent); }
.day-head.today .dnum { background: var(--accent); color: #fff; }
.day-head.weekend .dow { color: #c0703c; }
.day-head.today.weekend .dow { color: var(--accent); }

.time-col { overflow: hidden; }
.time-col-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  will-change: transform;
}

.row-label {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 10px 6px 0 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}
.row-label.allday { color: var(--text); opacity: .65; }

.board-scroll {
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: 30px;
  min-width: 0;
  scrollbar-color: var(--line) transparent;
}

.cells {
  display: grid;
  grid-template-columns: repeat(7, minmax(var(--colw, 148px), 1fr));
  gap: 6px;
  padding-right: 14px;
  align-items: stretch;
}

.cell {
  position: relative;
  min-height: 82px;
  background: var(--cell);
  border-radius: 10px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: background .12s, box-shadow .12s;
}
.cell.weekend { background: color-mix(in srgb, var(--cell) 93%, #c9b48c); }
.cell.today { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent); }
.cell.drop-target {
  background: color-mix(in srgb, var(--accent) 14%, var(--cell));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.cell.no-match .card { display: none; }

.cell-add {
  order: 99;
  align-self: stretch;
  height: 22px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.cell:hover .cell-add { opacity: .55; }
.cell-add:hover { opacity: 1; background: rgba(127, 137, 160, .14); }

.cell-input {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px 8px;
  font-size: 13px;
  outline: none;
  box-shadow: 0 2px 10px rgba(79, 110, 247, .18);
}

/* ── Card ──────────────────────────────────────────────── */

.card {
  position: relative;
  background: var(--surface);
  border-radius: 9px;
  border-left: 3px solid var(--accent);
  padding: 6px 24px 6px 8px;
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
  transition: box-shadow .12s, transform .08s;
  user-select: none;
  -webkit-user-select: none;
}
.card:hover { box-shadow: 0 3px 10px rgba(18, 24, 45, .12); }
.card:active { cursor: grabbing; }
.card.is-dragged { opacity: .28; }

.card-title {
  font-size: 13px;
  line-height: 1.32;
  font-weight: 500;
  word-break: break-word;
  white-space: pre-wrap;
}
.card-note {
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.card.done .card-title { text-decoration: line-through; color: var(--muted); }
.card.done { opacity: .72; }
.card.done .card-note { opacity: .8; }

.card-check {
  position: absolute;
  top: 6px;
  right: 5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: .55;
  transition: opacity .12s, border-color .12s, background .12s;
}
.card:hover .card-check { opacity: 1; }
.card-check:hover { border-color: var(--accent); }
.card-check.on {
  background: var(--accent);
  border-color: var(--accent);
  opacity: 1;
}
.card-check.on::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 1.7px solid #fff;
  border-bottom: 1.7px solid #fff;
  transform: rotate(-45deg) translate(0, -1px);
}

.dragging-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  transform: rotate(2deg) scale(1.02);
  box-shadow: 0 14px 34px rgba(15, 20, 40, .28);
  opacity: .96;
  cursor: grabbing;
}

.empty-hint {
  position: absolute;
  left: 50%;
  top: 84px;
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(560px, calc(100% - 150px));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(20, 26, 45, .08);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  padding: 10px 14px;
  pointer-events: none;
}
.empty-hint b { color: var(--text); font-weight: 600; }

/* ── Sync pill ─────────────────────────────────────────── */

.sync {
  position: fixed;
  left: 14px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  z-index: 30;
  pointer-events: none;
  transition: opacity .3s;
}
.sync .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2fae74;
}
.sync.busy .dot { background: #e0a325; }
.sync.error .dot { background: var(--danger); }
.sync.idle { opacity: 0; }

/* ── Modals ────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 16, 28, .46);
  backdrop-filter: blur(3px);
  animation: fade .14s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: min(470px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 24px 70px rgba(10, 14, 30, .35);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }

.field {
  display: block;
  margin-bottom: 12px;
}
.field > span {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.field textarea { resize: vertical; min-height: 68px; }
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 2px; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--sw);
  cursor: pointer;
  padding: 0;
  transition: transform .1s, box-shadow .1s;
}
.swatch:hover { transform: scale(1.08); }
.swatch.sel { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw); }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  margin: 4px 0 14px;
  cursor: pointer;
  user-select: none;
}
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.spacer { flex: 1; }

.hint-text { margin: -4px 0 12px; color: var(--muted); font-size: 12.5px; }

.rows-editor { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row-item { display: flex; gap: 8px; align-items: center; }
.row-item input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  padding: 8px 10px;
  font-size: 13.5px;
  outline: none;
}
.row-item input:focus { border-color: var(--accent); }
.row-item .icon-btn { font-size: 14px; color: var(--muted); }

/* ── Mobile ────────────────────────────────────────────── */

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 9px 12px;
  }
  .brand { order: 1; }
  .tools { order: 2; gap: 6px; }
  .weeknav { order: 3; width: 100%; }
  .week-range { margin-left: auto; font-size: 12.5px; }
  .search { display: none; }
  .primary-btn { height: 32px; padding: 0 11px; }

  :root { --colw: 76vw; }

  .board {
    grid-template-columns: 46px minmax(0, 1fr);
    grid-template-rows: 46px minmax(0, 1fr);
    gap: 5px;
    padding: 6px 0 0 10px;
  }
  .day-heads-inner { gap: 5px; padding-right: 10px; height: 46px; }
  .cells { gap: 5px; padding-right: 10px; }
  .time-col-inner { gap: 5px; }
  .day-head { height: 46px; align-items: flex-start; padding-left: 8px; }
  .day-head .dnum { font-size: 16px; }
  .row-label { font-size: 10px; padding: 8px 4px 0 0; white-space: normal; line-height: 1.2; }
  .cell { min-height: 76px; }
  .empty-hint { top: 62px; max-width: calc(100% - 40px); font-size: 12px; padding: 8px 10px; }
  .sync { left: 10px; bottom: 10px; }
  .sheet { padding: 16px; border-radius: 16px; }
}

@media (hover: none) {
  .cell-add { opacity: .45; }
  .card-check { opacity: .8; }
}

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