:root {
  --main: #ff4848; --main-dark: #e03030; --main-light: rgba(255,72,72,0.10);
  --accent: #3c5a98; --accent-light: rgba(60,90,152,0.10);
  --dark: #595967; --bg: #fafafa; --bg2: #e2e2e2; --card: #ffffff;
  --border: #e2e2e2; --text: #7b7b7b; --title: #000000;
  --sidebar-w: 230px; --radius: 8px; --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --success: #27ae60; --warning: #f39c12; --danger: #e03030;
}

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

body {
  font-family: 'Fira Sans', sans-serif; font-size: 13px;
  background: var(--bg); color: var(--text);
  display: flex; height: 100vh; overflow: hidden;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg2); border-radius: 10px; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto; box-shadow: 2px 0 8px rgba(0,0,0,0.04);
}

.sidebar-logo {
  padding: 18px 18px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}

.logo-icon {
  width: 34px; height: 34px; background: var(--main); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px; flex-shrink: 0;
}

.logo-text { font-weight: 700; font-size: 15px; color: var(--title); line-height: 1.2; }
.logo-sub { font-size: 10px; color: var(--text); margin-top: 1px; }

.sidebar-blog {
  padding: 12px 16px; background: var(--bg);
  border-bottom: 1px solid var(--border); cursor: pointer;
}

.blog-selector-label {
  font-size: 10px; color: var(--text);
  text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 4px;
}

.blog-name-display {
  font-size: 12px; font-weight: 600; color: var(--title);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}

.blog-name-display i { color: var(--main); font-size: 10px; }

.nav-section-label {
  padding: 14px 16px 4px; font-size: 10px; font-weight: 600;
  color: var(--text); text-transform: uppercase; letter-spacing: 1px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; color: var(--text);
  font-size: 13px; transition: all 0.15s; position: relative;
}

.nav-item:hover { background: var(--bg); color: var(--title); }

.nav-item.active {
  background: var(--main-light); color: var(--main); font-weight: 600;
}

.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--main);
}

.nav-item i { width: 16px; text-align: center; font-size: 13px; }

.nav-badge {
  margin-left: auto; background: var(--main); color: white;
  font-size: 10px; font-weight: 700; padding: 1px 7px;
  border-radius: 20px; min-width: 20px; text-align: center;
}

.nav-badge.blue { background: var(--accent); }
.nav-badge.green { background: var(--success); }

.sidebar-footer {
  margin-top: auto; padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.user-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
}

.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--main);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white;
  flex-shrink: 0; overflow: hidden;
}

.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-info { flex: 1; min-width: 0; }

.user-name {
  font-size: 12px; font-weight: 600; color: var(--title);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-email {
  font-size: 10px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.logout-btn { color: var(--text); cursor: pointer; font-size: 13px; }
.logout-btn:hover { color: var(--main); }

/* ===== MAIN ===== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ===== TOPBAR ===== */
.topbar {
  height: 52px; background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 22px; gap: 12px;
  flex-shrink: 0; box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.topbar-title {
  font-size: 16px; font-weight: 700; color: var(--title); flex: 1;
}

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

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 5px;
  font-size: 12px; font-family: 'Fira Sans', sans-serif;
  cursor: pointer; border: none; font-weight: 500;
  transition: all 0.15s; text-decoration: none;
}

.btn-primary { background: var(--main); color: white; }
.btn-primary:hover { background: var(--main-dark); }
.btn-outline { background: transparent; color: var(--main); border: 1px solid var(--main); }
.btn-outline:hover { background: var(--main-light); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--title); border-color: #ccc; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(224,48,48,0.3); }
.btn-danger:hover { background: rgba(224,48,48,0.08); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #229954; }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: #2e4880; }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ===== CONTENT ===== */
.content { flex: 1; overflow-y: auto; padding: 22px; }

/* ===== PANEL ===== */
.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== CARDS ===== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}

.card-title { font-size: 14px; font-weight: 700; color: var(--title); }
.card-body { padding: 16px 18px; }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 22px;
}

.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}

.stat-card::after {
  content: ''; position: absolute; right: -10px; top: -10px;
  width: 60px; height: 60px; border-radius: 50%; opacity: 0.06;
}

.stat-card.s1::after { background: var(--main); }
.stat-card.s2::after { background: var(--accent); }
.stat-card.s3::after { background: var(--success); }
.stat-card.s4::after { background: var(--warning); }

