/* RAT v3 — стили панели и регистрации. До v3 собирались из backend/Shared.html + Admin_Styles.html; теперь правятся здесь. */

  :root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1a2233;
    --muted: #6b7487;
    /* Бренд RAT: violet ring (#5A5BFF → #3F3CFF), green check отдельно в --ok */
    --accent: #5A5BFF;
    --accent-hover: #3F3CFF;
    --danger: #d5344f;
    --ok: #0AA36E;
    --border: #e3e7f0;
    --radius: 14px;
    --shadow: 0 6px 24px rgba(26, 34, 51, 0.08);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
  }
  .card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    width: 100%;
    max-width: 420px;
  }
  .card.wide { max-width: 720px; }
  h1 { font-size: 22px; margin-bottom: 4px; }
  .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
  label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
  input, select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color .15s;
  }
  input:focus, select:focus { border-color: var(--accent); }
  button {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
  }
  button:hover { background: var(--accent-hover); }
  button:disabled { opacity: .55; cursor: default; }
  button.secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
    margin-top: 10px;
  }
  button.secondary:hover { background: #f0f3fb; }
  .msg { margin-top: 14px; font-size: 14px; display: none; }
  .msg.error { color: var(--danger); display: block; }
  .msg.ok { color: var(--ok); display: block; }
  .hidden { display: none !important; }
  .badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e9eefc;
    color: var(--accent);
  }
  .badge.pro { background: #e5f7ec; color: var(--ok); }
  .list-item {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -3px;
    margin-right: 8px;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .footer-note { margin-top: 24px; text-align: center; font-size: 12px; color: var(--muted); }

  /* Бренд (как в панели преподавателя v1) */
  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
  }
  .brand-logo {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: block;
  }
  .brand-text { min-width: 0; }
  .brand-name {
    font-size: 1.25em;
    font-weight: 700;
    line-height: 1.15;
    color: var(--text);
  }
  .brand-slogan {
    font-size: 0.72em;
    color: var(--muted);
    margin-top: 2px;
    font-weight: 500;
  }
  .brand.compact .brand-logo { width: 36px; height: 36px; }
  .brand.compact .brand-name { font-size: 1.05em; }

  /* Горизонтальные формы: label сверху, control снизу, hints не сдвигают inputs */
  .form-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
  }
  .field-col {
    flex: 1;
    min-width: 140px;
    display: flex;
    flex-direction: column;
  }
  .field-col > label {
    margin: 0 0 6px;
  }
  .field-col-fixed {
    flex: 0 0 auto;
    min-width: 0;
  }
  .field-hint {
    min-height: 1.35em;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
    line-height: 1.35;
  }


    body { align-items: stretch; padding: 0; }
    .layout { width: 100%; max-width: 1100px; margin: 0 auto; padding: 16px 16px 60px; }

    /* Шапка + вкладки закреплены при прокрутке (только CSS, без API) */
    .sticky-chrome {
      position: sticky;
      top: 0;
      z-index: 40;
      margin: 0 -16px 16px;
      padding: 12px 16px 10px;
      background: rgba(244, 246, 251, 0.94);
      border-bottom: 1px solid rgba(26, 34, 51, 0.06);
    }

    .topbar {
      display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
      background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
      padding: 12px 16px; margin-bottom: 10px;
    }
    .topbar h1 { font-size: 17px; margin: 0; }
    .topbar .tb-name {
      font-size: 17px; margin: 0; text-align: right;
      font-weight: 700; max-width: min(420px, 55vw);
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .topbar .grow { flex: 1; min-width: 12px; }
    .topbar .sub { margin: 2px 0 0; }
    .topbar .brand { margin-bottom: 0; }

    .tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 0; }
    .tab-btn {
      width: auto; margin: 0; padding: 9px 18px; border-radius: 999px;
      background: var(--card); color: var(--text); border: 1px solid var(--border);
      font-size: 14px; font-weight: 600; box-shadow: none;
    }
    .tab-btn:hover { background: #eef1fb; }
    .tab-btn.active {
      background: linear-gradient(135deg, var(--accent), var(--accent-hover));
      color: #fff;
      border-color: transparent;
    }

    .panel {
      background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
      padding: 24px; margin-bottom: 16px;
    }
    .panel h2 {
      font-size: 17px;
      font-weight: 700;
      margin: 0 0 14px;
      padding-bottom: 10px;
      border-bottom: 2px solid var(--border);
      color: var(--text);
      letter-spacing: -0.01em;
    }
    .panel h2.panel-h2 {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 8px;
    }
    .panel-h2-main { flex: 0 1 auto; }
    .panel-h2-sub { display: inline; font-weight: 500; }
    .panel-tip-btn {
      width: 22px !important;
      min-width: 22px;
      height: 22px;
      margin: 0 !important;
      padding: 0 !important;
      border-radius: 50%;
      border: 1px solid var(--border);
      background: #eef1f8;
      color: var(--muted);
      font-size: 12px;
      font-weight: 700;
      line-height: 1;
      cursor: pointer;
      flex: 0 0 auto;
      box-shadow: none;
    }
    .panel-tip-btn:hover,
    .panel-tip-btn.is-open {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
    }
    .panel-tip-bubble {
      margin: -6px 0 14px;
      padding: 10px 12px;
      background: #f0f4ff;
      border: 1px solid #d5def5;
      border-radius: 10px;
      font-size: 13px;
      font-weight: 400;
      color: var(--text);
      line-height: 1.45;
      white-space: pre-wrap;
    }
    .panel-summary-with-tip {
      display: flex;
      align-items: center;
      gap: 8px;
      list-style: none;
    }
    .panel-summary-with-tip::-webkit-details-marker { display: none; }
    /* Название не растягивать — «?» сразу после текста, не у правого края */
    .panel-summary-with-tip > span { flex: 0 1 auto; min-width: 0; }
    .panel-head {
      display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
      margin: 0 0 14px; padding-bottom: 10px; border-bottom: 2px solid var(--border);
    }
    .panel-head h2 { margin: 0; padding: 0; border: none; flex: 1; min-width: 140px; }
    details.panel.accordion > summary {
      list-style: none; cursor: pointer;
      font-size: 17px; font-weight: 700; margin: 0 0 0; padding-bottom: 10px;
      border-bottom: 2px solid var(--border); color: var(--text); letter-spacing: -0.01em;
      display: flex; align-items: center; gap: 8px; user-select: none;
    }
    details.panel.accordion > summary::-webkit-details-marker { display: none; }
    details.panel.accordion > summary::before {
      content: '▸'; font-size: 14px; color: var(--muted); transition: transform .15s;
    }
    details.panel.accordion[open] > summary::before { transform: rotate(90deg); }
    details.panel.accordion[open] > summary { margin-bottom: 14px; }
    details.panel.accordion > .accordion-body { margin-top: 0; }
    .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
    .form-row button { width: auto; margin-top: 0; padding: 11px 22px; flex-shrink: 0; }
    label { margin-top: 0; }
    textarea {
      width: 100%; min-height: 110px; padding: 11px 14px; border: 1px solid var(--border);
      border-radius: 10px; font-size: 14px; font-family: inherit; resize: vertical;
    }
    textarea:focus { outline: none; border-color: var(--accent); }

    table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 12px; }
    th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
    th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .4px; }
    tr:hover td { background: #f8fafd; }
    td input[type="number"] { width: 64px; padding: 6px 8px; margin: 0; }
    td select { padding: 6px 8px; margin: 0; width: auto; }

    .btn-sm {
      width: auto; margin: 0; padding: 6px 14px; font-size: 13px; border-radius: 8px;
    }
    .btn-danger { background: var(--danger); }
    .btn-danger:hover { background: #b32741; }
    .btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
    .btn-ghost:hover { background: #f0f3fb; }

    .pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
    .pill.open { background: #e0f5e9; color: #14713d; }
    .pill.active { background: #e0f5e9; color: #14713d; }
    .pill.draft { background: #eef1f8; color: var(--muted); }
    .pill.closed { background: #fde4e8; color: #9f1d38; }

    /* Режимы: IRAT оранж · GRAT зелёный · Задания розовый · Эссе фиолетовый */
    .mode-irat, .badge.mode-irat, .pill.mode-irat {
      background: #fff1e0; color: #c45c12; border-color: #f0c48a;
    }
    .mode-grat, .badge.mode-grat, .pill.mode-grat {
      background: #e5f7ec; color: #14713d; border-color: #a8dcb8;
    }
    .mode-task, .badge.mode-task, .pill.mode-task {
      background: #fce7f3; color: #9d174d; border-color: #f9a8d4;
    }
    .mode-essay, .badge.mode-essay, .pill.mode-essay {
      background: #f3e8ff; color: #6b21a8; border-color: #d4b4f0;
    }
    select.mode-irat { background: #fff1e0; color: #c45c12; font-weight: 600; }
    select.mode-grat { background: #e5f7ec; color: #14713d; font-weight: 600; }
    select.mode-task { background: #fce7f3; color: #9d174d; font-weight: 600; }
    select.mode-essay { background: #f3e8ff; color: #6b21a8; font-weight: 600; }
    input.mode-irat { background: #fff1e0; color: #c45c12; }
    input.mode-grat { background: #e5f7ec; color: #14713d; }
    input.mode-task { background: #fce7f3; color: #9d174d; }
    input.mode-essay { background: #f3e8ff; color: #6b21a8; }
    #qr-overlay {
      position: fixed; inset: 0; background: rgba(26, 34, 51, 0.55);
      display: flex; align-items: center; justify-content: center; z-index: 9999; cursor: pointer;
    }
    #qr-overlay img {
      background: #fff; padding: 20px; border-radius: 14px;
      box-shadow: 0 12px 40px rgba(0,0,0,.25); max-width: 90vw; max-height: 90vh;
    }
    #essay-review-overlay, #qe-overlay, #bind-overlay, #join-code-overlay, #help-overlay {
      position: fixed; inset: 0; background: rgba(26, 34, 51, 0.55);
      display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 16px;
    }
    #essay-review-overlay .essay-review-card, #qe-overlay .qe-card, #bind-overlay .essay-review-card, #join-code-overlay .essay-review-card, #help-overlay .essay-review-card {
      background: #fff; border-radius: 14px; padding: 20px 22px; width: min(920px, 100%);
      max-height: 90vh; overflow: auto; box-shadow: 0 12px 40px rgba(0,0,0,.25); cursor: default;
    }
    #essay-review-overlay .essay-review-grid {
      display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
    }
    @media (max-width: 720px) {
      #essay-review-overlay .essay-review-grid { grid-template-columns: 1fr; }
    }

    /* —— Мобильная оболочка (десктоп не трогаем) —— */
    .mobile-only { display: none !important; }
    .m-sheet-bg, .m-sheet { display: none; }

    .mobile-desktop-hint {
      display: none;
      margin: 0 0 12px;
      padding: 10px 12px;
      border-radius: 10px;
      background: #f0f4ff;
      border: 1px solid #d5def5;
      color: var(--text);
      font-size: 12px;
      line-height: 1.45;
      font-weight: 500;
    }

    .icon-btn {
      width: 36px; height: 36px; margin: 0; padding: 0;
      border-radius: 10px; border: 1px solid var(--border);
      background: #fff; color: var(--text);
      font-size: 18px; font-weight: 700; line-height: 1;
      box-shadow: none; flex-shrink: 0; cursor: pointer;
    }
    .icon-btn:hover { background: #eef1fb; }

    .table-scroll {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      margin-top: 8px;
    }

    /* Карточки из таблицы: только с классом m-stack + data-label */
    table.m-stack { width: 100%; }

    @media (max-width: 720px) {
      .desktop-only { display: none !important; }
      .mobile-only { display: flex !important; }
      #mobile-desktop-hint.mobile-only {
        display: block !important;
      }
      /* на экране входа — та же подсказка */
      #login-card .mobile-only {
        display: inline !important;
      }

      .layout { padding: 12px 12px 96px; }
      .sticky-chrome {
        margin: 0 -12px 12px;
        padding: 10px 12px 8px;
      }
      .sticky-chrome .tabs { display: none !important; }
      .topbar { padding: 10px 12px; gap: 8px; margin-bottom: 0; }
      .topbar .brand-slogan { display: none; }
      .topbar .tb-name {
        font-size: 14px;
        max-width: min(150px, 36vw);
      }
      .panel { padding: 14px; }
      .panel h2, details.panel.accordion > summary { font-size: 15px; }

      .form-row {
        flex-direction: column;
        align-items: stretch;
      }
      .form-row .field-col { min-width: 0; width: 100%; }
      .form-row button,
      .form-row > button {
        width: 100%;
        margin-top: 0;
      }
      .row { gap: 8px; }
      .row > button, .row > .btn-sm {
        flex: 1 1 calc(50% - 8px);
        min-height: 40px;
      }

      /* Нижний tab bar */
      #mobile-tabbar {
        display: grid !important;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 60;
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid var(--border);
        padding: 4px 2px calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 20px rgba(26, 34, 51, 0.06);
      }
      #mobile-tabbar button {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        width: 100%;
        margin: 0;
        padding: 6px 2px;
        min-height: 52px;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: var(--muted);
        font-size: 10px;
        font-weight: 650;
        box-shadow: none;
        line-height: 1.15;
      }
      #mobile-tabbar button .m-ico { font-size: 17px; line-height: 1; }
      #mobile-tabbar button.active {
        color: var(--accent-hover);
        background: transparent;
      }

      /* Sheets */
      .m-sheet-bg {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 70;
        background: rgba(26, 34, 51, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity .18s ease;
      }
      .m-sheet-bg.open {
        opacity: 1;
        pointer-events: auto;
      }
      .m-sheet {
        display: block;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 71;
        background: #fff;
        border-radius: 18px 18px 0 0;
        padding: 10px 14px calc(16px + env(safe-area-inset-bottom, 0px));
        transform: translateY(110%);
        transition: transform .22s ease;
        max-height: 70vh;
        overflow: auto;
      }
      .m-sheet.open { transform: translateY(0); }
      .m-sheet-handle {
        width: 36px; height: 4px;
        border-radius: 999px;
        background: #d8dde8;
        margin: 4px auto 12px;
      }
      .m-sheet h3 {
        font-size: 14px;
        font-weight: 700;
        margin: 0 0 6px;
      }
      .m-sheet-item {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        margin: 0;
        padding: 14px 8px;
        border: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        background: transparent;
        color: var(--text);
        font-size: 15px;
        font-weight: 600;
        text-align: left;
        text-decoration: none;
        box-shadow: none;
        box-sizing: border-box;
      }
      a.m-sheet-item { color: var(--text); }
      .m-sheet-item:last-child { border-bottom: 0; }
      .m-sheet-item.danger { color: var(--danger); }

      /* Таблица → карточки */
      table.m-stack thead { display: none; }
      table.m-stack,
      table.m-stack tbody {
        display: block;
        width: 100%;
      }
      table.m-stack tr {
        display: block;
        background: #fafbfe;
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 10px 12px;
        margin: 0 0 10px;
      }
      table.m-stack tr:hover td { background: transparent; }
      table.m-stack td {
        display: grid;
        grid-template-columns: 34% 1fr;
        gap: 8px;
        align-items: start;
        padding: 5px 0;
        border: 0;
        font-size: 13px;
        word-break: break-word;
      }
      table.m-stack td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: .02em;
        padding-top: 2px;
      }
      table.m-stack td.m-stack-check {
        grid-template-columns: 1fr;
        padding-bottom: 2px;
      }
      table.m-stack td.m-stack-check::before { display: none; }
      table.m-stack td.m-stack-actions {
        grid-template-columns: 1fr;
        padding-top: 8px;
      }
      table.m-stack td.m-stack-actions::before { display: none; }
      table.m-stack td.m-stack-actions .btn-sm {
        margin: 4px 4px 0 0;
        min-height: 36px;
      }

      /* Широкие таблицы без m-stack — горизонтальный скролл */
      #tab-content table:not(.m-stack) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
      }
    }
    #qe-overlay .qe-opt-row {
      display: flex; gap: 8px; align-items: center; margin-top: 8px;
    }
    #qe-overlay .qe-opt-row input[type="text"] { flex: 1; margin: 0; }
    #qe-overlay .qe-opt-row label { margin: 0; white-space: nowrap; font-weight: 600; min-width: 1.6em; }
    .qe-list-item {
      padding: 10px 6px; border-bottom: 1px solid var(--border); cursor: pointer;
    }
    .qe-list-item:hover { background: #f4f6fb; }
    .essay-topic-block {
      border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-top: 8px;
      background: #fafbfe;
    }
    .essay-topic-block textarea { min-height: 72px; margin-top: 0; }
    .name-link {
      background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer;
      padding: 0; margin: 0; width: auto; text-align: left; text-decoration: underline;
    }
    .name-link:hover { color: var(--accent-hover); }
    .pill.done { background: #e0f5e9; color: #14713d; }
    .pill.prog { background: #fff4d6; color: #8a6d00; }
    .badge.owner { background: #fff4d6; color: #8a6d00; cursor: default; }

    .empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
    .toolbar-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
    .howto-ol {
      margin: 0;
      padding-left: 1.3em;
      font-size: 14px;
      line-height: 1.5;
    }
    .howto-ol > li { margin: 8px 0; }
    .howto-ol ul {
      margin: 6px 0 0;
      padding-left: 1.15em;
    }
    .howto-ol ul li { margin: 4px 0; }
    .copy-link {
      display: flex; gap: 8px; align-items: center; background: #f4f6fb;
      border-radius: 10px; padding: 10px 14px; font-size: 13px; word-break: break-all;
    }
    .lang-checks {
      display: flex; gap: 14px; flex-wrap: nowrap; align-items: center;
      min-height: 43px; padding: 0;
    }
    #iq-timer { width: 4.5em; max-width: 4.5em; }
    .lang-checks label {
      display: inline-flex; align-items: center; gap: 6px; margin: 0;
      font-size: 14px; font-weight: 500; cursor: pointer;
    }
    .lang-checks input[type="checkbox"] {
      width: 16px; height: 16px; margin: 0; padding: 0;
      flex: 0 0 auto; cursor: pointer;
    }
  

/* Плавность (замечание владельца 2026-10-04): обновление блока — без «прыжка», прежняя таблица бледнеет на время запроса;
   смена вкладки — короткое появление. */
.is-loading { opacity: .55; transition: opacity .15s ease; pointer-events: none; }
#tab-content > * { transition: opacity .15s ease; }
.tab-fade { animation: tabFade .16s ease-out; }
@keyframes tabFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tab-fade { animation: none; } }


/* Обновлённые условия — полоска «Принимаю» над панелью */
.terms-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 14px; padding: 10px 14px;
  border: 1px solid #f0d58a; border-radius: 10px; background: #fff8e1; font-size: 14px; line-height: 1.45; }
.terms-banner span { flex: 1 1 320px; }
.terms-banner button { width: auto; margin: 0; padding: 7px 16px; }
