:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --card2: #f1f1ef;
  --border: #e9e9e7;
  --border2: #d3d3cf;
  --text: #37352f;
  --muted: #787774;
  --acc: #2383e2;
  --green: #0f7b6c;
  --red: #d44c47;
  --amber: #9f6b00;
  --gray: #9b9a97;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919;
    --card: #1f1f1f;
    --card2: #262626;
    --border: #2f2f2f;
    --border2: #3f3f3f;
    --text: #e6e4e1;
    --muted: #9b9a97;
    --acc: #529cca;
    --green: #3d9f8e;
    --red: #e0645a;
    --amber: #c9a05c;
    --gray: #6b6b68;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: 70px;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
#topDate { color: var(--muted); font-size: 13px; }

#content { padding: 10px 16px 28px; flex: 1; }

#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 11px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
}

.tab svg { width: 21px; height: 21px; fill: currentColor; }
.tab.active { color: var(--text); }

/* --- Карточки --- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 14px 15px;
  margin-bottom: 10px;
  transition: border-color .15s;
}

h2.section {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin: 20px 2px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h2.section span { color: var(--acc); font-weight: 600; }

.qtitle { font-size: 15px; font-weight: 600; margin-bottom: 4px; word-break: break-word; }

.qmeta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 3px 14px; margin-bottom: 6px; }

.qmeta b { color: var(--text); font-weight: 600; }

.qxp { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.qxp .good { color: var(--green); font-weight: 600; }
.qxp .bad2 { color: var(--red); }

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 5px;
  margin-bottom: 7px;
}
.badge.done { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.badge.declined { background: var(--card2); color: var(--muted); }
.badge.overdue { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.badge.paused { background: color-mix(in srgb, var(--amber) 12%, transparent); color: var(--amber); }

.paused-card { opacity: .55; }

.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  background: var(--card);
  transition: background .15s, border-color .15s;
}
.btn:active { transform: scale(.98); }

.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.accent { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--border2); }
.btn.ghost:hover { background: var(--card2); }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 26px 10px;
  border: 1px dashed var(--border2);
  border-radius: 9px;
}

/* --- Редактор --- */

.subtabs { display: flex; gap: 8px; margin: 4px 0 14px; background: var(--card2); border-radius: 7px; padding: 3px; }

.subtab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.subtab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.row-editor {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 0 2px;
  font-size: 13.5px;
}
.row-editor .mini { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

.iconbtn {
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  flex: none;
}
.iconbtn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }

.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--border2);
  border-radius: 20px;
  transition: .2s;
  cursor: pointer;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .slider { background: var(--acc); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11.5px;
  color: var(--muted);
}

/* --- Модалка --- */

#modalRoot {
  position: fixed;
  inset: 0;
  background: rgba(55, 53, 47, .3);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
#modalRoot.open { display: flex; }

.modal {
  background: var(--bg);
  border-radius: 12px 12px 0 0;
  border: 1px solid var(--border2);
  border-bottom: none;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 16px 30px;
  animation: slideUp .2s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h3 { font-size: 15.5px; margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }

.field input, .field textarea, .field select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 9px 11px;
  font-size: 14.5px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--acc); }

.row2 { display: flex; gap: 10px; }
.row2 .field { flex: 1; }

.remrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.remrow input { flex: 1; }

.modal .btnrow { margin-top: 16px; }

/* --- Профиль --- */

.profile-top { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--card2);
  border: 1px solid var(--border2);
  flex: none;
}

.placeholder-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--acc);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 600;
  flex: none;
}

.pname { font-size: 18px; font-weight: 700; }
.pabout { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.achange { font-size: 12.5px; color: var(--acc); cursor: pointer; margin-top: 4px; display: inline-block; }

.xpbar { height: 6px; background: var(--card2); border-radius: 4px; overflow: hidden; margin: 8px 0 3px; }
.xpbar div { height: 100%; background: var(--acc); border-radius: 4px; transition: width .3s; }
.xplabel { font-size: 12px; color: var(--muted); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-top: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
}
.stat .v { font-size: 19px; font-weight: 700; color: var(--text); }
.stat .k { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* --- Тост --- */

#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 13.5px;
  opacity: 0;
  transition: .25s;
  pointer-events: none;
  z-index: 99;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { text-align: center; color: var(--muted); padding: 40px 0; }