.stat-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; margin-bottom: 12px;
}

.stat-card.s1 .stat-icon { background: var(--main-light); color: var(--main); }
.stat-card.s2 .stat-icon { background: var(--accent-light); color: var(--accent); }
.stat-card.s3 .stat-icon { background: rgba(39,174,96,0.1); color: var(--success); }
.stat-card.s4 .stat-icon { background: rgba(243,156,18,0.1); color: var(--warning); }

.stat-value {
  font-size: 26px; font-weight: 700; color: var(--title); margin-bottom: 3px;
}

.stat-label { font-size: 11px; color: var(--text); }

/* ===== TABLE ===== */
.table-wrap {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--bg); padding: 11px 14px;
  font-size: 11px; font-weight: 600; color: var(--text);
  text-align: left; text-transform: uppercase; letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

.row-actions { display: flex; gap: 5px; }

/* ===== TAGS ===== */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}

.tag-pub { background: rgba(39,174,96,0.12); color: var(--success); }
.tag-draft { background: rgba(243,156,18,0.12); color: var(--warning); }
.tag-sched { background: var(--accent-light); color: var(--accent); }
.tag-spam { background: rgba(224,48,48,0.12); color: var(--danger); }

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; flex-wrap: wrap;
}

.search-wrap { position: relative; flex: 1; min-width: 200px; }

.search-wrap i {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: var(--text); font-size: 12px;
}

.search-input {
  width: 100%; background: var(--card);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 8px 12px 8px 32px; font-size: 13px;
  font-family: 'Fira Sans', sans-serif;
  color: var(--title); outline: none;
}

.search-input:focus { border-color: var(--main); }
.search-input::placeholder { color: var(--text); }

.filter-btn {
  padding: 7px 12px; border-radius: 5px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; cursor: pointer;
  font-family: 'Fira Sans', sans-serif; transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--main); color: var(--main); }

.filter-btn.active {
  background: var(--main-light); border-color: var(--main);
  color: var(--main); font-weight: 600;
}

/* ===== FORM CONTROLS ===== */
.form-group {
  display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px;
}

.form-label {
  font-size: 11px; font-weight: 600; color: var(--dark);
  text-transform: uppercase; letter-spacing: 0.6px;
}

.form-input, .form-select, .form-textarea {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 5px; padding: 8px 12px; color: var(--title);
  font-size: 13px; font-family: 'Fira Sans', sans-serif;
  outline: none; width: 100%; transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--main);
}

.form-textarea { resize: vertical; min-height: 80px; }

/* ===== TOGGLE ===== */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }
.toggle-row label { font-size: 13px; color: var(--title); }

.toggle {
  width: 38px; height: 22px; background: var(--bg2);
  border-radius: 11px; position: relative; cursor: pointer;
  transition: background 0.2s; flex-shrink: 0;
}

.toggle.on { background: var(--main); }

.toggle::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  background: white; border-radius: 50%; top: 3px; left: 3px;
  transition: left 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle.on::after { left: 19px; }

/* ===== LOADING / EMPTY ===== */
.loading-wrap, .empty-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px; color: var(--text);
}

.loading-wrap i {
  font-size: 32px; color: var(--main); margin-bottom: 12px;
  animation: spin 1s linear infinite;
}

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

.empty-wrap i { font-size: 36px; color: var(--bg2); margin-bottom: 12px; }
.empty-wrap p { font-size: 14px; }

/* ===== SETUP SCREEN ===== */
#setup-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}

.setup-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px; width: 480px;
  box-shadow: var(--shadow-md); text-align: center;
}

.setup-logo {
  width: 60px; height: 60px; background: var(--main);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: white; margin: 0 auto 20px;
}

.setup-title {
  font-size: 22px; font-weight: 700; color: var(--title); margin-bottom: 8px;
}

.setup-desc {
  font-size: 13px; color: var(--text); line-height: 1.7; margin-bottom: 24px;
}

.setup-input-wrap { text-align: left; margin-bottom: 16px; }
.setup-divider {
  display: flex; align-items: center; gap: 10px; margin: 20px 0;
}

.setup-divider::before, .setup-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.setup-divider span { font-size: 11px; color: var(--text); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center; z-index: 10000;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--card); border-radius: 12px;
  width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 15px; font-weight: 700; color: var(--title); }

