/* ===== Portal v3.0 — Dark Theme + Glassmorphism ===== */

/* Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Dark palette */
  --bg-primary: #0d0d0d;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --border-color: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);

  /* Text */
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --text-accent: var(--accent-color, #3b82f6);

  /* Accent (overridden per client) */
  --accent-color: #3b82f6;
  --accent-hover: color-mix(in srgb, var(--accent-color) 85%, white);
  --accent-glow: color-mix(in srgb, var(--accent-color) 30%, transparent);

  /* Status */
  --color-critical: #ef4444;
  --color-high: #f97316;
  --color-medium: #eab308;
  --color-low: #22c55e;
  --color-safe: #6b7280;

  /* Sizing */
  --sidebar-width: 240px;
  --header-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Glassmorphism */
  --glass-bg: rgba(255,255,255,0.05);
  --glass-border: rgba(255,255,255,0.08);
  --glass-blur: 12px;
}

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

html { font-size: 14px; }

body {
  font-family: 'Inter', 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--text-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ===== Login Page ===== */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.08) 0%, transparent 60%),
              var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 48px 40px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 36px;
  font-size: 0.9rem;
}

.login-card .brand {
  text-align: center;
  margin-bottom: 32px;
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ===== Form Elements ===== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
}

.btn-primary {
  width: 100%;
  background: var(--accent-color);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}

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

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.login-error {
  color: var(--color-critical);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 16px;
  min-height: 20px;
}

/* ===== Layout: Sidebar + Main ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

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

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

.sidebar-header .client-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-header .service-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
  text-decoration: none;
}

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

.nav-item .nav-icon {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

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

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.logout-btn:hover {
  background: rgba(239,68,68,0.1);
  color: var(--color-critical);
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 32px;
}

.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Glass Card ===== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: border-color 0.2s, transform 0.2s;
}

.glass-card:hover {
  border-color: var(--border-hover);
}

.glass-card .card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

/* ===== KPI Counters ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--kpi-color, var(--accent-color));
  opacity: 0.8;
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}

.kpi-unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}

.kpi-change {
  font-size: 0.8rem;
  margin-top: 8px;
  color: var(--text-muted);
}

.kpi-change.positive { color: var(--color-low); }
.kpi-change.negative { color: var(--color-critical); }

/* ===== AI Briefing Card ===== */
.ai-brief-card {
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.ai-brief-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-color), transparent);
}

.ai-brief-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.ai-brief-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ai-brief-badge.high { background: rgba(239,68,68,0.15); color: var(--color-critical); }
.ai-brief-badge.medium { background: rgba(234,179,8,0.15); color: var(--color-medium); }
.ai-brief-badge.low { background: rgba(34,197,94,0.15); color: var(--color-low); }

.ai-brief-summary {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.ai-brief-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.topic-tag {
  padding: 4px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.ai-brief-recommendation {
  padding: 12px 16px;
  background: rgba(255,255,255,0.03);
  border-left: 3px solid var(--accent-color);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.ai-brief-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 12px;
  text-align: right;
}

/* ===== Charts Grid ===== */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.chart-container {
  position: relative;
  height: 280px;
}

.chart-full {
  grid-column: 1 / -1;
}

.chart-container canvas {
  max-height: 100%;
}

/* ===== Data Table ===== */
.data-table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.data-table th {
  padding: 10px 8px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 8px;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-primary);
  white-space: nowrap;
}
.data-table td:nth-child(2) {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

/* ===== Status Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-critical { background: rgba(239,68,68,0.15); color: var(--color-critical); }
.badge-high { background: rgba(249,115,22,0.15); color: var(--color-high); }
.badge-medium { background: rgba(234,179,8,0.15); color: var(--color-medium); }
.badge-low { background: rgba(34,197,94,0.15); color: var(--color-low); }
.badge-safe { background: rgba(107,114,128,0.15); color: var(--color-safe); }

.badge-delete { background: rgba(239,68,68,0.15); color: var(--color-critical); }
.badge-review { background: rgba(234,179,8,0.15); color: var(--color-medium); }
.badge-exclude { background: rgba(107,114,128,0.15); color: var(--color-safe); }
.badge-pending { background: rgba(59,130,246,0.15); color: #3b82f6; }

.badge-submitted { background: rgba(34,197,94,0.15); color: var(--color-low); }
.badge-deleted { background: rgba(34,197,94,0.2); color: #4ade80; }
.badge-failed { background: rgba(239,68,68,0.15); color: var(--color-critical); }

/* ===== Platform Tags ===== */
.platform-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
}

.pagination button {
  padding: 8px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.pagination button:hover:not(:disabled) {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

.pagination button.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pagination .page-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0 8px;
}

/* ===== Filters Bar ===== */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  align-items: center;
}

.filter-select {
  padding: 8px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.filter-select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px 8px 36px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent-color);
}

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

