/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #eef0f5;
  --card: #ffffff;
  --text: #1c2635;
  --muted: #8a97a8;
  --faint: #b8c2cc;
  --line: #e2e6ec;
  --field: #f7f8fa;
  --accent: #5b8ef5;
  --accent-dark: #4278e0;
  --accent-soft: #edf2ff;
  --red: #e05050;
  --red-soft: #fff0f0;
  --orange: #e8890c;
  --orange-soft: #fef3e2;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: max(24px, env(safe-area-inset-top)) 16px max(48px, env(safe-area-inset-bottom));
}
body.modal-open { overflow: hidden; }

button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }

/* ── Header ── */
.header {
  position: relative;
  text-align: center;
  max-width: 860px;
  margin: 0 auto 22px;
  min-height: 44px;
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  padding: 0 52px;
}
.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 5px;
  font-size: 12px;
  color: #9aabb8;
  min-height: 18px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #c8d0da; flex-shrink: 0; }
.status-dot.saving  { background: #f5c842; }
.status-dot.saved   { background: #4caf7d; }
.status-dot.error,
.status-dot.offline { background: var(--red); }

.header.admin h1 { padding: 0 96px; }   /* справа две кнопки — держим заголовок по центру */
@media (max-width: 400px) {
  .header.admin h1 { font-size: 19px; }
}

.header-actions {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  gap: 8px;
}

.add-user-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: background 0.15s;
}
.add-user-btn:hover { background: var(--accent-soft); }
.add-user-btn:active { transform: scale(0.95); }
.add-user-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(91, 142, 245, 0.35);
}
.avatar-btn:active { transform: scale(0.95); }

