:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;
  --muted: #6b7280;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Login */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 400px;
  text-align: center;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.login-card p { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card input {
  width: 100%; padding: 0.75rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; margin-bottom: 1rem;
  outline: none; transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--primary); }
.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex; align-items: center; gap: 2rem;
  position: sticky; top: 0; z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 0.5rem; }
.header-left h1 { font-size: 1.1rem; font-weight: 700; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
}
.status-dot.online { background: var(--success); }
nav { display: flex; gap: 0.25rem; flex: 1; }
.nav-link {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.9rem; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary); color: white; }

/* Buttons */
.btn {
  padding: 0.6rem 1.25rem;
  border: none; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-outline {
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }

/* Main */
main { max-width: 960px; margin: 0 auto; padding: 1rem 1.5rem; }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.badge-published { background: #dcfce7; color: #166534; }
.badge-failed, .badge-partial_failed { background: #fef2f2; color: #991b1b; }
.badge-queued, .badge-publishing { background: #fef9c3; color: #854d0e; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-validated, .badge-draft { background: #f1f5f9; color: #475569; }
.badge-cancelled { background: #f1f5f9; color: #6b7280; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.6rem 0.75rem; color: var(--text-secondary); font-weight: 500; border-bottom: 2px solid var(--border); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td { padding: 0.75rem; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8fafc; }
tr.clickable { cursor: pointer; }

/* Platform icons */
.platform-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem; font-weight: 500;
  background: #f1f5f9;
}
.platform-tag.facebook { background: #dbeafe; color: #1e40af; }
.platform-tag.twitter { background: #e0f2fe; color: #0369a1; }
.platform-tag.tiktok { background: #fce7f3; color: #9d174d; }
.platform-tag.youtube { background: #fef2f2; color: #991b1b; }
.platform-tag.telegram { background: #ccfbf1; color: #115e59; }

/* Form */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem; color: var(--text-secondary); }
.form-group textarea, .form-group input, .form-group select {
  width: 100%; padding: 0.65rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.9rem; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.form-group textarea:focus, .form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 100px; }
.char-count { font-size: 0.75rem; color: var(--text-secondary); text-align: right; margin-top: 0.25rem; }

/* Checkboxes */
.channel-list { display: flex; flex-direction: column; gap: 0.5rem; }
.channel-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: border-color 0.15s;
}
.channel-item:hover { border-color: var(--primary); }
.channel-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.channel-info { flex: 1; }
.channel-info .name { font-weight: 500; font-size: 0.9rem; }
.channel-info .id { font-size: 0.75rem; color: var(--text-secondary); }

/* Detail page */
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.detail-meta { display: flex; gap: 2rem; flex-wrap: wrap; margin-top: 0.75rem; }
.detail-meta .meta-item { font-size: 0.85rem; }
.detail-meta .meta-label { color: var(--text-secondary); font-size: 0.75rem; }

.target-card {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 0.5rem;
}
.target-card .target-info { flex: 1; }

/* Logs timeline */
.log-entry {
  display: flex; gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.log-entry:last-child { border-bottom: none; }
.log-time { color: var(--text-secondary); white-space: nowrap; font-size: 0.8rem; min-width: 80px; }
.log-action { font-weight: 500; }

/* Summary cards */
.summary-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.summary-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem;
  text-align: center;
}
.summary-card .count { font-size: 1.75rem; font-weight: 700; }
.summary-card .label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }

/* Pagination */
.pagination {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1rem; font-size: 0.85rem; color: var(--text-secondary);
}

/* Toast */
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  color: white; font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease-out;
  max-width: 360px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Empty state */
.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-secondary);
}
.empty-state p { font-size: 0.95rem; }

/* Loading */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center { display: flex; justify-content: center; padding: 3rem; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 150;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  max-width: 420px; width: 90%;
}
.modal h3 { margin-bottom: 0.75rem; }
.modal p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* Pages management */
.pages-list { display: flex; flex-direction: column; gap: 0.75rem; }
.page-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.page-card:hover { border-color: var(--primary); }
.page-card.page-inactive { opacity: 0.6; background: #fafafa; }
.page-card-left { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.page-card-info { flex: 1; min-width: 0; }
.page-card-name { font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem; }
.page-card-id { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; font-family: monospace; }
.page-card-token { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; font-family: monospace; }
.page-card-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.page-card .channel-avatar { width: 40px; height: 40px; }

/* Channel avatar */
.channel-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.channel-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.channel-name { font-weight: 500; font-size: 0.85rem; }

/* Caption block in detail view */
.caption-block {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  border-left: 3px solid var(--primary);
}

/* Upload drop zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafbfc;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.upload-zone.has-file {
  border-color: var(--success);
  border-style: solid;
  background: #f0fdf4;
  padding: 1rem;
}
.upload-zone-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.upload-zone-text { font-size: 0.85rem; color: var(--text-secondary); }
.upload-zone-text strong { color: var(--primary); }
.upload-zone-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.upload-preview {
  display: flex; align-items: center; gap: 1rem; text-align: left;
}
.upload-preview-thumb {
  width: 64px; height: 64px; border-radius: 6px;
  object-fit: cover; background: var(--bg); flex-shrink: 0;
}
.upload-preview-thumb.video-thumb {
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; background: #1e293b; color: white;
}
.upload-preview-info { flex: 1; min-width: 0; }
.upload-preview-name { font-weight: 600; font-size: 0.85rem; word-break: break-all; }
.upload-preview-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }
.upload-preview-status { font-size: 0.8rem; margin-top: 0.25rem; }

.upload-progress {
  height: 4px; border-radius: 2px; background: var(--border);
  margin-top: 0.5rem; overflow: hidden;
}
.upload-progress-bar {
  height: 100%; background: var(--primary); border-radius: 2px;
  transition: width 0.3s;
}

/* Import pages */
.import-section {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  background: #f8fafc;
}
.import-section.active { border-color: var(--primary); background: #eff6ff; }
.import-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.import-header h3 { font-size: 0.95rem; font-weight: 600; }
.import-header .step-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
}
.import-header .step-num.done { background: var(--success); }

.import-pages-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.import-page-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.15s;
}
.import-page-item:hover { border-color: var(--primary); }
.import-page-item.already-added { opacity: 0.5; background: #fafafa; }
.import-page-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex-shrink: 0; }
.import-page-info { flex: 1; min-width: 0; }
.import-page-name { font-weight: 600; font-size: 0.9rem; }
.import-page-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.1rem; }
.import-page-perms { display: flex; gap: 0.35rem; flex-wrap: wrap; flex-shrink: 0; }

.perm-badge {
  display: inline-block; padding: 0.15rem 0.5rem;
  border-radius: 4px; font-size: 0.7rem; font-weight: 600;
}
.perm-badge.ok { background: #dcfce7; color: #166534; }
.perm-badge.missing { background: #fef2f2; color: #991b1b; }
.perm-badge.info { background: #dbeafe; color: #1e40af; }

.import-summary {
  margin-top: 1rem; padding: 0.75rem 1rem;
  background: var(--surface); border-radius: var(--radius);
  font-size: 0.85rem; border: 1px solid var(--border);
}

/* Create publish layout — single screen, 2-column */
.create-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: 1fr auto;
  gap: 0 1rem;
  height: calc(100vh - 56px - 3rem); /* viewport minus header minus padding */
  max-height: calc(100vh - 56px - 3rem);
}
.create-content {
  grid-column: 1;
  grid-row: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
}
.create-channels {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.channel-list-scroll {
  flex: 1;
  overflow-y: auto;
  max-height: none;
  padding-right: 0.25rem;
}
.create-footer {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  bottom: 0;
}
.create-footer .btn-primary {
  padding: 0.65rem 2rem;
  font-size: 0.95rem;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .create-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    max-height: none;
  }
  .create-content { grid-column: 1; grid-row: 1; padding-right: 0; }
  .create-channels { grid-column: 1; grid-row: 2; }
  .channel-list-scroll { max-height: 200px; }
  .create-footer { grid-column: 1; grid-row: 3; position: sticky; bottom: 0; }
}
@media (max-width: 640px) {
  header { padding: 0 1rem; gap: 0.75rem; }
  main { padding: 1rem; }
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .detail-meta { gap: 1rem; }
  table { font-size: 0.8rem; }
  td, th { padding: 0.5rem; }
}