.search-wrapper::before {
  content: '\1F50D';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

/* ===== Activity Feed ===== */
.activity-feed {
  max-height: 400px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-dot.scrape { background: #3b82f6; }
.activity-dot.submit { background: #22c55e; }
.activity-dot.alert { background: #ef4444; }

.activity-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== Skeleton Loading ===== */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text { height: 16px; margin-bottom: 8px; }
.skeleton-text.short { width: 60%; }
.skeleton-title { height: 24px; width: 40%; margin-bottom: 16px; }
.skeleton-block { height: 100px; }

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 0.9rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 300px;
  animation: toast-in 0.3s ease-out;
}

.toast.removing {
  animation: toast-out 0.3s ease-in forwards;
}

.toast-critical { border-left: 3px solid var(--color-critical); }
.toast-warning { border-left: 3px solid var(--color-medium); }
.toast-success { border-left: 3px solid var(--color-low); }
.toast-info { border-left: 3px solid var(--accent-color); }

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

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

/* ===== Brand Health Score ===== */
.health-score-ring {
  width: 120px;
  height: 120px;
  position: relative;
  margin: 0 auto 16px;
}

.health-score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.health-score-ring .ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.08);
  stroke-width: 8;
}

.health-score-ring .ring-fill {
  fill: none;
  stroke: var(--accent-color);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 1s ease-out;
}

.health-score-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.health-score-label {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* ===== AI Learning Page ===== */
.learning-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.learning-stat {
  text-align: center;
}

.learning-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
}

.learning-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 1rem;
}

/* ===== Brand Health AI Card ===== */
.brand-health-card {
  position: relative;
}

.brand-health-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.brand-health-header .card-title {
  margin-bottom: 0;
}

.brand-health-ai-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.brand-health-main {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 20px;
}

.brand-health-ring-wrap {
  flex-shrink: 0;
}

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

.brand-health-grade {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.brand-health-summary {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.brand-health-factors {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.factor-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.factor-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  width: 80px;
  flex-shrink: 0;
}

.factor-bar-bg {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.factor-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s ease-out;
}

.factor-value {
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

.brand-health-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 12px;
}

/* ===== Bottom Tab Bar (Mobile) ===== */
.bottom-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-tab-bar nav {
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-around;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
  min-width: 56px;
  -webkit-tap-highlight-color: transparent;
}

.tab-item:hover {
  text-decoration: none;
}

.tab-item .tab-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.tab-item.active {
  color: var(--accent-color);
}

.tab-item.active .tab-icon {
  transform: scale(1.1);
}

/* ===== Mobile Card List (replaces table) ===== */
.mobile-card-list {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.mobile-post-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: border-color 0.15s;
}

.mobile-post-card:active {
  border-color: var(--border-hover);
}

.mobile-post-card-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mobile-post-card-title a {
  color: var(--text-primary);
}

.mobile-post-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mobile-post-card-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ===== Responsive — Tablet ===== */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .learning-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Responsive — Mobile (768px) ===== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  html {
    font-size: 14px;
    /* iOS 안전 영역 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }

  body {
    /* 모바일 텍스트 선택 최적화 */
    -webkit-text-size-adjust: 100%;
    /* 모바일 스크롤 부드럽게 */
    -webkit-overflow-scrolling: touch;
  }

  /* Hide desktop sidebar */
  .sidebar {
    display: none !important;
  }

  /* Hide old mobile menu button */
  .mobile-menu-btn {
    display: none !important;
  }

  /* Show bottom tab bar */
  .bottom-tab-bar {
    display: block;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  /* Main content: no sidebar, add bottom padding for tab bar */
  .main-content {
    margin-left: 0;
    padding: 16px 16px calc(80px + env(safe-area-inset-bottom, 0px)) 16px;
  }

  .page-header {
    margin-bottom: 20px;
  }

  .page-title {
    font-size: 1.4rem;
  }

  .page-subtitle {
    font-size: 0.82rem;
  }

  /* KPI 2x2 grid — 인라인 3col도 모바일에서 2col */
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .kpi-card {
    padding: 14px 16px;
  }

  .kpi-value {
    font-size: 1.6rem;
  }

  .kpi-label {
    font-size: 0.75rem;
  }

  /* Glass cards full width */
  .glass-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  /* Charts stack vertically */
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .chart-container {
    height: 200px;
  }

  /* AI Brief card compact */
  .ai-brief-summary {
    font-size: 0.92rem;
    line-height: 1.6;
  }

  .ai-brief-recommendation {
    font-size: 0.82rem;
    padding: 10px 12px;
  }

  /* Brand health mobile */
  .brand-health-main {
    flex-direction: column;
    gap: 12px;
    align-items: center;
    text-align: center;
  }

  .health-score-ring {
    width: 100px;
    height: 100px;
    margin-bottom: 8px;
  }

  .health-score-value {
    font-size: 1.5rem;
  }

  .factor-label {
    width: 64px;
    font-size: 0.75rem;
  }

  /* Table → Card list on mobile */
  .data-table-wrapper,
  .data-table-wrap {
    display: none;
  }

  .mobile-card-list {
    display: flex;
  }

  /* Filters bar: 2열 그리드 + 검색 풀와이드 */
  .filters-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .filter-select {
    font-size: 0.8rem;
    padding: 10px 28px 10px 10px;
    min-height: 44px;
    width: 100%;
  }

  .search-wrapper {
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
  }

  .search-input {
    min-height: 44px;
    font-size: 0.85rem;
    width: 100%;
  }

  /* Pagination touch-friendly */
  .pagination {
    flex-wrap: wrap;
    padding-bottom: 8px;
  }

  .pagination button {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  /* Source toggle full width */
  #sourceToggle {
    display: flex;
    gap: 8px;
  }

  #sourceToggle .btn {
    flex: 1;
    min-height: 44px;
    justify-content: center;
  }

  /* Activity feed */
  .activity-feed {
    max-height: 300px;
  }

  .activity-item {
    padding: 10px 0;
  }

  /* Login card mobile */
  .login-card {
    margin: 16px;
    padding: 32px 24px;
  }

  .login-card h1 {
    font-size: 1.4rem;
  }

  /* Toast at bottom center (above tab bar) */
  .toast-container {
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    left: 16px;
    align-items: center;
  }

  .toast {
    min-width: auto;
    width: 100%;
    justify-content: center;
  }

  @keyframes toast-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(20px); }
  }

  /* Learning page */
  .learning-grid {
    grid-template-columns: 1fr;
  }

  /* Touch targets */
  .btn {
    min-height: 44px;
  }

  .nav-item {
    min-height: 44px;
  }

  /* Badges slightly bigger for touch */
  .badge {
    padding: 4px 10px;
    font-size: 0.72rem;
  }

  .platform-tag {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  /* ===== Pipeline: 모바일에서 세로 배치 ===== */
  .pipeline-flow {
    flex-direction: column;
    gap: 8px;
  }

  .pipeline-arrow {
    transform: rotate(90deg);
    font-size: 16px;
  }

  .pipeline-stage {
    width: 100%;
    padding: 12px 16px;
    min-width: 0;
  }

  .pipeline-stage-count {
    font-size: 22px;
  }

  .pipeline-decisions {
    gap: 12px;
  }

  .pipeline-decision {
    font-size: 15px;
  }

  /* ===== Posts 페이지: 상태 칩 가로 스크롤 ===== */
  .status-counts {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .status-counts::-webkit-scrollbar {
    display: none;
  }

  .status-chip {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
  }

  /* ===== Posts: 빠른 필터 가로 스크롤 ===== */
  .quick-filters {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .quick-filters::-webkit-scrollbar {
    display: none;
  }

  .quick-btn {
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 40px;
  }

  /* ===== Posts: 키보드 힌트 숨김 (터치 환경) ===== */
  .keyboard-hint {
    display: none !important;
  }

  /* ===== Posts: 배치 액션바 모바일 ===== */
  .batch-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .batch-bar .select-info {
    min-width: auto;
    font-size: 13px;
  }

  .batch-bar .btn {
    font-size: 0.8rem;
    padding: 8px 12px;
    flex: 1;
    min-width: 0;
  }

  /* ===== Posts: 제출 영역 모바일 ===== */
  .submit-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    bottom: 64px;
    margin-top: 8px;
  }

  .submit-summary {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .submit-summary > .submit-stat {
    display: inline;
    font-size: 13px;
  }

  .submit-summary > .submit-stat[style*="color:#666"] {
    display: none;
  }

  .submit-actions {
    margin-left: 0;
    flex-direction: column;
    gap: 8px;
  }

  .btn-submit {
    width: 100%;
    min-height: 48px;
    font-size: 15px;
  }

  /* ===== Posts: 프로그레스/확인 모달 모바일 ===== */
  .progress-box {
    width: calc(100vw - 32px);
    max-width: 480px;
    padding: 24px 20px;
    margin: 16px;
  }

  .progress-log {
    max-height: 150px;
    font-size: 11px;
  }

  /* ===== 모바일 포스트 카드 액션 영역 ===== */
  .mobile-post-card {
    position: relative;
  }

  .mobile-post-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.05);
  }

  .mobile-post-card-actions .action-btn {
    width: auto;
    height: auto;
    padding: 6px 14px;
    font-size: 12px;
    border-radius: 6px;
    gap: 4px;
  }

  /* ===== Whitelist: 추가 폼 모바일 (세로 스택) ===== */
  .add-whitelist-form {
    flex-direction: column;
  }

  .add-whitelist-form select,
  .add-whitelist-form input {
    width: 100%;
    min-height: 44px;
    font-size: 14px;
  }

  .add-whitelist-form .btn-add {
    min-height: 48px;
    font-size: 15px;
  }

  /* Whitelist 필터 버튼 터치 최적화 */
  .whitelist-filters {
    width: 100%;
  }

  .filter-btn {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 13px;
  }

  /* Whitelist 모바일 카드 */
  .whitelist-mobile-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
  }

  .whitelist-mobile-card + .whitelist-mobile-card {
    margin-top: 8px;
  }

  /* ===== Reports: iframe 모바일 높이 ===== */
  .report-iframe-wrapper iframe {
    height: 400px;
  }

  .report-item {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .report-view-btn {
    width: 100%;
    text-align: center;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ===== 관리자 클라이언트 선택 드롭다운 터치 최적화 ===== */
  .admin-selector select {
    min-height: 44px;
    font-size: 14px !important;
  }
}

/* ===== 모바일 관리자 클라이언트 선택기 (페이지 상단) ===== */
.mobile-admin-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
}

.mobile-admin-selector label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

.mobile-admin-selector select {
  flex: 1;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  min-height: 40px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.mobile-admin-selector select option {
  background: #1a1a1a;
  color: #fff;
}

/* ===== Responsive — Small Phone (375px) ===== */
@media (max-width: 400px) {
  .main-content {
    padding: 12px 12px calc(80px + env(safe-area-inset-bottom, 0px)) 12px;
  }

  .page-title {
    font-size: 1.25rem;
  }

  .kpi-value {
    font-size: 1.4rem;
  }

  .kpi-card {
    padding: 12px 14px;
  }

  .glass-card {
    padding: 14px;
  }

  .chart-container {
    height: 180px;
  }

  .ai-brief-summary {
    font-size: 0.85rem;
  }

  .mobile-post-card {
    padding: 12px 14px;
  }

  .mobile-post-card-title {
    font-size: 0.85rem;
  }

  .filter-select {
    font-size: 0.75rem;
  }

  /* 작은 화면: 탭바 아이콘/텍스트 축소 */
  .tab-item {
    font-size: 0.6rem;
    min-width: 48px;
    padding: 6px 8px;
  }

  .tab-item .tab-icon {
    font-size: 1.15rem;
  }

  /* 파이프라인 더 컴팩트 */
  .pipeline-stage-count {
    font-size: 18px;
  }

  .pipeline-stage {
    padding: 10px 12px;
  }

  /* 리포트 iframe 더 짧게 */
  .report-iframe-wrapper iframe {
    height: 300px;
  }
}

/* Hide old mobile menu on desktop */
.mobile-menu-btn {
  display: none;
}

/* Skeleton shimmer enhanced */
.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.03) 0%,
    rgba(255,255,255,0.08) 20%,
    rgba(255,255,255,0.03) 40%,
    rgba(255,255,255,0.03) 100%
  );
  background-size: 300% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 300% 0; }
  100% { background-position: -300% 0; }
}

