/* НГТУ Inbox. Палитра — фирменные цвета НГТУ НЭТИ:
   тёмный и светлый зелёный (#0f8958, #00cc73), тёмный и светлый красный (#c0013f, #f20f38).
   Шрифт — системный: на iPhone и Mac это San Francisco. */

:root {
  --primary: #0f8959;
  --primary-ink: #ffffff;
  --green: #0f8958;
  --green-light: #00cc73;
  --red: #c0013f;
  --red-light: #f20f38;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --ink: #11181f;
  --muted: #5e6873;
  --faint: #8d969f;
  --line: #e5e8eb;
  --hover: #eff1f3;
  --note-bg: #fdecef;
  --note-ink: #8a0730;
  --src-dispace_messages: #0f8958;
  --src-dispace_tests: #0f8958;
  --src-ciu_messages: #c0013f;
  --src-owa_mail: #4b5661;
  --radius: 12px;
  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter Display", "Inter", "Segoe UI Variable Display", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #12a36a;
    --primary-ink: #ffffff;
    --green: #2fcf8a;
    --green-light: #2fcf8a;
    --red: #ff4766;
    --red-light: #ff4766;
    --bg: #0e1114;
    --surface: #171b20;
    --ink: #e9edf1;
    --muted: #9aa4ae;
    --faint: #6f7a85;
    --line: #252b32;
    --hover: #1e242a;
    --note-bg: #3a1220;
    --note-ink: #ffb3c3;
    --src-dispace_messages: #2fcf8a;
    --src-dispace_tests: #2fcf8a;
    --src-ciu_messages: #ff5a78;
    --src-owa_mail: #a3b0bd;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--bg); }

body {
  color: var(--ink);
  background: var(--bg);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }

/* ---------- заставка ---------- */

.splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--surface);
  transition: opacity .3s ease, visibility .3s;
}
.splash.done { opacity: 0; visibility: hidden; }
.splash-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  margin: 0;
  text-align: center;
  font: 500 13px/1.3 var(--font);
  letter-spacing: .02em;
  color: var(--faint);
  animation: footer-in .5s .7s ease both;
}
@keyframes footer-in { from { opacity: 0; } to { opacity: 1; } }

/* Логотип «эмблема | inbox». На заставке слово выезжает из-за черты. */
.lockup { display: flex; align-items: center; gap: 14px; }
.lockup-mark { width: 64px; height: 64px; display: block; }
.lockup-bar { width: 2px; height: 44px; border-radius: 1px; background: var(--faint); opacity: .55; }
/* Контейнер слова начинается прямо у черты: из-за неё слово и выезжает. */
.lockup-word { overflow: hidden; margin-left: -14px; padding: 0 2px 6px 14px; margin-bottom: -6px; }
.lockup-word span {
  display: block;
  font: 600 40px/1.05 var(--font-display);
  letter-spacing: -.025em;
  color: var(--ink);
}
.lockup.small .lockup-mark { width: 44px; height: 44px; }
.lockup.small .lockup-bar { height: 30px; }
.lockup.small .lockup-word span { font-size: 28px; }

