:root {
  --bg: #0d0f13;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --accent: #f8c630;
  --accent-2: #53d2c2;
  --danger: #ff4e5b;
  --success: #3fd982;
  --text: #f4f4f4;
  --muted: rgba(255, 255, 255, 0.65);
  --header-height: 72px; /* Фиксируем высоту хедера */
}

* {
  box-sizing: border-box;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
}

html,
body {
  margin: 0;
  height: 100vh; /* Фиксируем высоту экрана */
  min-height: 100dvh;
  overflow: hidden; /* Запрещаем скролл страницы целиком */
  background: radial-gradient(circle at top left, #22283c 0%, #0d0f13 45%) fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
}

body.logged-in {
  --header-height: 48px;
}

body.login-open #app {
  filter: blur(6px);
  pointer-events: none;
  opacity: 0.7;
}

body.consent-open #app {
  filter: blur(6px);
  pointer-events: none;
  opacity: 0.7;
}

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

#app.main-app-container {
  height: 100dvh;
}

.landscape-scroll-spacer {
  display: none;
  height: 0;
}

/* --- HEADER --- */
.topbar {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.07), transparent);
}

.user-info {
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.user-info span {
  color: var(--text);
}

.user-info button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
}

.user-info .user-link {
  color: var(--text);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
}

.user-info .user-link:hover {
  background: rgba(255, 255, 255, 0.16);
}

body.logged-in .user-info {
  display: flex;
}

body.logged-in .help-btn {
  display: none;
}

.help-btn {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  background: #0f1118;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 20px 24px;
  width: min(520px, 90vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  margin: 0 0 12px;
}

.modal-card ol {
  padding-left: 18px;
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-card button {
  padding: 8px 12px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.login-card {
  width: min(420px, 92vw);
}

.login-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.login-form .email-input {
  flex: 1 1 220px;
}

.login-form #loginStatus {
  flex-basis: 100%;
  color: var(--muted);
}

.consent-card {
  width: min(720px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
}

.prep-card {
  width: min(640px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
}

.prep-summary {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 14px;
  display: grid;
  gap: 6px;
}

.prep-list {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--text);
  font-size: 14px;
}

.prep-list .prep-sep {
  list-style: none;
  margin: 10px 0;
}

.prep-actions {
  display: flex;
  justify-content: flex-end;
}

.consent-body p,
.consent-body li {
  color: var(--muted);
  line-height: 1.5;
}

.consent-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 12px 0;
  font-size: 14px;
}

.consent-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

#consentStatus {
  color: var(--muted);
  font-size: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.login {
  display: flex;
  gap: 8px;
}

.email-input {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
  width: 220px;
}

.email-input input {
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--text);
  width: 100%;
  outline: none;
}

.email-domain {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

.login button {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  color: #000;
}

/* --- WORKSPACE LAYOUT --- */
.workspace {
  flex: 1;
  display: grid;
  /* Левая колонка - 320px, Правая - все остальное */
  grid-template-columns: 320px 1fr; 
  gap: 20px;
  padding: 20px;
  height: calc(100vh - var(--header-height)); /* Высота минус хедер */
  overflow: hidden;
}

/* --- SIDEBAR (GRID PANEL) --- */
.grid-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(10px);
  height: 100%; /* Занимает всю высоту */
  overflow: hidden; /* Скрываем вылезающее */
}

.drawer-header {
  display: none;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.drawer-header button {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
}

.controls {
  flex-shrink: 0; /* Не сжимать селект */
  display: grid;
  gap: 10px;
}

.controls select {
  width: 100%;
  padding: 12px;
  background: #1a1d24;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* Контейнер для скролла списка кейсов */
.grid-scroll-area {
  flex: 1;
  overflow-y: auto; /* Включаем вертикальный скролл */
  padding-right: 4px; /* Место для скроллбара */
}

/* Кастомизация скроллбара */
.grid-scroll-area::-webkit-scrollbar {
  width: 6px;
}
.grid-scroll-area::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.2);
}
.grid-scroll-area::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
}

.grid {
  display: grid;
  /* Одна колонка для списка кейсов - более читаемо */
  grid-template-columns: 1fr; 
  gap: 8px;
}

