/* ═══════════════════════════════════════
   Unified Hub Platform — Design System
   ═══════════════════════════════════════ */

:root {
  /* Ads Hub — Green/Gold theme */
  --ads-primary: #10b981;
  --ads-primary-dark: #059669;
  --ads-accent: #f59e0b;
  --ads-gradient: linear-gradient(135deg, #10b981, #059669);
  --ads-glow: rgba(16, 185, 129, 0.15);

  /* Social Hub — Purple theme */
  --social-primary: #8b5cf6;
  --social-primary-dark: #7c3aed;
  --social-accent: #ec4899;
  --social-gradient: linear-gradient(135deg, #8b5cf6, #7c3aed);
  --social-glow: rgba(139, 92, 246, 0.15);

  /* Active theme (default: ads) */
  --primary: var(--ads-primary);
  --primary-dark: var(--ads-primary-dark);
  --accent: var(--ads-accent);
  --gradient: var(--ads-gradient);
  --glow: var(--ads-glow);

  /* Neutral */
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #21242f;
  --bg-sidebar: #13151d;
  --border: #2a2d3a;
  --border-light: #333648;
  --text: #e4e6f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5a5e72;

  /* Status */
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --radius: 10px;
  --radius-sm: 6px;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ═══ SIDEBAR ═══════════════════════════ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.hub-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--glow);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  margin-bottom: 10px;
  transition: all 0.3s ease;
}

.hub-icon {
  font-size: 20px;
}

.hub-switcher select {
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  flex: 1;
  font-family: inherit;
}

.hub-switcher select option {
  background: var(--bg-card);
  color: var(--text);
}

.biz-switcher select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.biz-switcher select:hover { border-color: var(--primary); }

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  position: relative;
}

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

.nav-item.active {
  background: var(--glow);
  color: var(--primary);
  font-weight: 500;
}

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

.nav-icon { font-size: 16px; width: 22px; text-align: center; }

.nav-section {
  padding: 8px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  user-select: none;
  list-style: none; /* Hide default triangle */
}

/* Hide default marker in WebKit */
.nav-section::-webkit-details-marker {
  display: none;
}

#navPlatformDetails > summary.nav-section::after {
  content: '▼';
  font-size: 8px;
  margin-left: auto;
  transition: transform 0.2s ease;
  transform: rotate(-90deg);
}

#navPlatformDetails[open] > summary.nav-section::after {
  transform: rotate(0deg);
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 10px;
}

.badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: auto;
  font-weight: 600;
}

.badge.warning { background: var(--warning); }

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

.lang-switcher {
  margin-bottom: 8px;
}