.modal-close {
  cursor: pointer; color: var(--text); font-size: 18px;
}

.modal-close:hover { color: var(--title); }

.modal-body { padding: 20px; }

.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ===== TOAST ===== */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--dark); color: white;
  padding: 12px 18px; border-radius: 8px; font-size: 13px;
  z-index: 99999; display: none; align-items: center; gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); max-width: 320px;
}

#toast i { font-size: 15px; flex-shrink: 0; }
#toast.show { display: flex; animation: toastIn 0.3s ease; }
#toast.success i { color: #2ecc71; }
#toast.error i { color: var(--main); }
#toast.info i { color: #3498db; }

@keyframes toastIn {
  from { opacity:0; transform: translateY(10px); }
  to { opacity:1; transform: none; }
}

/* ===== AI CONTENT GENERATOR ===== */
.ai-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  color: white;
}

.ai-section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-section-desc {
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 15px;
}

.ai-input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.ai-input {
  flex: 1;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  padding: 10px 14px;
  color: white;
  font-size: 14px;
  font-family: 'Fira Sans', sans-serif;
}

.ai-input::placeholder { color: rgba(255,255,255,0.7); }

.ai-input:focus {
  outline: none;
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.5);
}

.ai-result {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 15px;
  color: var(--title);
  display: none;
}

.ai-result.show { display: block; }

.ai-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.ai-result-title { font-size: 14px; font-weight: 600; color: var(--title); }

.ai-result-content { font-size: 13px; line-height: 1.8; color: var(--text); }

/* ===== AD PROTECTION ===== */
.protection-section { margin-bottom: 20px; }

.protection-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.protection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.protection-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--title);
  display: flex;
  align-items: center;
  gap: 8px;
}

.protection-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.protection-badge.active { background: rgba(39,174,96,0.12); color: var(--success); }
.protection-badge.inactive { background: rgba(150,150,150,0.12); color: #999; }

.ip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.ip-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--main-light);
  color: var(--main);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.ip-tag .remove-ip { cursor: pointer; opacity: 0.7; transition: opacity 0.2s; }
.ip-tag .remove-ip:hover { opacity: 1; }

.country-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-light);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.log-table { width: 100%; margin-top: 15px; }

.log-table th {
  background: var(--bg);
  padding: 8px 12px;
  font-size: 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.log-table td {
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.log-table tr:last-child td { border-bottom: none; }
.log-expired { opacity: 0.5; }

/* ==================== EDITOR LAYOUT ==================== */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  transition: grid-template-columns 0.3s ease;
}
.editor-layout.ai-open {
  grid-template-columns: 1fr 320px;
}
.editor-main { min-width: 0; }

/* AI Panel */
.editor-ai-panel {
  display: none;
  flex-direction: column;
}
.editor-ai-panel.visible {
  display: flex;
}
.ai-panel-inner {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: sticky;
  top: 0;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
}
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--main);
  color: white;
  font-size: 13px;
  font-weight: 600;
}
.ai-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.ai-tab {
  flex: 1;
  padding: 9px 4px;
  border: none;
  background: none;
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.ai-tab:hover { color: var(--main); }
.ai-tab.active { color: var(--main); border-bottom-color: var(--main); font-weight: 600; background: white; }
.ai-tab-content { display: none; padding: 14px; overflow-y: auto; flex: 1; }
.ai-tab-content.active { display: block; }
.ai-panel-preview {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 12px;
  color: var(--title);
  max-height: 280px;
  overflow-y: auto;
  line-height: 1.6;
}
.ai-panel-preview h2, .ai-panel-preview h3 { font-size: 13px; margin: 8px 0 4px; color: var(--main); }
.ai-panel-preview p { margin: 0 0 6px; }
.ai-panel-preview ul { padding-left: 16px; margin: 4px 0; }

/* Progress */
.ai-progress-wrap { padding: 10px 0; }
.ai-progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.ai-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--main), var(--accent));
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}
.ai-progress-indeterminate {
  width: 40% !important;
  animation: indeterminate 1.5s ease infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-200%); }
  100% { transform: translateX(350%); }
}
.ai-progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text);
  margin-top: 4px;
}

/* Settings key visibility */
.form-row { display: flex; gap: 12px; }

/* API status */
#set-api-status.success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
#set-api-status.error { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }

/* AI result actions in panel */
.ai-result-actions { display: flex; flex-direction: column; gap: 4px; }