.splash .lockup-mark { animation: mark-in .5s cubic-bezier(.2, .8, .2, 1) both; }
.splash .lockup-bar { animation: bar-in .35s .3s cubic-bezier(.2, .8, .2, 1) both; }
.splash .lockup-word span { animation: word-out .7s .55s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes mark-in { from { opacity: 0; transform: scale(.82); } to { opacity: 1; transform: none; } }
@keyframes bar-in { from { transform: scaleY(0); } to { transform: none; } }
@keyframes word-out { from { transform: translateX(-110%); } to { transform: none; } }

/* ---------- верхняя панель ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 8px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.appbar h1 {
  flex: 1;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar.sub h1 { font-size: 17px; font-weight: 600; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:active { background: var(--hover); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.spinning svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- элементы форм ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 14px; background: var(--primary); color: var(--primary-ink); }
.btn-small.btn-ghost { background: transparent; color: var(--ink); }
.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; position: relative; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
input, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* меньше 16px iOS увеличивает страницу при фокусе */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
textarea { resize: vertical; min-height: 160px; line-height: 1.5; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.error { margin: 0; color: var(--red); font-size: 14px; white-space: pre-line; }
.note { background: var(--note-bg); color: var(--note-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0; }

/* ---------- сегменты ---------- */

.segments {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--hover);
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segments::-webkit-scrollbar { display: none; }
.segment {
  flex: 1 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.segment[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.segment .count { margin-left: 5px; color: var(--red); font-weight: 700; font-size: 12px; }

/* ---------- лента ---------- */

.toolbar { display: grid; gap: 10px; margin: 4px 0 8px; }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 11px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { padding-left: 36px; background: var(--surface); }

.banners { display: grid; gap: 8px; margin-top: 4px; }
.banners:empty { display: none; }
.offline { font-size: 13px; color: var(--muted); margin: 6px 0; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.list li + li .row { border-top: 1px solid var(--line); }

.row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 0 8px;
  width: 100%;
  padding: 12px 14px 12px 10px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row:active { background: var(--hover); }
.row .dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.row.unread .dot { background: var(--red); }
.row-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.row-from { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .row-from, .row.unread .row-title { font-weight: 650; }
.row-time { flex: none; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.row-title { margin: 1px 0 0; overflow-wrap: anywhere; }
.row-snippet {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--src, var(--primary));
}
.row .tag { margin-bottom: 2px; }

.empty { text-align: center; padding: 48px 16px; }
.empty-title { font-weight: 600; margin: 0 0 4px; }
.spinner-ring {
  width: 38px;
  height: 38px;
  margin: 0 auto 16px;
  border: 3.5px solid color-mix(in srgb, var(--primary) 20%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ring-spin 0.85s linear infinite;
}
@keyframes ring-spin {
  to { transform: rotate(360deg); }
}
.more { display: flex; margin: 14px auto 0; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 360px + 16px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 16px;
  background: var(--primary);
  color: var(--primary-ink);
  font: inherit;
  font-weight: 600;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--primary) 35%, transparent);
  cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }

/* ---------- тесты ---------- */

#test-segments { margin: 4px 0 12px; }
.group-title, .section-title { margin: 20px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tests { display: grid; gap: 10px; }
.test {
  display: block;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
.test-title { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
.test-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.pill { flex: none; white-space: nowrap; display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.pill-open { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.pill-urgent { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.pill-soon { background: var(--hover); color: var(--muted); }
.pill-missed { background: var(--hover); color: var(--red); }
.test-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.score { margin-top: 12px; }
.score-line { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.score-value { font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.score-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.bar { position: relative; height: 6px; margin-top: 8px; border-radius: 3px; background: var(--hover); overflow: visible; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--green); }
.bar-fill.low { background: var(--red); }
.bar-mark { position: absolute; top: -3px; width: 2px; height: 12px; border-radius: 1px; background: var(--ink); opacity: .45; }

/* ---------- сообщение ---------- */

.message { padding: 8px 2px 16px; }
.message-source { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; color: var(--muted); }
.message h2 { margin: 8px 0 6px; font-size: 21px; line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
.message-author { margin: 0; color: var(--muted); }
.message-extra { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.message-extra:empty { display: none; }
.message-body {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-body a { color: var(--primary); }
.actionbar { display: flex; gap: 10px; flex-wrap: wrap; padding-bottom: 8px; }
.actionbar .btn { flex: 1 1 0; white-space: nowrap; padding: 0 12px; }

/* ---------- написать ---------- */

.compose { padding-top: 4px; }
.grow textarea { min-height: 200px; }
.recipient { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.suggestions {
  list-style: none;
  margin: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  max-height: 280px;
  overflow-y: auto;
}
.suggestions button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.suggestions button:active, .suggestions button:hover { background: var(--hover); }
.suggestions .kind { color: var(--faint); font-size: 12px; flex: none; }
.suggestions .hint { padding: 10px; color: var(--muted); font-size: 14px; }

/* ---------- настройки ---------- */

.settings { list-style: none; margin: 8px 0 0; padding: 0; background: var(--surface); border-radius: var(--radius); }
.settings li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px; }
.settings li + li { border-top: 1px solid var(--line); }
.settings-title { margin: 0; font-weight: 500; }
.source-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.source-dot.bad { background: var(--red); }
.version { text-align: center; margin-top: 28px; }

/* ---------- привязка ---------- */

.pair { max-width: 400px; margin: 24px auto 0; text-align: center; }
.pair .lockup { justify-content: center; margin-bottom: 10px; }
.pair h2 { margin: 14px 0 8px; font-size: 22px; }
.pair .form { margin-top: 22px; text-align: left; }
.pair .note { text-align: left; margin-bottom: 10px; }
#pair-code { font-family: ui-monospace, Consolas, monospace; font-size: 22px; letter-spacing: .14em; text-align: center; text-transform: uppercase; }

/* ---------- нижняя навигация ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  position: relative;
  flex: 0 1 140px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  color: var(--faint);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--primary); }
.badge {
  position: absolute;
  top: 8px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  z-index: 40;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}

/* Над нижней панелью и кнопкой «Написать». */
body.with-tabbar .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px); }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { opacity: .8; }

.sync-bar {
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  background-size: 200% 100%;
  animation: sync-pulse 1.2s infinite linear;
}
@keyframes sync-pulse {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn.spinning svg { animation: none; }
  .splash { transition: none; }
  .splash .lockup-mark, .splash .lockup-bar, .splash .lockup-word span, .splash-footer { animation: none; }
  .sync-bar { animation: none; }
}