/* ── Menu ── */
.menu {
  position: absolute;
  right: 0;
  top: 48px;
  z-index: 50;
  min-width: 240px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  padding: 6px;
  text-align: left;
}
.menu-head { padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.menu-head .muted { font-size: 12px; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover { background: var(--field); }
.menu-item.danger { color: var(--red); }
.menu-note { padding: 8px 12px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* ── Banners ── */
.banners { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.banners:not(:empty) { margin-bottom: 18px; }
.banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  font-size: 14px;
  line-height: 1.4;
}
.banner .banner-text { flex: 1 1 220px; }
.banner.remind { background: var(--orange-soft); }
.banner.warn { background: #fff8e6; }
.banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
.banner button {
  border: none;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.banner button.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.banner.remind button { background: var(--orange); }
.banner.remind button.ghost { background: transparent; color: var(--muted); }

/* ── Grid ── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  max-width: 860px;
  margin: 0 auto 20px;
  align-items: start;
}
@media (max-width: 640px) {
  .main-grid { grid-template-columns: 1fr; }
}

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.06);
  min-width: 0;
}
.card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.card-icon { font-size: 18px; }
.card-title { font-size: 16px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-count {
  margin-left: auto;
  background: var(--bg);
  color: var(--muted);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.section-title {
  max-width: 860px;
  margin: 8px auto 12px;
  font-size: 15px;
  font-weight: 700;
  color: #5a6a7d;
  padding-left: 4px;
}

/* ── Input area ── */
.input-row { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-end; }
.input-row input[type="text"],
.input-row textarea,
.edit-area {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--field);
  transition: border-color 0.15s, background 0.15s;
  outline: none;
  resize: none;
}
.input-row input[type="text"]:focus,
.input-row textarea:focus,
.edit-area:focus { border-color: var(--accent); background: #fff; }
.input-row textarea { min-height: 62px; max-height: 140px; line-height: 1.45; }
.hint-text { font-size: 11px; color: #b0bac5; margin-top: 3px; padding-left: 2px; }
.input-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.btn-add {
  width: 42px;
  height: 42px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.btn-add:hover  { background: var(--accent-dark); }
.btn-add:active { transform: scale(0.93); }

/* ── Items ── */
.items-list { display: flex; flex-direction: column; gap: 7px; }
.empty-state { text-align: center; color: #c0cad5; font-size: 13px; padding: 14px 0; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--field);
  border-radius: 12px;
  padding: 9px 8px 9px 12px;
  transition: background 0.15s, box-shadow 0.3s;
}
.item:hover { background: #eff1f6; }
.item.ro { padding-right: 12px; }
.item.flash { box-shadow: 0 0 0 2px var(--accent); }
.item.task.overdue { background: var(--red-soft); }
.item-body { flex: 1; min-width: 0; padding-top: 1px; }
.item-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
}
.item.ro .item-text { cursor: default; flex: 1; }
.edit-area { display: block; width: 100%; font-size: 15px; padding: 6px 8px; line-height: 1.45; }

/* Чипы: срок, напоминание, от кого / кому */
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: none;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  background: #e6ebf3;
  color: #5a6a7d;
  cursor: pointer;
  white-space: nowrap;
}
span.chip { cursor: default; }
.chip.due.today   { background: var(--orange-soft); color: var(--orange); }
.chip.due.overdue { background: #ffd9d9; color: #c93a3a; }
.chip.due.soon    { background: var(--accent-soft); color: var(--accent); }
.chip.remind      { background: #f1ecff; color: #7a5bd6; }
.chip.who         { background: #e8f4ec; color: #3f8f5f; font-weight: 500; }

/* Кнопки 🔔 и 👤 в строке задачи */
.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: 9px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.38;
  filter: grayscale(1);
  transition: opacity 0.15s, background 0.15s, filter 0.15s;
}
.icon-btn:hover { opacity: 0.9; background: #e3e8f0; filter: none; }
.icon-btn.on { opacity: 1; filter: none; }

/* ── Checkbox (tasks) ── */
.task-check {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border: 2px solid #c8d0da;
  border-radius: 7px;
  cursor: pointer;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  margin-top: 1px;
  margin-right: 2px;
  padding: 0;
}
.task-check:hover { border-color: var(--accent); background: var(--accent-soft); }
.task-check.done  { background: var(--accent); border-color: var(--accent); }
.task-check.done::after { content: '✓'; color: #fff; font-size: 12px; font-weight: 800; }

/* ── Archive button (memories) ── */
.btn-to-archive {
  background: none;
  border: none;
  color: #c8d0da;
  cursor: pointer;
  font-size: 16px;
  padding: 3px 7px;
  border-radius: 7px;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.btn-to-archive:hover { color: #f5a623; background: #fef6e7; }

/* ── Блоки пользователей ── */
.team { max-width: 860px; margin: 0 auto; }
.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.card-foot { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.foot-toggle {
  border: none;
  background: var(--field);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #5a6a7d;
  cursor: pointer;
}
.foot-toggle.open { background: var(--accent-soft); color: var(--accent); }
.foot-body { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }

.done-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #6b7a8c;
  padding: 6px 8px 6px 10px;
  background: var(--field);
  border-radius: 10px;
}
.done-row .done-text { flex: 1; min-width: 0; text-decoration: line-through; white-space: pre-wrap; word-break: break-word; }
.done-row .done-date { font-size: 11px; color: var(--faint); white-space: nowrap; padding-top: 2px; }

/* ── Archive section ── */
.archive-wrap { max-width: 860px; margin: 0 auto; }
.archive-toggle {
  width: 100%;
  border: none;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 13px 18px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  transition: background 0.15s;
}
.archive-toggle:hover { background: var(--field); }
.archive-toggle-title { font-size: 15px; font-weight: 600; color: #5a6a7d; }
.archive-badge { background: var(--bg); color: var(--muted); border-radius: 20px; padding: 2px 9px; font-size: 12px; font-weight: 600; }
.archive-arrow { margin-left: auto; color: var(--faint); font-size: 13px; transition: transform 0.2s; }
.archive-arrow.open { transform: rotate(180deg); }

.archive-body { display: none; margin-top: 10px; }
.archive-body.open { display: block; }
.archive-list { display: flex; flex-direction: column; gap: 8px; }

.arc-item {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 7px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.arc-item-body { flex: 1; min-width: 0; }
.arc-item-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 5px; }
.arc-type { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 8px; letter-spacing: 0.2px; }
.arc-type.task { background: var(--accent-soft); color: var(--accent); }
.arc-type.mem  { background: #fef6e7; color: #f5a623; }
.arc-date { font-size: 11px; color: var(--faint); }
.arc-text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.arc-actions { display: flex; gap: 6px; flex-shrink: 0; }
.arc-more { text-align: center; padding: 6px 0 2px; }

.btn-restore, .btn-del {
  border: none;
  border-radius: 9px;
  padding: 6px 9px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s;
  line-height: 1;
}
.btn-restore { background: var(--accent-soft); color: var(--accent); }
.btn-restore:hover { background: #d6e4ff; }
.btn-del { background: var(--red-soft); color: var(--red); }
.btn-del:hover { background: #ffd6d6; }

.btn-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
}

/* ── Buttons ── */
.btn-primary, .btn-ghost, .btn-danger {
  border: none;
  border-radius: 11px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: var(--field); color: #5a6a7d; }
.btn-ghost:hover { background: #e9edf3; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.wide { width: 100%; padding: 12px; font-size: 15px; }

/* ── Login ── */
.login { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 72px); }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 20px;
  padding: 28px 24px 22px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-logo { text-align: center; }
.login-logo img { border-radius: 16px; }
.login-card h1 { text-align: center; font-size: 21px; margin-bottom: 6px; }
.login-note { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.45; }
.login-note:empty { display: none; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: #5a6a7d; }
.field input, .field select {
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 400;
  color: var(--text);
  background: var(--field);
  outline: none;
  width: 100%;
  min-width: 0;
}
.field input:focus { border-color: var(--accent); background: #fff; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form-error { color: var(--red); font-size: 13px; min-height: 0; line-height: 1.4; }
.form-error:empty { display: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(28, 38, 53, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px;
  padding: 18px 18px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (max-width: 520px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 20px 20px 0 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); max-height: 92vh; }
}
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-x { border: none; background: var(--field); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px; color: var(--muted); }
.modal-sub {
  font-size: 13px;
  color: #5a6a7d;
  background: var(--field);
  border-radius: 10px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 84px;
  overflow: hidden;
}
.field-label { font-size: 12px; font-weight: 700; color: #5a6a7d; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input[type="date"], .row input[type="time"], .row input[type="datetime-local"] {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: 9px 10px;
  font-size: 15px;
  font-family: inherit;
  background: var(--field);
  color: var(--text);
  outline: none;
}
.row input[type="time"] { flex: 0 0 112px; }
.row input:focus { border-color: var(--accent); background: #fff; }
.row .btn-ghost { padding: 9px 12px; flex-shrink: 0; }

.qchips { display: flex; flex-wrap: wrap; gap: 6px; }
.qchip {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 13px;
  cursor: pointer;
}
.qchip:hover { border-color: var(--accent); color: var(--accent); }

.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--field); border-radius: 12px; padding: 4px; }
.seg button {
  flex: 1 1 auto;
  border: none;
  background: none;
  border-radius: 9px;
  padding: 7px 8px;
  font-size: 13px;
  cursor: pointer;
  color: #5a6a7d;
}
.seg button.on { background: #fff; color: var(--accent); font-weight: 700; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }
.when-preview { font-size: 13px; color: #5a6a7d; min-height: 18px; }
.when-preview.err { color: var(--red); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }

/* Выбор исполнителя / список пользователей */
.user-pick { display: flex; flex-direction: column; gap: 4px; }
.pick {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: none;
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
}
.pick:hover { background: var(--field); }
.pick.cur { background: var(--accent-soft); }
.pick-name { flex: 1; }
.pick-check { color: var(--accent); font-weight: 800; }

.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--field); }
.user-row .pick-name { font-size: 14px; }
.user-row .role { font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.user-row .small-btn {
  border: none;
  background: var(--field);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
}
.user-row .small-btn:hover { background: #e3e8f0; }
/* Данные для входа нового пользователя */
.creds {
  background: #f1fbf4;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
}
.creds span { color: #6b8a76; }
.creds b { word-break: break-all; user-select: all; }
.creds .creds-pass { font-size: 17px; letter-spacing: 0.3px; }
.creds-title { font-size: 13px; color: #5a6a7d; }
.creds-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.creds-actions button { flex: 1 1 140px; }
.add-user { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Поле пароля с генератором */
.pw-row { display: flex; gap: 8px; }
.pw-row input { flex: 1; font-size: 17px !important; letter-spacing: 0.3px; }
.pw-row .btn-ghost { padding: 0 14px; font-size: 18px; flex-shrink: 0; }
.qchip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.pw-hint { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ── Toasts ── */
.toasts {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #263345;
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.18s ease-out;
}
.toast button { border: none; background: none; color: #9fc0ff; font-weight: 700; font-size: 14px; cursor: pointer; padding: 2px 4px; }
/* окно на телефоне — нижняя шторка: подсказки показываем сверху, чтобы не закрывали кнопки */
body.modal-open .toasts { top: max(16px, env(safe-area-inset-top)); bottom: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(238, 240, 245, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #5a6a7d;
  z-index: 100;
}
.loading-overlay.hidden { display: none; }