.lang-switcher select,
.settings-select {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.lang-switcher select:hover,
.settings-select:hover {
  border-color: var(--primary);
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ═══ MAIN CONTENT ══════════════════════ */

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.top-bar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar h1 {
  font-size: 18px;
  font-weight: 600;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-range-switcher select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s;
}

.date-range-switcher select:hover {
  border-color: var(--primary);
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.btn-icon:hover {
  border-color: var(--primary);
  background: var(--glow);
}

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

/* ═══ PAGES ═════════════════════════════ */

.page {
  padding: 20px 24px;
  animation: fadeIn 0.3s ease;
}

.hidden { display: none !important; }
.page.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══ STAT CARDS ════════════════════════ */

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: all 0.25s ease;
  cursor: default;
}

.stat-card:hover {
  border-color: var(--primary);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-change {
  font-size: 12px;
  margin-top: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ═══ AI INSIGHT CARD ═══════════════════ */

.ai-insight-card {
  background: var(--bg-card);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px var(--glow);
  animation: fadeIn 0.5s ease;
}

.ai-insight-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient);
}

.ai-insight-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.ai-icon {
  font-size: 16px;
  animation: pulse 2s infinite;
}

.ai-insight-header strong {
  font-size: 14px;
  color: var(--primary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

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

.ai-insight-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.ai-insight-line::before {
  content: '👉';
  font-size: 12px;
}

/* ═══ CARDS ═════════════════════════════ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

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

.card-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-placeholder {
  padding: 20px;
  height: 200px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.mini-chart {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, var(--glow) 0%, transparent 100%);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.mini-chart::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
}

/* ═══ TABLE ═════════════════════════════ */

.table-container { overflow-x: auto; }

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

th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

tr:hover td { background: var(--bg-card-hover); }

.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

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

/* ═══ BUTTONS ═══════════════════════════ */

.btn-sm {
  padding: 5px 14px;
  font-size: 12px;
  background: var(--glow);
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-sm:hover {
  background: var(--primary);
  color: white;
}

/* ═══ UTILITIES ═════════════════════════ */

/* ── Action Queue ──────────────────────── */
.queue-group {
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.queue-group:last-child {
  border-bottom: none;
}
.queue-group-header {
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  list-style: none; /* Hide default triangle */
  display: flex;
  align-items: center;
  user-select: none;
  transition: background 0.2s;
}
.queue-group-header::-webkit-details-marker {
  display: none; /* Hide default triangle in WebKit */
}
.queue-group-header:hover {
  background: rgba(255, 255, 255, 0.05);
}
.queue-group-header::before {
  content: '▶';
  display: inline-block;
  font-size: 10px;
  margin-right: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
details[open].queue-group > .queue-group-header::before {
  transform: rotate(90deg);
}
.queue-group-badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 8px;
  font-weight: bold;
}
.queue-group-content {
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--border);
}

.action-item {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 16px 42px; /* Extra left padding for indentation */
  transition: all 0.2s;
}
.action-item:last-child {
  border-bottom: none;
}

/* ── Post Cards (Media Hub) ────────────── */
.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.post-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.post-card-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.post-card-content {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.post-card-metrics {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.action-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.action-title {
  flex: 1;
  font-size: 14px;
}

.action-title strong {
  color: var(--text);
  font-weight: 600;
}

.action-title .meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.action-details {
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  overflow-x: auto;
  border: 1px solid var(--border-light);
}

.action-details pre {
  margin: 0;
  font-family: monospace;
}

.action-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}


.empty-state {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.protection-rule {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.protection-rule:last-child { border-bottom: none; }

.rule-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.anomaly-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.anomaly-level {
  font-size: 18px;
}

.anomaly-info { flex: 1; }
.anomaly-info .desc { color: var(--text); }
.anomaly-info .meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

.module-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  cursor: pointer;
}

.module-nav-item:hover {
  background: var(--bg-card);
  color: var(--text);
}

.module-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: auto;
}

.module-status-dot.active { background: var(--success); }
.module-status-dot.loaded { background: var(--primary); }
.module-status-dot.error { background: var(--danger); }

/* Platform Brand Icon (圓形背景 + FA 白色圖示) */
.nav-platform-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.module-nav-item:hover .nav-platform-icon {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.module-nav-label {
  flex: 1;
  font-size: 13px;
}

/* ═══ SOCIAL HUB THEME ═════════════════ */

body.social-hub {
  --primary: var(--social-primary);
  --primary-dark: var(--social-primary-dark);
  --accent: var(--social-accent);
  --gradient: var(--social-gradient);
  --glow: var(--social-glow);
}

/* ═══ CACHE STATUS BADGE ════════════════ */

.cache-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 20px;
  border-left: 3px solid transparent;
  flex-wrap: wrap;
}

.cache-badge--ok {
  background: rgba(16, 185, 129, 0.08);
  border-left-color: var(--success);
  color: var(--text);
}

.cache-badge--warn {
  background: rgba(245, 158, 11, 0.1);
  border-left-color: var(--warning);
  color: var(--warning);
}

.cache-badge--live {
  background: rgba(139, 92, 246, 0.08);
  border-left-color: var(--primary);
  color: var(--text-secondary);
}

.cache-badge--info {
  background: rgba(59, 130, 246, 0.08);
  border-left-color: #3b82f6;
  color: var(--text-secondary);
}

.cache-mode {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ═══ SETTINGS ═════════════════════════ */

.settings-group {
  padding: 16px 20px;
}

.settings-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.settings-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--primary);
}

/* ═══ SOCIAL HUB SCHEDULER ════════════ */

.scheduler-container {
  display: flex;
  gap: 20px;
  padding: 20px;
}

.calendar-grid {
  flex: 3;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.calendar-day {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  min-height: 100px;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.calendar-day.empty {
  background: transparent;
  border-color: transparent;
}

.calendar-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-align: right;
}

.calendar-event {
  background: var(--glow);
  border-left: 3px solid var(--primary);
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.draft-panel {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.draft-panel h4 {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
}

.draft-item {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 12px;
  cursor: grab;
  transition: border-color 0.2s;
}

.draft-item:hover {
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.settings-select {
  padding: 6px 10px;
  background: var(--bg-body);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  outline: none;
}

.settings-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-body);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: monospace;
  font-size: 13px;
  transition: border-color 0.2s;
}

.settings-input:focus {
  border-color: var(--primary);
}

/* =========================================
   Tabs Layout
   ========================================= */
.settings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.settings-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.settings-tab-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}

.settings-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.settings-tab-pane {
  display: none;
  animation: fadeIn 0.3s ease;
}

.settings-tab-pane.active {
  display: block;
}

/* =========================================
   Login Protocol
   ========================================= */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  background: rgba(9, 9, 11, 0.95);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s;
}

.login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  padding: 32px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  transform: translateY(0);
  animation: floatUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes floatUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
