:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #25d366;
  --accent-dim: #1da851;
  --warn: #f59e0b;
  --error: #ef4444;
  --success: #22c55e;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

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

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.header-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.stream-pill {
  font-size: 0.8rem;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.app-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-group-broadcasts {
  border-color: rgba(37, 211, 102, 0.35);
  background: linear-gradient(180deg, rgba(37, 211, 102, 0.08), var(--surface));
}

.nav-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.nav-group-hint {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.nav-item {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav-item.active {
  background: rgba(37, 211, 102, 0.15);
  border-color: rgba(37, 211, 102, 0.45);
  color: #fff;
}

.nav-item-broadcast {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.nav-item-broadcast .broadcast-name {
  font-weight: 600;
}

.nav-item-broadcast .broadcast-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.nav-item-broadcast.active .broadcast-meta {
  color: rgba(255, 255, 255, 0.75);
}

.main-content {
  min-width: 0;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.broadcast-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.broadcast-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}

.broadcast-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.broadcast-card-icon {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.broadcast-card-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.broadcast-card-desc {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.broadcast-card-status {
  font-size: 0.78rem;
}

.broadcast-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.broadcast-panel-header h2 {
  margin: 0;
}

.back-link {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--text);
  background: var(--border);
}

@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav-group {
    padding: 12px;
  }
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.card-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.card-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.card-value.connected {
  color: var(--success);
}

.card-value.disconnected {
  color: var(--error);
}

.card-value.warn {
  color: var(--warn);
}

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

section h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.95rem;
}

input[type="time"] {
  min-width: 140px;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
  direction: ltr;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

button.is-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.is-loading .btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

button:hover {
  background: var(--accent-dim);
}

button:disabled:hover {
  background: var(--accent);
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover {
  background: var(--border);
}

button.danger {
  background: var(--error);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

#qr-container {
  text-align: center;
  padding: 16px;
}

#qr-container img {
  max-width: 260px;
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

th {
  color: var(--muted);
  font-weight: 500;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-badge.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.status-badge.failed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.status-badge.partial {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warn);
}

#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 100;
}

#toast.show {
  opacity: 1;
}

.char-count {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

.char-count.over {
  color: var(--error);
  font-weight: 600;
}

.activity-list {
  max-height: 300px;
  overflow-y: auto;
}

.activity-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.activity-item .time {
  color: var(--muted);
  margin-right: 8px;
}

.activity-item .event {
  font-weight: 500;
}

.activity-item .details {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
  word-break: break-all;
}

.message-preview {
  white-space: pre-wrap;
  direction: rtl;
  text-align: right;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.9rem;
}

.nav-item-create {
  border-style: dashed;
  color: var(--accent);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  color: var(--muted);
}

#panel-create-broadcast textarea,
.view-panel textarea {
  width: 100%;
  min-height: 80px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

#bf-message-template {
  direction: rtl;
  font-family: inherit;
  min-height: 180px;
}

.form-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.form-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(37, 211, 102, 0.2);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

.textarea-ltr {
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.textarea-message {
  direction: rtl;
  text-align: right;
  font-family: inherit;
  min-height: 180px;
}

.field-warning {
  color: var(--warn);
  font-size: 0.85rem;
  margin: 0 0 8px;
}

.setup-steps {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.setup-steps li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.setup-steps li.done {
  color: var(--success);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 24px !important;
}

.error-cell {
  max-width: 220px;
  word-break: break-word;
  font-size: 0.8rem;
}

#setup-checklist {
  background: linear-gradient(135deg, rgba(37, 211, 102, 0.08), var(--surface));
  border-color: rgba(37, 211, 102, 0.3);
}

#setup-checklist h3 {
  margin-top: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -8px 0 16px;
}

.schedule-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.schedule-row .muted {
  color: var(--muted);
}

.schedule-row-link {
  cursor: pointer;
  border-radius: 8px;
  padding-left: 8px;
  padding-right: 8px;
  margin-left: -8px;
  margin-right: -8px;
}

.schedule-row-link:hover {
  background: rgba(255, 255, 255, 0.04);
}

.danger-text {
  color: var(--error) !important;
  border-color: var(--error) !important;
}

code {
  font-size: 0.8rem;
  word-break: break-all;
}
