/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--dur-normal) var(--ease-out);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 22px;
  font-size: var(--text-lg);
  font-weight: 700;
  text-decoration: none;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo svg { width: 28px; height: 28px; flex-shrink: 0; }
.sidebar-logo em { color: var(--primary-400); font-style: normal; }
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-400);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  margin-bottom: 2px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: var(--gray-200); }
.sidebar-nav a.active { background: rgba(59,130,246,0.15); color: var(--primary-400); }
.sidebar-nav a svg { width: 20px; height: 20px; flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a.active svg { opacity: 1; }
.sidebar-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-500);
  padding: 20px 14px 6px;
}
.sidebar-user {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--primary-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: 12px;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast);
}
.sidebar-logout:hover { color: var(--error-500); }
.sidebar-logout svg { width: 18px; height: 18px; }

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  background: var(--gray-900);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  width: 40px;
  height: 40px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}

/* ========== Main Content ========== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}
.page-header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
}
.page-subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-top: 2px;
}
.page-body {
  padding: 28px 32px;
  max-width: 1200px;
}

/* ========== Views ========== */
.view { display: none; }
.view.active { display: block; }

/* ========== Stat Cards ========== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--gray-200);
}
.stat-card-label {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-bottom: 6px;
}
.stat-card-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.2;
}
.stat-card-value.score-excellent { color: var(--score-excellent); }
.stat-card-value.score-good { color: var(--score-good); }
.stat-card-value.score-average { color: var(--score-average); }
.stat-card-value.score-poor { color: var(--score-poor); }

/* ========== Table ========== */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h2 {
  font-size: var(--text-base);
  font-weight: 600;
}
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--gray-50); }

/* ========== Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-full);
}
.badge-pending { background: var(--warning-50); color: var(--warning-600); }
.badge-running, .badge-crawling { background: var(--primary-50); color: var(--primary-600); }
.badge-ready, .badge-done { background: var(--success-50); color: var(--success-600); }
.badge-failed, .badge-error { background: var(--error-50); color: var(--error-600); }
.badge-critical { background: var(--error-50); color: var(--error-600); }
.badge-warning { background: var(--warning-50); color: var(--warning-600); }
.badge-opportunity { background: var(--primary-50); color: var(--primary-600); }

/* ========== Score Ring ========== */
.score-ring {
  width: 140px;
  height: 140px;
  position: relative;
}
.score-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.score-ring-bg { fill: none; stroke: var(--gray-100); stroke-width: 10; }
.score-ring-fg {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-chart) var(--ease-out);
}
.score-ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-ring-number {
  font-size: var(--text-4xl);
  font-weight: 800;
  line-height: 1;
}
.score-ring-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ========== Report ========== */
.report-header {
  display: flex;
  align-items: flex-start;
  gap: 28px;
  margin-bottom: 32px;
  padding: 24px;
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
}
.report-info { flex: 1; }
.report-domain {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin-bottom: 4px;
}
.report-date {
  font-size: var(--text-sm);
  color: var(--gray-500);
}
.report-stats {
  display: flex;
  gap: 24px;
  margin-top: 16px;
}
.report-stat {
  text-align: center;
}
.report-stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
}
.report-stat-label {
  font-size: 12px;
  color: var(--gray-500);
}

/* Category cards */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.category-card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 20px;
}
.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.category-name {
  font-size: var(--text-base);
  font-weight: 600;
}
.category-score {
  font-size: var(--text-xl);
  font-weight: 700;
}
.category-bar {
  height: 6px;
  background: var(--gray-100);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.category-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--dur-chart) var(--ease-out);
}

/* Issues list */
.issue-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}
.issue-item:last-child { border-bottom: none; }
.issue-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.issue-title {
  font-size: var(--text-sm);
  font-weight: 500;
}
.issue-desc {
  font-size: 13px;
  color: var(--gray-500);
  line-height: 1.4;
}
.issue-fix {
  font-size: 13px;
  color: var(--primary-600);
  margin-top: 4px;
}

/* Actions list */
.action-list {
  list-style: none;
}
.action-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: var(--text-sm);
}
.action-item:last-child { border-bottom: none; }
.action-number {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--primary-50);
  color: var(--primary-600);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

