/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1E88E5;
  --primary-light: #42A5F5;
  --accent: #26C6DA;
  --gradient: linear-gradient(135deg, #1E88E5, #26C6DA);
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #2c3e50;
  --text-secondary: #7f8c8d;
  --border: #e8ecf1;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ===== Pages ===== */
.page { display: none; height: 100%; }
.page.active { display: flex; flex-direction: column; }

/* ===== Login ===== */
#login-page {
  justify-content: center;
  align-items: center;
  background: var(--gradient);
  padding: 24px;
}
.login-container { width: 100%; max-width: 360px; }
.login-logo {
  text-align: center;
  margin-bottom: 40px;
  color: #fff;
}
.logo-icon {
  width: 64px; height: 64px;
  background: rgba(255,255,255,0.2);
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  backdrop-filter: blur(8px);
}
.login-logo h1 { font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.login-logo p { font-size: 14px; opacity: 0.85; }

.login-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.form-group { margin-bottom: 16px; }
.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-group input:focus { border-color: var(--primary); }
.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--gradient); color: #fff; }
.btn-primary:active { opacity: 0.9; }
.btn-block { width: 100%; padding: 14px; font-size: 17px; }
.btn-sm { padding: 10px 20px; font-size: 14px; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  font-size: 22px;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 20px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-header h2 { font-size: 18px; font-weight: 700; }

/* ===== Content ===== */
.app-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 80px;
}

.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 4px; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr !important;
  gap: 14px;
  margin-bottom: 4px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px 18px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}
.stat-card:active {
  transform: scale(0.97);
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient);
  opacity: 0.7;
}
.stat-icon {
  font-size: 22px;
  margin-bottom: 6px;
  display: block;
}
.stat-number {
  font-size: 30px;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
}
.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
  font-weight: 500;
}

/* ===== Platform Cards ===== */
.platform-cards { display: flex; flex-direction: column; gap: 10px; }
.platform-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.platform-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
}
.platform-icon.wechat { background: #07c160; }
.platform-icon.xiaohongshu { background: #fe2c55; }
.platform-icon.douyin { background: #161823; }
.platform-icon.shipinhao { background: #07c160; }
.platform-icon.weibo { background: #e6162d; }
.platform-icon.zhihu { background: #0066ff; }
.platform-icon.bilibili { background: #fb7299; }

.platform-info { flex: 1; min-width: 0; }
.platform-info h4 { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.platform-info p { font-size: 12px; color: var(--text-secondary); }

.platform-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
}
.status-unauthorized { background: #f8d7da; color: #721c24; }
.status-authorizing { background: #fff3cd; color: #856404; }
.status-authorized { background: #d4edda; color: #155724; }
/* Legacy aliases */
.status-unconfigured { background: #f8d7da; color: #721c24; }
.status-configured { background: #fff3cd; color: #856404; }
.status-expired { background: #fff3cd; color: #856404; }
.status-auth_failed { background: #f8d7da; color: #721c24; }

/* ===== Content List ===== */
.content-list { display: flex; flex-direction: column; gap: 10px; }
.content-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.content-item h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.content-item .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.tag-draft { background: #f0f0f0; color: #999; }
.tag-published { background: #d4edda; color: #155724; }
.tag-pending { background: #fff3cd; color: #856404; }
.tag-publishing { background: #cce5ff; color: #004085; }
.tag-partial { background: #f8d7da; color: #721c24; }
.tag-failed { background: #f8d7da; color: #721c24; }

.content-item .actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.content-item .actions .btn {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 8px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ===== Platform Manage Cards ===== */
.platform-manage-cards { display: flex; flex-direction: column; gap: 12px; }
.pm-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.pm-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.pm-card-header h4 { flex: 1; font-size: 16px; font-weight: 600; }
.pm-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.pm-field:last-child { border-bottom: none; }
.pm-field .label { color: var(--text-secondary); min-width: 80px; }
.pm-field .value { font-weight: 500; text-align: right; flex: 1; margin-left: 12px; word-break: break-all; }
.pm-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ===== Action Bar ===== */
.action-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 6px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 11px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.tab-item svg { margin-bottom: 3px; }
.tab-item.active { color: var(--primary); }
.tab-item.active svg { stroke: var(--primary); }

/* ===== Modal ===== */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== Form Elements ===== */
.form-field { margin-bottom: 16px; }
.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  background: #fff;
}
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--primary);
}
.form-field textarea { min-height: 120px; resize: vertical; }
.form-field .checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.form-field .checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.form-field .checkbox-group label.checked {
  border-color: var(--primary);
  background: rgba(30,136,229,0.08);
  color: var(--primary);
}
.form-field .checkbox-group input[type="checkbox"] { display: none; }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.form-actions .btn { flex: 1; padding: 13px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 32px;
  color: var(--text-secondary);
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (min-width: 500px) {
  .app-content { padding: 20px 24px 80px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ===== 弧光AI 聊天视图 ===== */
#view-arc-ai.active {
  display: flex;
  flex-direction: column;
}
#view-arc-ai #chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: var(--bg);
}
#view-arc-ai #chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#view-arc-ai #chat-input-area {
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--card);
  display: flex;
  gap: 10px;
  align-items: center;
}
#view-arc-ai #chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
#view-arc-ai #chat-input:focus {
  border-color: var(--primary);
}
#view-arc-ai #chat-send {
  padding: 10px 18px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
#view-arc-ai #chat-send:active {
  opacity: 0.8;
}
