:root {
  color-scheme: light;
  --bg: #f5f8fc;
  --text: #142d52;
  --muted: #637895;
  --line: #d7e3f1;
  --panel: #ffffff;
  --accent: #193e73;
  --accent-strong: #2459a4;
  --accent-soft: #edf4ff;
  --gold: #c49a52;
  --danger: #b42318;
  --ok: #0f7b5f;
  --shadow: 0 14px 36px rgba(25, 62, 115, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 220px),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1400px, calc(100vw - 32px));
  margin: 24px auto;
}

.topbar,
.band,
.projects-section,
.editor-section,
.clips-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 22px;
  background: linear-gradient(135deg, #193e73 0%, #2459a4 100%);
  color: white;
  border-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 19px;
}

.topbar p {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.78);
}

.status-pill {
  min-width: 156px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 9px 12px;
  text-align: center;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.08);
}

.status-pill.ok {
  color: var(--ok);
  border-color: #b7dfca;
  background: #eefbf5;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  padding: 7px 12px;
  cursor: pointer;
}

.telegram-panel {
  display: grid;
  grid-template-columns: 180px minmax(120px, 160px) minmax(150px, 180px) 140px 150px;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.telegram-panel input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.telegram-panel button,
.link-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.telegram-panel button:hover,
.link-button:hover,
.section-head button:hover,
.metric button:hover,
.topbar-actions button:hover {
  border-color: var(--accent-strong);
}

.telegram-status {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--muted);
}

.telegram-status.ok {
  color: var(--ok);
  background: #eefbf5;
  border-color: #b7dfca;
}

.band {
  margin-top: 16px;
  padding: 18px;
  border-top: 3px solid var(--gold);
}

.upload-panel {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 210px minmax(280px, 1fr) 150px;
  gap: 16px;
  align-items: end;
}

.field label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.segments {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f7faff;
}

.segment {
  height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
}

input[type="number"],
input[type="file"],
input[type="text"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 8px 10px;
  color: var(--text);
}

.primary,
.section-head button,
.metric button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.primary {
  min-height: 42px;
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: white;
  font-weight: 600;
}

.primary:hover {
  filter: brightness(1.04);
}

.primary:disabled {
  opacity: 0.55;
  cursor: default;
}

.progress-wrap {
  margin-top: 16px;
}

.progress-label {
  margin-bottom: 8px;
  color: var(--muted);
}

.progress {
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #edf4ff;
}

.progress > div {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-strong) 100%);
  transition: width 150ms ease;
}

.storage-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric {
  min-height: 96px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(25, 62, 115, 0.06);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin: 9px 0 12px;
  font-size: 22px;
  color: var(--accent);
}

.metric button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--danger);
}

.projects-section {
  margin-top: 16px;
  padding: 18px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-head button {
  min-height: 34px;
  padding: 6px 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #516985;
  font-weight: 600;
  background: #f8fbff;
}

.filename {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--accent-soft);
  color: var(--muted);
}

.status.audio_ready {
  background: #eefbf5;
  color: var(--ok);
}

.status.candidates_ready {
  background: #edf6ff;
  color: var(--accent);
}

.status.error {
  background: #fff0ed;
  color: var(--danger);
}

.links a {
  color: var(--accent);
  text-decoration: none;
  margin-right: 10px;
}

.link-button {
  color: var(--accent);
  padding: 2px 8px;
}

.links .link-button {
  margin-right: 10px;
}

.link-button.danger-link {
  color: var(--danger);
  border-color: #f1c5c0;
}

.candidates-section {
  margin-top: 16px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.candidate-text {
  max-width: 440px;
  white-space: normal;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(25, 62, 115, 0.96), rgba(36, 89, 164, 0.92)),
    var(--bg);
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(10, 29, 56, 0.22);
  border-top: 4px solid var(--gold);
}

.login-card h1 {
  color: var(--accent);
}

.login-card p {
  margin-top: 8px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.login-form button {
  min-height: 42px;
}

.login-error {
  color: var(--danger);
  font-size: 14px;
}

.editor-section,
.clips-section {
  margin-top: 16px;
  padding: 18px;
}

.section-head span {
  color: var(--muted);
  font-size: 14px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(260px, 320px);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.editor-main-column {
  display: grid;
  gap: 14px;
}

.editor-preview-column {
  display: grid;
  justify-items: start;
  align-content: start;
}

.video-panel {
  background: #0b1020;
  border-radius: 8px;
  overflow: hidden;
}

.editor-video-stage {
  position: relative;
  width: 100%;
  background: #0b1020;
  overflow: hidden;
}

.video-panel video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 640px;
  background: #0b1020;
}

.editor-crop-box {
  position: absolute;
  top: 0;
  left: 0;
  border: 3px solid #30d158;
  background: rgba(48, 209, 88, 0.08);
  cursor: grab;
  outline: none;
  touch-action: none;
}

.editor-crop-box:active {
  cursor: grabbing;
}

.editor-crop-box:focus {
  box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.35);
}

.safe-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.75);
}

.safe-line.left {
  left: 12%;
}

.safe-line.right {
  right: 12%;
}

.crop-label {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12px;
}

.editor-controls {
  display: grid;
  gap: 14px;
}

.editor-controls .field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.time-controls {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 150px;
  gap: 10px;
  align-items: end;
}

.time-controls button,
.editor-actions button,
.camera-buttons button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.camera-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.preview-block {
  display: grid;
  gap: 8px;
  width: min(300px, 100%);
}

.preview-block span,
.crop-readout {
  color: var(--muted);
  font-size: 14px;
}

#editorPreviewCanvas {
  width: 100%;
  aspect-ratio: 9 / 16;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1020;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.editor-actions button {
  padding: 8px 14px;
}

.editor-actions .primary {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.status.rendering {
  background: #fff7e6;
  color: #8a5a00;
}

.status.rendered {
  background: #eefbf5;
  color: var(--ok);
}

.clip-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

#keyframesBody tr {
  cursor: pointer;
}

#keyframesBody tr:hover {
  background: #f4f8ff;
}

#keyframesBody tr.selected {
  background: #e8f1ff;
}

@media (max-width: 980px) {
  .upload-panel,
  .storage-grid,
  .telegram-panel,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    width: 100%;
  }
}
