:root {
  --bg: #0f1117;
  --panel: #171a22;
  --border: #2a3140;
  --text: #eef2ff;
  --muted: #93a0b8;
  --primary: #5b8cff;
  --primary-hover: #4a7af0;
  --danger: #ef5b5b;
  --success: #3ecf8e;
  --warning: #f0b429;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  background: linear-gradient(180deg, #0b0d12 0%, #12151d 100%);
  color: var(--text);
  min-height: 100vh;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.layout-main .panel {
  padding: 18px 20px;
}

.auth-card {
  width: min(420px, 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
}

.topbar h1,
.panel h2 {
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
}

.dashboard {
  padding: 24px 32px 40px;
  max-width: 1100px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 8px;
  font-size: 14px;
}

.back-link:hover {
  color: var(--primary);
}

.broadcast-name-input {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  background: transparent;
  border: 0;
  color: var(--text);
  width: 100%;
  max-width: 480px;
  padding: 0;
}

.broadcast-name-input:focus {
  outline: none;
  border-bottom: 1px solid var(--primary);
}

.youtube-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  margin-bottom: 16px;
  background: #11151d;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.broadcasts-table {
  width: 100%;
  border-collapse: collapse;
}

.broadcasts-table th,
.broadcasts-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.broadcasts-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.broadcasts-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.row-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.row-link:hover {
  color: var(--primary);
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.badge.inline {
  display: inline-block;
}

.center {
  text-align: center;
}

.page-shell {
  display: grid;
  grid-template-columns: 620px 460px;
  gap: 28px;
  padding: 24px 32px 40px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  align-items: start;
}

.layout-main {
  width: 620px;
  min-width: 0;
  max-width: 620px;
  overflow: hidden;
  display: grid;
  gap: 16px;
}

.right-sidebar {
  width: 460px;
  min-width: 460px;
  max-width: 460px;
  position: sticky;
  top: 20px;
  display: grid;
  gap: 16px;
  align-content: start;
}

.right-sidebar .panel-header {
  flex-wrap: nowrap;
  gap: 12px;
}

.right-sidebar .panel-header h2 {
  flex-shrink: 0;
  white-space: nowrap;
}

.right-sidebar .panel-header .actions {
  flex-shrink: 0;
}

.preview-panel {
  width: 100%;
  box-sizing: border-box;
}

.right-sidebar .info-grid {
  grid-template-columns: 1fr 1fr;
}

.stream-duration.live {
  color: var(--success, #22c55e);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

#stream-lag-hint {
  margin-top: 8px;
  color: var(--warning);
}

.preview-panel h2 {
  margin-bottom: 12px;
}

.watermark-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.watermark-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.watermark-box {
  position: absolute;
  z-index: 2;
  box-sizing: border-box;
  border: 2px dashed rgba(91, 140, 255, 0.9);
  cursor: grab;
  touch-action: none;
}

.watermark-box.dragging {
  cursor: grabbing;
  opacity: 0.92;
}

.watermark-box.resizing {
  cursor: default;
}

.watermark-box img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}

.wm-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 2px;
  z-index: 3;
  box-sizing: border-box;
}

.wm-handle-nw {
  top: -7px;
  left: -7px;
  cursor: nwse-resize;
}

.wm-handle-ne {
  top: -7px;
  right: -7px;
  cursor: nesw-resize;
}

.wm-handle-sw {
  bottom: -7px;
  left: -7px;
  cursor: nesw-resize;
}

.wm-handle-se {
  bottom: -7px;
  right: -7px;
  cursor: nwse-resize;
}

.preview-actions {
  margin-top: 10px;
}

.preview-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(8, 10, 14, 0.97);
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  box-sizing: border-box;
}

.preview-fullscreen.hidden {
  display: none;
}

.preview-fullscreen-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.preview-fullscreen-header h3 {
  margin: 0 0 4px;
}

.preview-fullscreen-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.watermark-stage-fullscreen {
  max-width: 96vw;
  max-height: calc(100vh - 140px);
  border-radius: 12px;
}

.preview-fullscreen-hint {
  margin: 14px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

body.preview-fs-open {
  overflow: hidden;
}

.preview-placeholder {
  aspect-ratio: 16 / 9;
  background: #11151d;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  padding: 16px;
}

.preview-placeholder span {
  font-size: 32px;
  opacity: 0.4;
}

.preview-frame-wrap {
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.preview-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.preview-open-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.preview-open-link:hover {
  text-decoration: underline;
}

.youtube-links {
  margin-top: 16px;
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #11151d;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.link-row {
  display: grid;
  gap: 4px;
}

.link-row a {
  color: var(--primary);
  word-break: break-all;
  text-decoration: none;
}

.link-row a:hover {
  text-decoration: underline;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.actions,
.topbar-actions,
.watermark-upload {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn,
.upload-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  background: var(--primary);
  color: white;
}

.upload-btn.secondary {
  background: #2a3140;
  color: var(--text);
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.success {
  background: var(--success);
  color: #0b1a12;
}

.btn.success:hover {
  background: #35b87d;
}

.btn.danger {
  background: var(--danger);
  color: white;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.badge {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.badge.idle {
  background: #2a3140;
  color: var(--muted);
}

.badge.running {
  background: rgba(62, 207, 142, 0.15);
  color: var(--success);
}

.badge.error {
  background: rgba(239, 91, 91, 0.15);
  color: var(--danger);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.playlist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #11151d;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: grab;
  min-width: 0;
  max-width: 100%;
}

.playlist-item.dragging {
  opacity: 0.5;
}

.drag-handle {
  color: var(--muted);
  user-select: none;
}

.playlist-meta {
  flex: 1;
  min-width: 0;
}

.playlist-meta strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-form,
#login-form {
  display: grid;
  gap: 16px;
}

.settings-form label,
#login-form label {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

.settings-form input,
.settings-form select,
.settings-form textarea,
#login-form input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #11151d;
  color: var(--text);
}

.checkbox {
  display: flex !important;
  align-items: flex-start;
  gap: 10px;
  font-weight: 500 !important;
}

.checkbox input {
  width: auto;
  margin-top: 3px;
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.message {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.message.success {
  background: rgba(62, 207, 142, 0.12);
  color: var(--success);
}

.message.error {
  background: rgba(239, 91, 91, 0.12);
  color: var(--danger);
}

.message.info {
  background: rgba(91, 140, 255, 0.12);
  color: var(--primary);
}

.error {
  color: var(--danger);
}

.youtube-status {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.watch-url {
  margin-top: 12px;
  padding: 12px;
  background: #11151d;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: grid;
  gap: 6px;
}

.watch-url a {
  color: var(--primary);
  word-break: break-all;
}

.upload-progress {
  margin-bottom: 12px;
}

.progress-bar {
  height: 8px;
  background: #2a3140;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #7aa2ff);
  transition: width 0.2s ease;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
    width: 100%;
    padding-left: 16px;
    padding-right: 16px;
  }

  .layout-main {
    width: 100%;
    max-width: 100%;
  }

  .right-sidebar {
    position: static;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