.grid-group {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.grid-group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.grid-group-body {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.grid-cell {
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s;
}

.grid-cell:hover {
  background: rgba(255, 255, 255, 0.1);
}

.grid-cell.green {
  border-color: var(--success);
  background: rgba(63, 217, 130, 0.1);
}

.grid-cell.red {
  border-left: 3px solid var(--danger); /* Акцент слева вместо рамки */
}

.grid-cell.selected {
  background: rgba(248, 198, 48, 0.12);
  box-shadow: 0 0 0 2px rgba(248, 198, 48, 0.35);
}

.grid-cell.selected.green {
  border-color: var(--success);
}

.grid-cell.selected.red {
  border-left: 3px solid var(--danger);
}

.grid-cell strong {
  font-size: 14px;
  color: var(--accent);
}

.grid-cell span {
  font-size: 11px;
  color: var(--muted);
}

.grid-progress {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* --- CAMERA PANEL --- */
.camera-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  overflow: hidden;
}

.camera-wrap {
  position: relative;
  flex: 1; /* Занимает всё доступное место */
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify_content: center;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Чтобы видеть весь кадр целиком без обрезки */
}

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.status {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(calc(-50% + var(--drag-x, 0px)));
  background: rgba(0, 0, 0, 0.65);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  touch-action: none;
  will-change: transform;
  transition: transform 0.1s ease-out;
}

.step {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(calc(-50% + var(--drag-x, 0px)));
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  color: var(--accent);
  white-space: normal;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
  touch-action: none;
  will-change: transform;
  transition: transform 0.1s ease-out;
}

.countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 80px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 4px 20px rgba(0,0,0,0.5);
  pointer-events: none;
}

.info {
  flex-shrink: 0;
  background: var(--panel);
  padding: 12px 20px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.current-case {
  font-weight: 600;
  color: var(--accent);
}

.override {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.override button {
  padding: 10px 16px;
  background: var(--panel-strong);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.override button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.record-progress {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 160px;
  height: 160px;
  opacity: 0.95;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  display: grid;
  place-items: center;
  z-index: 5;
  transform: translate(-50%, -50%);
}

.record-progress.hidden {
  display: none;
}

.record-progress svg {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

.space-prompt {
  position: absolute;
  bottom: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(0, 0, 0, 0.75));
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px;
  z-index: 6;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.space-prompt.hidden {
  display: none;
}

.space-prompt-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 4px;
}

.space-prompt-body {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.space-prompt-timer {
  font-weight: 700;
  color: var(--accent);
}

.record-progress circle {
  fill: none;
  stroke-width: 4;
}

.record-progress .progress-bg {
  stroke: rgba(255, 255, 255, 0.15);
}

.record-progress .progress-ring {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 113.097;
  stroke-dashoffset: 113.097;
  transition: stroke 0.2s ease;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 30;
}

.drawer-backdrop.hidden {
  display: none;
}

.drawer-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.mobile-bar {
  display: none;
}

body.drawer-open .mobile-bar {
  opacity: 0;
  pointer-events: none;
}

/* --- MOBILE ADAPTATION --- */
@media (max-width: 1024px) {
  .topbar {
    padding: 10px 16px;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .brand {
    text-align: center;
  }

  .login {
    width: 100%;
  }
  .email-input { flex: 1; width: auto; }

  .workspace {
    grid-template-columns: 1fr;
    padding: 0;
    height: calc(100vh - var(--header-height));
    gap: 0;
  }

  .camera-panel {
    order: 1;
    padding: 0 0 150px;
  }

  .camera-wrap {
    border-radius: 0;
    min-height: 0;
  }

  video,
  #overlay {
    object-fit: cover;
  }

  .status {
    bottom: 96px;
    font-size: 13px;
    max-height: 25vh;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: pan-y;
    white-space: normal;
  }

  .step {
    font-size: 12px;
    max-height: 25vh;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: pan-y;
  }

  .countdown {
    font-size: clamp(48px, 12vw, 72px);
  }

  .record-progress {
    width: 140px;
    height: 140px;
  }

  .record-progress svg {
    width: 100px;
    height: 100px;
  }

  .info,
  .override {
    display: none;
  }

  .grid-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 70vh;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 40;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.35);
    padding-top: 12px;
  }

  .grid-panel.open {
    transform: translateY(0);
  }

  .drawer-header {
    display: flex;
  }

  .grid-panel .controls {
    display: grid;
    gap: 8px;
  }

  .grid-scroll-area {
    padding-right: 8px;
  }

  .mobile-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    width: 100vw;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(44px, auto);
    gap: 8px;
    align-items: center;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(8, 10, 14, 0.92);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 9999;
    backdrop-filter: blur(12px);
    max-height: 160px;
  }

  .mobile-bar button,
  .mobile-bar select {
    min-height: 44px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-capture {
    grid-column: 1 / -1;
    min-height: 56px;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: #000;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
  }

  .mobile-attack {
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: #1a1d24;
    color: var(--text);
    padding: 8px 12px;
  }

  .mobile-camera {
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: #1a1d24;
    color: var(--text);
    padding: 8px 12px;
  }

  .mobile-progress {
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
  }

  body.logged-in .topbar {
    height: 44px;
    padding: 0 12px;
    justify-content: space-between;
  }

  body.logged-in .brand {
    display: none;
  }
}

@media (max-width: 1024px) and (orientation: portrait) {
  .mobile-bar {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: minmax(44px, auto);
  }

  .mobile-bar button,
  .mobile-bar select {
    white-space: normal;
    text-overflow: clip;
    line-height: 1.1;
  }

  .mobile-attack,
  .mobile-camera,
  .mobile-progress {
    letter-spacing: -0.5px;
  }
}

@media (max-width: 600px) {
  .mobile-bar button,
  .mobile-bar select {
    font-size: 12px;
  }
}

@media (max-width: 1024px) and (orientation: landscape) {
  .camera-panel {
    padding: 0 210px 0 0;
  }

  html,
  body {
    overflow-y: auto !important;
    min-height: 101vh !important;
  }

  #app.main-app-container {
    overflow-y: auto !important;
  }

  .landscape-scroll-spacer {
    display: block;
    height: 20vh;
    width: 100%;
  }

  .mobile-bar {
    top: var(--header-height);
    bottom: 0;
    right: 0;
    left: auto;
    width: 200px;
    height: calc(100vh - var(--header-height));
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(44px, auto);
    justify-content: start;
    padding: 12px;
  }

  .mobile-bar button,
  .mobile-bar select {
    width: 100%;
  }

  .mobile-capture {
    grid-column: 1;
    min-height: 50px;
  }

  .status {
    bottom: 24px;
  }

  .grid-panel {
    height: calc(100vh - var(--header-height));
  }
}
