/* Video Service — построено на токенах Infomaximum Design System (tokens.css) */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg-complimentary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: var(--text-header-2-size); line-height: var(--text-header-2-lh); font-weight: 500; margin: 0; }
h2 { font-size: var(--text-header-1-size); line-height: var(--text-header-1-lh); font-weight: 500; margin: 0; }

.text-secondary { color: var(--text-secondary); margin: 0; }

/* ───────── Layout ───────── */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-1) var(--space-1);
}

.card {
  background: var(--bg-primary);
  border: 1px solid var(--line-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-hint {
  font-size: var(--text-body-3-size);
  color: var(--text-secondary);
  margin-left: auto;
  text-align: right;
}

.card-actions { display: flex; flex-direction: column; gap: var(--space-4); }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ───────── Buttons ───────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: none;
  font-family: var(--font-sans);
  font-size: var(--text-body-2-size);
  font-weight: 500;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background-color .15s ease-out, border-color .15s ease-out, color .15s ease-out, box-shadow .15s ease-out;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus-primary); }
.btn:disabled { opacity: var(--opacity-loading); cursor: not-allowed; }
.btn svg { flex-shrink: 0; width: 16px; height: 16px; }

.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-body-3-size); }
.btn-lg { height: 44px; font-size: 15px; }
.btn-full { width: 100%; }

.btn-primary { background: var(--primary-base); color: var(--text-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-active); }

.btn-secondary { background: var(--bg-primary); border-color: var(--line-border); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-container-hover); }
.btn-secondary:active:not(:disabled) { background: var(--bg-container-active); }

.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-container-hover); color: var(--text-primary); }

.icon-btn { width: 32px; height: 32px; padding: 0; }

/* ───────── Forms ───────── */

.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field-label { font-size: var(--text-body-3-size); color: var(--text-secondary); }

.input {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--line-border);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body-2-size);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:hover:not(:focus) { border-color: var(--neutral-65); }
.input:focus { border-color: var(--primary-base); box-shadow: var(--shadow-focus-primary); }
.input::placeholder { color: var(--text-hint); }

.alert {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-body-3-size);
  margin: 0;
}
.alert-error { background: var(--danger-bg); color: var(--danger-active); border: 1px solid var(--danger-border); }

/* Чекбокс */
.notify-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-body-2-size);
  cursor: pointer;
  user-select: none;
}
.notify-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkbox-box {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  position: relative;
  border: 1px solid var(--line-border);
  border-radius: var(--radius-xs);
  background: var(--bg-primary);
  transition: background-color .15s, border-color .15s;
}
.notify-toggle:hover .checkbox-box { border-color: var(--neutral-65); }
.notify-toggle input:checked ~ .checkbox-box {
  background: var(--primary-base);
  border-color: var(--primary-base);
}
.notify-toggle input:checked ~ .checkbox-box::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid var(--text-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.notify-toggle input:focus-visible ~ .checkbox-box { box-shadow: var(--shadow-focus-primary); }

/* ───────── Строки видео ───────── */

#video-rows { display: flex; flex-direction: column; gap: var(--space-2); }
#video-rows:not(:empty) { margin-bottom: var(--space-3); }

.video-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line-divider);
  border-radius: var(--radius-md);
  transition: border-color .15s;
}
.video-row:hover { border-color: var(--line-border); }
.video-row.is-filled { align-items: flex-start; }

.row-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  margin-top: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-complimentary);
  color: var(--text-secondary);
  font-size: var(--text-body-3-size);
  font-weight: 500;
  font-feature-settings: "tnum";
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }

.video-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  min-height: 26px;
}
.video-meta-title {
  font-size: var(--text-body-2-size);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-tag {
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-complimentary);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 18px;
}
.video-clear-btn { margin-left: auto; }

.video-row-actions { flex-shrink: 0; display: flex; align-items: center; gap: var(--space-1); margin-top: 2px; }

/* ───────── Выбор папки ───────── */

