:root {
  --bg: #f4f4f1;
  --card: #fff;
  --bg-input: #fcfcfb;
  --bg-elevated: #f8f8f5;
  --bg-gray: #eef0ee;
  --bg-warn-soft: #faf7f4;

  --ink: #1c1e1d;
  --muted: #6f7573;
  --line: #e4e5e0;
  --checkbox-border: #a8aea8;

  --accent: #2c5f4f;
  --accent-on: #ffffff;
  --accent-soft: #e6efeb;

  --warn: #a8503a;
  --warn-soft: #f7e8e2;
  --warn-line: #d9b4a8;
  --warn-divider: #efe5e0;

  --success: #198754;
}

[data-theme="dark"] {
  --bg: #141716;
  --card: #1d2120;
  --bg-input: #191c1b;
  --bg-elevated: #232827;
  --bg-gray: #262b29;
  --bg-warn-soft: #2a221e;

  --ink: #e6e9e7;
  --muted: #8e9592;
  --line: #2d3330;
  --checkbox-border: #5a605d;

  --accent: #6cbf97;
  --accent-on: #0f1a14;
  --accent-soft: #22322b;

  --warn: #e28a6e;
  --warn-soft: #3a2a24;
  --warn-line: #5c4034;
  --warn-divider: #3a2a24;

  --success: #22914f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background-color .2s;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { -webkit-appearance: none; appearance: none; }

/* Убираем зум на iOS при фокусе на поле */
input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  font-size: 16px !important; 
}

/* ---------- Авторизация ---------- */
.auth { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { position: relative; width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px 22px; }
.theme-toggle {
  position: absolute; top: 14px; right: 14px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg-elevated);
  color: var(--muted); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.auth-brand { font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.auth-sub { color: var(--muted); font-size: 13px; margin-top: 2px; margin-bottom: 20px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-gray); border-radius: 9px; padding: 3px; margin-bottom: 18px; }
.auth-tabs button { background: none; border: 0; padding: 9px; font-size: 14px; color: var(--muted); border-radius: 6px; cursor: pointer; }
.auth-tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.auth-card label { display: block; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.auth-card input { display: block; width: 100%; margin-top: 5px; padding: 12px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg-input); font-size: 16px; }
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { display: inline-block; width: 100%; padding: 13px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-on); font-weight: 500; font-size: 15px; cursor: pointer; margin-top: 6px; }
.btn:active { opacity: .9; }
.err { color: var(--warn); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ---------- Шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; display: flex; flex-direction: column; line-height: 1.15; flex: none; }
.brand span { font-weight: 400; font-size: 11.5px; color: var(--muted); letter-spacing: 0; }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; }
.me-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; color: var(--ink); font-weight: 500; }
.role { font-size: 10.5px; padding: 2px 7px; border-radius: 20px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; flex: none; }
.role-participant { background: var(--bg-gray); color: var(--muted); }
.role-editor { background: var(--accent-soft); color: var(--accent); }
.role-admin { background: var(--ink); color: var(--bg); }
.icon-btn {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--bg-elevated); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; cursor: pointer; text-decoration: underline; flex: none; }

/* ---------- Основной контент ---------- */
main { max-width: 640px; margin: 0 auto; padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; color: var(--muted); }