/* ========== Progress (audit in progress) ========== */
.progress-wrap {
  max-width: 520px;
  margin: 60px auto;
  text-align: center;
}
.progress-wrap h2 {
  font-size: var(--text-2xl);
  margin-bottom: 8px;
}
.progress-wrap p {
  color: var(--gray-500);
  margin-bottom: 32px;
}
.progress-bar {
  height: 8px;
  background: var(--gray-100);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary-500);
  border-radius: 4px;
  transition: width 0.5s var(--ease-out);
}
.progress-steps {
  text-align: left;
  list-style: none;
}
.progress-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: var(--text-sm);
  color: var(--gray-400);
}
.progress-step.done { color: var(--success-600); }
.progress-step.active { color: var(--gray-900); font-weight: 500; }
.progress-step-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--gray-300);
  flex-shrink: 0;
}
.progress-step.done .progress-step-dot { background: var(--success-500); }
.progress-step.active .progress-step-dot { background: var(--primary-500); animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

/* ========== New Audit Form ========== */
.new-audit-form {
  max-width: 560px;
}
.new-audit-form .form-group {
  margin-bottom: 20px;
}
.new-audit-form label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}
.new-audit-form input:not([type="checkbox"]):not([type="radio"]),
.new-audit-form select {
  width: 100%;
  padding: 10px 14px;
  font-size: var(--text-base);
  font-family: var(--font-sans);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  outline: none;
  background: #fff;
  transition: border-color var(--dur-fast);
}
.new-audit-form input:not([type="checkbox"]):not([type="radio"]):focus,
.new-audit-form select:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.size-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.size-card {
  background: #fff;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  text-align: center;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.size-card:hover { border-color: var(--primary-300); }
.size-card.selected { border-color: var(--primary-500); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.size-card-name { font-weight: 600; margin-bottom: 4px; }
.size-card-pages { font-size: 13px; color: var(--gray-500); }
.size-card-price { font-size: var(--text-xl); font-weight: 700; color: var(--primary-600); margin-top: 8px; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur-fast), transform var(--dur-fast);
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary-600); color: #fff; }
.btn-primary:hover { background: var(--primary-700); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-state svg {
  width: 64px;
  height: 64px;
  color: var(--gray-300);
  margin-bottom: 16px;
}
.empty-state h3 {
  font-size: var(--text-lg);
  margin-bottom: 8px;
}
.empty-state p {
  color: var(--gray-500);
  font-size: var(--text-sm);
  margin-bottom: 20px;
}

/* ========== Loading ========== */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Internal badge ========== */
.internal-badge {
  display: inline-block;
  background: var(--primary-600);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.04em;
  margin-left: 6px;
  vertical-align: middle;
}

/* ========== Raw Data Tabs ========== */
.raw-tabs {
  padding: 0 20px;
  border-bottom: 1px solid var(--gray-100);
}
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 0;
  max-height: 200px;
  overflow-y: auto;
}
.tab {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}
.tab.active {
  background: var(--primary-50);
  border-color: var(--primary-500);
  color: var(--primary-700);
}
.tab-count {
  background: rgba(0,0,0,0.06);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}
.tab.active .tab-count {
  background: var(--primary-500);
  color: #fff;
}

.raw-table-wrap {
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
}
.raw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.raw-table th {
  position: sticky;
  top: 0;
  background: var(--gray-50);
  font-size: 11px;
  padding: 8px 10px;
  white-space: nowrap;
  z-index: 2;
}
.raw-table td {
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--gray-100);
}
.raw-table tr:hover td {
  background: var(--gray-50);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .sidebar-overlay.open { display: block; }
  .main-content { margin-left: 0; }
  .page-header { padding: 16px 16px 16px 60px; }
  .page-body { padding: 20px 16px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .report-header { flex-direction: column; align-items: center; text-align: center; }
  .report-stats { flex-wrap: wrap; justify-content: center; }
  .category-grid { grid-template-columns: 1fr; }
  .size-cards { grid-template-columns: 1fr; }
}
