*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  line-height: 1.5;
}
h1, h2, h3, h4, p, ul { margin: 0; padding: 0; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: none;
  background: #3b82f6;
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  min-height: 44px;
  transition: background 0.15s, opacity 0.15s;
}
button:hover { background: #2563eb; }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.secondary { background: #334155; }
button.secondary:hover { background: #475569; }
button.danger { background: #ef4444; }
button.danger:hover { background: #dc2626; }
input, select, textarea {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  min-height: 44px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #3b82f6;
}
code {
  background: #1e293b;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  word-break: break-all;
  display: inline-block;
}
.hidden { display: none !important; }

#app { display: flex; min-height: 100vh; }

.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
  align-items: center;
  padding: 0 16px;
  z-index: 110;
  gap: 12px;
}
.mobile-header h1 { font-size: 1.1rem; }
.menu-toggle {
  background: transparent;
  font-size: 1.5rem;
  padding: 4px;
  min-height: 44px;
  min-width: 44px;
}
.menu-toggle:hover { background: #334155; }

.sidebar {
  width: 320px;
  background: #1e293b;
  border-right: 1px solid #334155;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid #334155;
}
.sidebar-header h1 { font-size: 1.25rem; }
.menu-close {
  background: transparent;
  font-size: 1.25rem;
  min-height: 44px;
  min-width: 44px;
}
.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid #334155;
}
.sidebar-section h2 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 12px;
}

.mp-list { list-style: none; margin-bottom: 12px; }
.mp-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
}
.mp-list li:hover { background: #334155; }
.mp-list li.active { background: #3b82f6; }
.mp-list li .mp-status {
  width: 8px; height: 8px; border-radius: 50%;
  background: #64748b;
  flex-shrink: 0;
  margin-right: 8px;
}
.mp-list li .mp-status.on { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.mp-list li .mp-label { flex: 1; font-size: 0.95rem; }
.mp-list li .mp-delete {
  background: transparent;
  color: #ef4444;
  padding: 4px 8px;
  min-height: 32px;
  font-size: 0.8rem;
  opacity: 0.7;
}
.mp-list li .mp-delete:hover { opacity: 1; background: #450a0a; }

.add-form { display: flex; flex-direction: column; gap: 8px; }
.add-form input, .add-form textarea, .add-form select { font-size: 0.9rem; }
.add-form textarea {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  color: #e2e8f0;
  width: 100%;
  resize: vertical;
}
.advanced-section { margin-top: 8px; }
.advanced-section summary {
  font-size: 0.85rem;
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}
.advanced-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #94a3b8;
  margin: 10px 0 6px;
}

.manual-toggle {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 6px;
}
.manual-toggle a { color: #3b82f6; cursor: pointer; }
.manual-toggle a:hover { text-decoration: underline; }
.manual-input {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  min-height: 32px;
  background: #334155;
}
.edit-btn:hover { background: #475569; }

.platform-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  min-height: 44px;
}
.platform-icon { font-size: 1.1rem; width: 24px; text-align: center; }
.platform-name { flex: 1; font-size: 0.95rem; }
.platform-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #94a3b8;
}
.platform-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.platform-status .dot.on { background: #22c55e; }
.platform-action { font-size: 0.8rem; padding: 6px 10px; }
.platform-warning {
  width: 100%;
  font-size: 0.75rem;
  color: #f59e0b;
  background: #451a03;
  padding: 6px 10px;
  border-radius: 4px;
  margin-top: 4px;
}

.log-panel {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  padding: 8px;
}
.log-line {
  padding: 2px 0;
  border-bottom: 1px solid #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-line:last-child { border-bottom: none; }
.log-time { color: #64748b; margin-right: 6px; }
.log-tag { font-weight: 600; margin-right: 6px; }
.log-tag-RTMP { color: #22c55e; }
.log-tag-API { color: #3b82f6; }
.log-tag-FORWARD { color: #a855f7; }
.log-tag-OVERLAY { color: #f97316; }
.log-tag-OAUTH { color: #06b6d4; }
.log-tag-WS { color: #64748b; }
.log-tag-FFMPEG { color: #eab308; }
.log-tag-ERROR { color: #ef4444; }
.log-level-ERROR { color: #ef4444; }
.log-level-WARN { color: #f59e0b; }
.log-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.log-filter {
  font-size: 0.7rem;
  padding: 4px 8px;
  min-height: 28px;
  background: #334155;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}
.log-filter.active { background: #3b82f6; }

.overlay-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.overlay-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.overlay-card img {
  width: 100%;
  height: 80px;
  object-fit: contain;
  background: #1e293b;
  display: block;
}
.overlay-card .overlay-name {
  padding: 6px 8px;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.overlay-card .overlay-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #ef4444;
  padding: 2px 6px;
  font-size: 0.75rem;
  min-height: 28px;
  border-radius: 4px;
}

.upload-area {
  border: 2px dashed #334155;
  border-radius: 6px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.upload-area:hover { border-color: #3b82f6; }
.upload-area p { font-size: 0.85rem; color: #94a3b8; margin-bottom: 8px; }
.upload-area input { display: none; }

#overlay-preview-container { margin-top: 12px; }
#overlay-preview-container img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  background: #0f172a;
  border-radius: 6px;
  display: block;
  margin-bottom: 8px;
}

.main { flex: 1; padding: 24px; overflow-y: auto; }
.welcome {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}

.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}
.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.info-row label {
  font-size: 0.85rem;
  color: #94a3b8;
  min-width: 80px;
}
.info-row code { flex: 1; min-width: 200px; }
.copy-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  min-height: 32px;
}

.video-card video {
  width: 100%;
  max-height: 400px;
  background: #000;
  border-radius: 6px;
}
.video-placeholder {
  width: 100%;
  max-height: 400px;
  background: #0f172a;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.9rem;
  min-height: 200px;
}

.stream-settings-card .settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.stream-settings-card .settings-col h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: #94a3b8;
  margin: 0 0 10px;
}
.stream-settings-card .setting-value {
  color: #e2e8f0;
  font-size: 0.9rem;
  flex: 1;
}

.forward-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.forward-card .forward-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.forward-card .fwd-status { font-size: 0.85rem; color: #94a3b8; }
.forward-card .fwd-status.on { color: #22c55e; }

#overlay-current {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
#overlay-current img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  background: #0f172a;
  border-radius: 4px;
  border: 1px solid #334155;
}
.warning-banner {
  background: #451a03;
  color: #f59e0b;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-top: 10px;
}

#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1e293b;
  border: 1px solid #334155;
  border-left: 4px solid #3b82f6;
  padding: 12px 16px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}
.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: #ef4444; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

.offline-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #450a0a;
  color: #ef4444;
  text-align: center;
  padding: 8px;
  font-size: 0.85rem;
  z-index: 300;
}
.offline-banner.show { display: block; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 767px) {
  .mobile-header { display: flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main { padding: 72px 16px 16px; width: 100%; }
  .mobile-only { display: block; }
  .forward-cards { grid-template-columns: 1fr; }
  .overlay-grid { grid-template-columns: repeat(3, 1fr); }
  .info-row { flex-direction: column; align-items: flex-start; }
  .info-row code { width: 100%; }
}
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}