.folder-picker {
  border: 1px solid var(--line-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.folder-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-bottom: 1px solid var(--line-divider);
}
.folder-path {
  flex: 1;
  min-width: 0;
  padding: 0 var(--space-1);
  font-size: var(--text-body-3-size);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-create-row {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2);
  border-bottom: 1px solid var(--line-divider);
  background: var(--bg-complimentary);
}
.folder-create-row .input { height: 32px; }

.folder-list {
  list-style: none;
  margin: 0;
  padding: var(--space-1);
  max-height: 216px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body-2-size);
  text-align: left;
  cursor: pointer;
  transition: background-color .12s;
}
.folder-item:hover { background: var(--bg-container-hover); }
.folder-item:focus-visible { outline: none; box-shadow: var(--shadow-focus-primary); }
.folder-item svg { flex-shrink: 0; width: 16px; height: 16px; color: var(--text-secondary); }
.folder-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.folder-empty { padding: var(--space-3); color: var(--text-hint); font-size: var(--text-body-3-size); }

.folder-selected {
  margin: var(--space-3) 0 0;
  font-size: var(--text-body-3-size);
  color: var(--text-secondary);
}
.folder-selected strong { color: var(--text-primary); font-weight: 500; }

/* ───────── Статус обработки ───────── */

.status-panel-header { justify-content: space-between; align-items: center; }

#status-list { display: flex; flex-direction: column; gap: var(--space-2); }

.status-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--line-divider);
  border-radius: var(--radius-md);
  transition: opacity .25s ease-out, transform .25s ease-out;
}
.status-row.is-removing { opacity: 0; transform: translateY(-4px); }

.status-row-main { display: flex; align-items: center; gap: var(--space-2); }
.status-title {
  flex: 1;
  min-width: 0;
  font-size: var(--text-body-2-size);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  flex-shrink: 0;
  padding: 2px 10px;
  border-radius: var(--radius-round);
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
  font-feature-settings: "tnum";
}
.status-queued, .status-cancelled { background: var(--bg-complimentary); color: var(--text-secondary); }
.status-downloading, .status-uploading { background: var(--info-bg); color: var(--info-active); }
.status-done { background: var(--positive-bg); color: var(--positive-active); }
.status-error { background: var(--danger-bg); color: var(--danger-active); }

.status-message {
  margin: 0;
  font-size: var(--text-body-3-size);
  color: var(--danger-active);
  word-break: break-word;
}

.status-progress-track {
  height: 4px;
  border-radius: var(--radius-round);
  background: var(--neutral-40);
  overflow: hidden;
}
.status-progress-fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-round);
  background: var(--info-base);
  transition: width .4s ease-out, background-color .2s;
}
.fill-done { background: var(--positive-base); }
.fill-error { background: var(--danger-base); }
.fill-cancelled { background: var(--neutral-60); }

/* ───────── Мобильные ───────── */

@media (max-width: 560px) {
  .page { padding: var(--space-4) var(--space-3) var(--space-6); gap: var(--space-2); }
  .card { padding: var(--space-4); border-radius: var(--radius-md); }
  .card-header { margin-bottom: var(--space-3); flex-wrap: wrap; gap: var(--space-1); }
  .card-hint { margin-left: 0; text-align: left; width: 100%; }

  h1 { font-size: 20px; line-height: 28px; }

  /* 16px, иначе iOS зумит страницу при фокусе на поле */
  .input { font-size: 16px; height: 42px; }

  .btn { height: 42px; }
  .btn-sm { height: 34px; }
  .icon-btn { width: 34px; height: 34px; }

  .video-row { padding: var(--space-2); gap: var(--space-2); }
  .row-num { width: 24px; height: 24px; }

  .folder-create-row { flex-wrap: wrap; }
  .folder-create-row .input { flex: 1 1 100%; height: 42px; }
  .folder-list { max-height: 180px; }

  .status-row-main { flex-wrap: wrap; }
  .status-title { flex: 1 1 100%; }
}
