:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #000000;
  --secondary: #8A8A8E;
  --separator: #C6C6C8;
  --accent: #007AFF;
  --danger: #FF3B30;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* Верхняя панель */

.topbar {
  display: flex;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  min-height: 44px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.topbar-spacer { flex: 1; }

.back-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 17px;
  padding: 8px 8px 8px 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--card);
  border-radius: 17px;
  padding: 5px 12px 5px 5px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.user-chip .avatar {
  width: 24px;
  height: 24px;
  font-size: 13px;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
}

/* Экран списков */

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 90px);
}

.big-title {
  font-size: 32px;
  font-weight: 700;
  margin: 8px 0 16px;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  background: var(--card);
  border: none;
  border-radius: 14px;
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.tile:active { opacity: 0.7; }

.tile-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.tile-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-weight: 600;
}

.tile-count {
  font-size: 24px;
  font-weight: 700;
}

.tile-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

/* Экран списка */

.list-title {
  font-size: 32px;
  font-weight: 700;
  margin: 4px 0 16px;
}

.items-card {
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
}

.item + .item { border-top: 0.5px solid var(--separator); }

.item .check {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--separator);
  background: none;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

.item.done .check {
  border-color: var(--list-color, var(--accent));
  background: var(--list-color, var(--accent));
}

.item .label {
  flex: 1;
  font-size: 17px;
  word-break: break-word;
}

.item.done .label {
  color: var(--secondary);
  text-decoration: line-through;
}

.assign-btn {
  border: none;
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  border-radius: 14px;
  padding: 5px 10px;
  flex-shrink: 0;
}

.assign-btn:active { opacity: 0.6; }

.assignee-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  border-radius: 14px;
  padding: 4px 10px 4px 4px;
  font-size: 14px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  flex-shrink: 0;
}

.assignee-chip .avatar {
  width: 22px;
  height: 22px;
  font-size: 12px;
}

.assignee-chip.mine { cursor: pointer; }
.assignee-chip.mine:active { opacity: 0.6; }

.item .delete {
  border: none;
  background: none;
  color: var(--separator);
  font-size: 16px;
  padding: 4px;
  flex-shrink: 0;
}

.item .delete:active { color: var(--danger); }

.done-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--secondary);
  font-size: 15px;
  margin: 22px 4px 8px;
}

.clear-done {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 15px;
  padding: 0;
}

.empty-hint {
  text-align: center;
  color: var(--secondary);
  margin-top: 48px;
  font-size: 16px;
}

/* Поле добавления */

.add-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: var(--bg);
}

.add-form {
  max-width: 608px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  background: var(--card);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.add-form input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 17px;
  padding: 8px;
  background: none;
  min-width: 0;
}

.add-form button {
  border: none;
  border-radius: 10px;
  background: var(--list-color, var(--accent));
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 8px 16px;
}

.add-form button:disabled {
  background: var(--separator);
}

/* Экран входа */

.login-card {
  max-width: 340px;
  margin: 64px auto 0;
  background: var(--card);
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 20px;
  text-align: center;
}

.login-card input {
  display: block;
  width: 100%;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  margin-bottom: 10px;
  outline: none;
}

.login-card input:focus { box-shadow: 0 0 0 2px var(--accent) inset; }

.login-card button[type="submit"] {
  width: 100%;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 12px;
  margin-top: 4px;
}

.login-error {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  margin: 12px 0 0;
}

/* Меню пользователя */

.menu {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 52px);
  right: 16px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  min-width: 200px;
  overflow: hidden;
  z-index: 100;
}

.menu-header {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--secondary);
  border-bottom: 0.5px solid var(--separator);
}

.menu-item {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 12px 16px;
  font-size: 16px;
}

.menu-item:active { background: var(--bg); }

/* Экран пользователей */

.user-row .avatar {
  width: 32px;
  height: 32px;
  font-size: 16px;
}

.login-hint {
  color: var(--secondary);
  font-size: 14px;
}

.role-badge {
  font-size: 13px;
  color: var(--secondary);
  background: var(--bg);
  border-radius: 10px;
  padding: 3px 8px;
}

.add-user-form {
  margin-top: 20px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-user-form .form-title {
  font-weight: 600;
  font-size: 16px;
}

.add-user-form input {
  border: none;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  outline: none;
}

.add-user-form button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  padding: 10px;
}

/* Баннер офлайн */

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #FFCC00;
  color: #000;
  text-align: center;
  font-size: 13px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 12px 6px;
  z-index: 200;
}