.big { font-size: 34px; font-weight: 700; letter-spacing: -.8px; line-height: 1.05; }
.big span { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.bar { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }

/* ---------- Навигация ---------- */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom button {
  background: none; border: 0; padding: 12px 2px;
  font-size: 11px; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.bottom button.active { color: var(--accent); font-weight: 600; }
.bottom button.active::before { content: ''; display: block; width: 16px; height: 2px; background: var(--accent); border-radius: 2px; margin-bottom: 1px; }

/* ---------- Задачи ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 8px 14px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }

.subject { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 18px 0 6px; font-weight: 600; padding-left: 2px; }

.task { display: flex; gap: 12px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.task:last-child { border-bottom: 0; }
.task:active { background: var(--bg-elevated); }
.task input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px; margin: 1px 0 0; flex: none;
  border: 1.5px solid var(--checkbox-border); border-radius: 6px; background: var(--card);
  position: relative; cursor: pointer;
}
.task input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.task input[type=checkbox]:checked::after {
  content: ''; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px;
  border: solid var(--accent-on); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 500; font-size: 15px; line-height: 1.35; }
.task.done .task-title { color: var(--muted); font-weight: 400; }
.task.done { background: var(--bg-gray); border-radius: 8px; padding-left: 8px; padding-right: 8px; margin-left: -8px; margin-right: -8px; }
.task-meta { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.task-flags { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex: none; margin-top: 1px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--bg-gray); color: var(--muted); white-space: nowrap; font-weight: 500; }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }

/* ---------- Дедлайн ---------- */
.deadline-card { background: linear-gradient(135deg, var(--card), var(--bg-elevated)); margin-bottom: 10px; }
.deadline-card.overdue { border-color: var(--warn-line); background: linear-gradient(135deg, var(--card), var(--warn-soft)); }
.dl-task { font-weight: 600; font-size: 15px; line-height: 1.35; margin-bottom: 2px; }
.dl-subj { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.dl-footer { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12.5px; }
.dl-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-remain { font-weight: 600; text-align: right; }
.dl-empty { font-size: 14px; color: var(--accent); padding: 6px 0; font-weight: 500; }

/* ---------- Редактор / Формы ---------- */
.field { margin-bottom: 9px; }
.field label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-input); font-size: 15px;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.btn-sm { padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 13.5px; cursor: pointer; }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.btn-sm.danger { color: var(--warn); border-color: var(--warn-line); }
.btn-sm.armed { background: var(--warn-soft) !important; color: var(--warn) !important; border-color: var(--warn) !important; font-weight: 600; }

/* Список пользователей (Админка) */
.users-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.users-row:last-child { border-bottom: 0; }
.users-row .u-name { flex: 1; min-width: 0; font-weight: 500; }
.users-row .u-login { font-size: 12px; color: var(--muted); font-weight: 400; }
.users-row select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); font-size: 13px; }

/* ---------- Недельные группировки ---------- */
.week-group { margin-bottom: 18px; }
.week-header { display: flex; align-items: center; gap: 10px; margin: 0 4px 8px; }
.week-info { flex: 1; min-width: 0; }
.week-dates { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; line-height: 1.3; }
.week-dates .current-badge { font-size: 10.5px; padding: 2px 7px; border-radius: 20px; background: var(--accent); color: var(--accent-on); letter-spacing: .03em; font-weight: 600; text-transform: uppercase; }
.week-hours { font-size: 12px; color: var(--muted); margin-top: 1px; }
.week-tasks { padding: 4px 16px; margin-bottom: 0; }
.week-group-card { padding: 14px 14px 6px; }
.week-group-card .week-header { margin: 0 0 10px; }
.ov-week-tasks { display: flex; flex-direction: column; }
.ov-week-tasks .task { padding: 11px 0; }
.ov-week-tasks .task-wrap { border-bottom: 1px solid var(--line); }
.ov-week-tasks .task-wrap:last-child { border-bottom: 0; }
.ov-week-tasks .task-wrap > .task { border-bottom: 0; }
.ov-week-tasks .task-wrap > .task-upload { padding: 6px 0 12px 34px; }

/* Кнопка подтверждения (галочка) */
.task-wrap { display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
.task-wrap:last-child { border-bottom: 0; }
.task-wrap > .task { border-bottom: 0; padding-bottom: 4px; }
.task-wrap > .task-upload { padding: 6px 0 14px 34px; }
.confirm-btn {
  display: block; width: 100%;
  padding: 11px 16px; border: 0; border-radius: 8px;
  background: var(--success); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.confirm-btn:active { opacity: .85; }
.confirm-btn:disabled { opacity: .6; cursor: default; }

/* Кнопки в карточке задачи */
.file-del { flex: none; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; }
.file-del:hover { border-color: var(--warn); color: var(--warn); }
.file-del[data-act="del-task"], .file-del[data-act="del-task-plan"] { margin-top: 4px; width: 22px; height: 22px; font-size: 14px; border-radius: 6px; background: var(--card); }

/* ---------- Модальные окна ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 1000; }
.modal-card { background: var(--card); border-radius: 12px; padding: 24px; width: 100%; max-width: 400px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.modal-card h2 { margin-top: 0; margin-bottom: 16px; font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.modal-card .field { margin-bottom: 12px; }
.modal-card .actions { margin-top: 20px; display: flex; gap: 10px; }
.modal-card .actions button { flex: 1; justify-content: center; padding: 12px; font-size: 15px; }