/* Lazy load fade-in for charts */
.chart-lazy {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.chart-lazy.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ====== Pipeline Stats ====== */
.pipeline-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.pipeline-stage {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 16px 24px;
  text-align: center;
  min-width: 120px;
}
.pipeline-stage-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-color, #3b82f6);
  font-weight: 600;
  margin-bottom: 4px;
}
.pipeline-stage-desc {
  font-size: 11px;
  color: #666;
  margin-bottom: 8px;
}
.pipeline-stage-count {
  font-size: 28px;
  font-weight: 700;
  color: #f0f0f0;
}
.pipeline-arrow {
  font-size: 20px;
  color: #555;
}
.pipeline-decisions {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}
.pipeline-decision {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  color: #ccc;
}

/* ====== Whitelist Page ====== */
.whitelist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.whitelist-filters {
  display: flex;
  gap: 8px;
}
.filter-btn {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: #aaa;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.filter-btn:hover { border-color: rgba(255,255,255,0.2); color: #fff; }
.filter-btn.active {
  background: var(--accent-color, #3b82f6);
  border-color: var(--accent-color, #3b82f6);
  color: #fff;
}
.wl-type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.wl-type-blog_url { background: rgba(45,180,0,0.15); color: #2db400; }
.wl-type-author_id { background: rgba(59,130,246,0.15); color: #3b82f6; }
.wl-type-keyword_pattern { background: rgba(234,179,8,0.15); color: #eab308; }
.wl-type-domain { background: rgba(168,85,247,0.15); color: #a855f7; }
.wl-status-active { color: #22c55e; }
.wl-status-pending_review { color: #eab308; }
.wl-action-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.wl-action-btn.approve { background: rgba(34,197,94,0.2); color: #22c55e; }
.wl-action-btn.remove { background: rgba(239,68,68,0.2); color: #ef4444; }
.wl-action-btn:hover { opacity: 0.8; }

/* Add form */
.add-whitelist-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.add-whitelist-form select,
.add-whitelist-form input {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #e0e0e0;
  font-size: 13px;
}
.add-whitelist-form select:focus,
.add-whitelist-form input:focus {
  outline: none;
  border-color: var(--accent-color, #3b82f6);
}
.add-whitelist-form .btn-add {
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  background: var(--accent-color, #3b82f6);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.add-whitelist-form .btn-add:hover { opacity: 0.85; }

/* ====== Reports Page ====== */
.report-list {
  display: grid;
  gap: 12px;
}
.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  transition: background 0.2s;
}
.report-item:hover {
  background: rgba(255,255,255,0.06);
}
.report-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.report-item-date {
  font-size: 16px;
  font-weight: 600;
  color: #e0e0e0;
}
.report-item-meta {
  font-size: 12px;
  color: #777;
}
.report-view-btn {
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent-color, #3b82f6);
  background: transparent;
  color: var(--accent-color, #3b82f6);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}
.report-view-btn:hover {
  background: var(--accent-color, #3b82f6);
  color: #fff;
}
.report-iframe-wrapper {
  margin-top: 20px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
.report-iframe-wrapper iframe {
  width: 100%;
  height: 600px;
  border: none;
  background: #111;
}
