/* ==========================================================================
   Журнал 56 ЗР — стили Mini App
   Цвета берём из темы Telegram, с запасными значениями на тёмную схему.
   ========================================================================== */

:root {
  --bg:        var(--tg-theme-bg-color, #17212b);
  --bg2:       var(--tg-theme-secondary-bg-color, #232e3c);
  --text:      var(--tg-theme-text-color, #f5f5f5);
  --hint:      var(--tg-theme-hint-color, #7d8b99);
  --link:      var(--tg-theme-link-color, #6ab3f3);
  --accent:    var(--tg-theme-button-color, #5288c1);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --line:      rgba(125, 139, 153, .22);
  --radius:    14px;
  --tabbar-h:  58px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------------ загрузка */

.boot, .fatal {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  text-align: center;
  gap: 14px;
}
.boot-spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-text { color: var(--hint); }
.fatal-emoji { font-size: 44px; }
.fatal h2 { margin: 0; font-size: 19px; }
.fatal p { margin: 0; color: var(--hint); max-width: 340px; }
.fatal-extra {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--bg2);
  padding: 10px 14px;
  border-radius: 10px;
  user-select: all;
}

/* ---------------------------------------------------------------- каркас */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 17px; }
.topbar-btn {
  background: none; border: none; color: var(--hint);
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.topbar-btn:active { background: var(--bg2); }

.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  -webkit-overflow-scrolling: touch;
}

.tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: var(--safe-b);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
}
.tab {
  flex: 1;
  background: none; border: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 2px 6px;
  font-size: 10.5px;
  cursor: pointer;
  font-family: inherit;
}
.tab-ico { font-size: 17px; line-height: 1; }
.tab.active { color: var(--accent); }

/* --------------------------------------------------------------- элементы */

.section-title {
  padding: 16px 14px 8px;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--hint);
  font-weight: 600;
}

.card {
  background: var(--bg2);
  border-radius: var(--radius);
  margin: 8px 12px;
  overflow: hidden;
}

.empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--hint);
}
.empty-emoji { font-size: 36px; display: block; margin-bottom: 10px; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  background: var(--line);
  color: var(--hint);
  vertical-align: middle;
}

/* ---------------------------------------------------------------- матрица */

.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.matrix {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 100%;
}

.matrix th, .matrix td {
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.matrix thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--hint);
  padding: 8px 4px;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.matrix thead th.col-subject {
  text-align: left;
  padding-left: 12px;
  z-index: 7;
}
.matrix thead th.me { color: var(--accent); }

.col-subject {
  position: sticky; left: 0; z-index: 4;
  background: var(--bg);
  text-align: left;
  padding: 9px 8px 9px 12px !important;
  min-width: 168px;
  max-width: 168px;
  font-size: 13.5px;
  line-height: 1.25;
}
.matrix tbody tr:nth-child(even) .col-subject { background: var(--bg); }

.subj-title { display: block; }
.subj-meta { display: block; font-size: 11px; color: var(--hint); margin-top: 2px; }

.col-person { width: 52px; text-align: center; }
.matrix thead th.nodata { opacity: .55; }
.th-nodata {
  display: block;
  font-size: 8.5px;
  font-weight: 400;
  line-height: 1.1;
  margin-top: 1px;
  letter-spacing: -.02em;
}

.cell {
  width: 100%;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 17px;
  padding: 9px 0;
  cursor: pointer;
  display: block;
  transition: transform .06s ease;
}
.cell:active { transform: scale(.86); }
.cell.readonly { cursor: default; }

.sem-row td {
  background: var(--bg2);
  padding: 6px 12px !important;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  position: sticky; left: 0;
}
.sem-row .sem-toggle { cursor: pointer; user-select: none; }
.sem-row .sem-count { float: right; font-weight: 400; }

/* ------------------------------------------------------------------ списки */

.list-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: rgba(125,139,153,.08); }

.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 14.5px; }
.list-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }
.list-mark { font-size: 17px; width: 22px; text-align: center; flex: none; }
.list-chev { color: var(--hint); font-size: 15px; flex: none; }

/* ------------------------------------------------------------------- формы */

.form { padding: 12px 14px 18px; }
.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--hint);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}

.btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-top: 6px;
}
.btn:active { opacity: .82; }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.danger { background: #b23b3b; color: #fff; }
.btn:disabled { opacity: .5; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 13px; }
.chip {
  padding: 6px 13px;
  border-radius: 20px;
  background: var(--bg2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-fg); border-color: transparent; }

/* --------------------------------------------------------------- статусы */

.status-list { padding: 6px 0 12px; }
.status-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  cursor: pointer;
  font-size: 15.5px;
}
.status-opt:active { background: rgba(125,139,153,.1); }
.status-opt.current { font-weight: 600; }
.status-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff; flex: none;
}

/* --------------------------------------------------------------- сводка */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 10px 12px; }
.stat {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 13px 14px;
}
.stat-value { font-size: 25px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--hint); margin-top: 3px; }

.bar-row { padding: 9px 14px; }
.bar-head { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 5px; }
.bar { height: 7px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--accent); }

/* ------------------------------------------------------------------ sheet */

.sheet { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: calc(12px + var(--safe-b));
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(22px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px;
  padding: 16px 18px 8px;
}
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-sub { font-size: 13px; color: var(--hint); margin-top: 3px; }
.sheet-close {
  background: none; border: none; color: var(--hint);
  font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  transform: translateX(-50%);
  background: rgba(20,20,20,.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 200;
  max-width: 88vw;
  text-align: center;
  animation: sheet-up .16s ease-out;
}

/* ---------------------------------------------------------------- контакты */

.contact-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.contact-row:last-child { border-bottom: none; }
.contact-ico { width: 22px; text-align: center; color: var(--hint); flex: none; }
.contact-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-val a { color: var(--link); text-decoration: none; }
.contact-act {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  color: var(--accent); font-size: 12.5px; padding: 4px 9px;
  cursor: pointer; font-family: inherit; flex: none;
}

.note { padding: 10px 16px 16px; color: var(--hint); font-size: 12.5px; line-height: 1.5; }
