:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef0f3;
  --text: #171717;
  --muted: #6b7280;
  --primary: #4b5563;
  --primary-strong: #111827;
  --danger: #b91c1c;
  --border: #e5e7eb;
  --ring: rgba(75, 85, 99, 0.18);
  --sidebar: #151515;
  --sidebar-muted: #b6bbc3;
  --radius: 12px;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

a { color: inherit; }

.app-container { min-height: 100vh; display: flex; }

.sidebar {
  width: 280px;
  position: fixed;
  inset: 0 auto 0 0;
  background: var(--sidebar);
  color: white;
  padding: 26px 18px;
  border-right: 1px solid #262626;
}

.brand {
  font-weight: 800;
  font-size: 1.22rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand::before {
  content: "SM";
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: #f5f5f5;
  color: #171717;
  font-size: 0.82rem;
  letter-spacing: 0;
}

.sidebar nav { margin-top: 24px; display: grid; gap: 6px; }

.nav-link {
  text-decoration: none;
  color: var(--sidebar-muted);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 0.94rem;
}

.nav-link:hover,
.nav-link.active {
  background: #2a2a2a;
  color: #fff;
}

.main-content {
  margin-left: 280px;
  width: calc(100% - 280px);
  padding: 32px;
}

header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

header h1 { margin: 0; font-size: clamp(1.55rem, 2vw, 2.05rem); }
header p { margin: 8px 0 0; color: var(--muted); max-width: 760px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h3 { margin-top: 0; }

.grid { display: grid; gap: 16px; }

.setup-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  margin-top: 16px;
}

.project-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.project-card {
  display: grid;
  gap: 12px;
}

.project-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.project-card-head h3 {
  margin: 0;
  line-height: 1.25;
}

.project-domain {
  margin: -2px 0 0;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  word-break: break-word;
}

.project-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.project-metrics .kpi {
  padding: 12px;
  box-shadow: none;
}

.project-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.project-action {
  min-height: 82px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-decoration: none;
  background: #fff;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "icon title"
    "icon meta";
  column-gap: 10px;
  align-items: center;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.project-action:hover {
  border-color: #a1a1aa;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.project-action i {
  grid-area: icon;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: inline-grid;
  place-items: center;
  background: var(--surface-3);
  color: #111827;
}

.project-action span {
  grid-area: title;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
}

.project-action small {
  grid-area: meta;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.project-action-primary {
  background: #111827;
  border-color: #111827;
}

.project-action-primary span,
.project-action-primary small {
  color: #fff;
}

.project-action-primary i {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.project-delete {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.project-delete summary {
  cursor: pointer;
  color: var(--danger);
  font-weight: 800;
  font-size: 0.86rem;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.project-delete summary::-webkit-details-marker {
  display: none;
}

.delete-project-form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0 22px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.kpi .label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 800;
}

.kpi .value { font-size: 1.45rem; font-weight: 800; margin-top: 6px; }

.input-row { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }

input, textarea, select, button { font: inherit; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 4px var(--ring);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.btn-primary,
.btn-dark {
  background: var(--primary-strong);
  color: #fff;
}

.btn-primary:hover,
.btn-dark:hover { background: #2f343b; }

.btn-muted {
  background: var(--surface-3);
  color: #27272a;
  border: 1px solid var(--border);
}

.btn-danger { background: var(--danger); color: #fff; }

.training-layout {
  grid-template-columns: 1.4fr 0.6fr;
  margin-top: 16px;
}

.source-form { grid-template-columns: 1fr auto; }
.settings-form { grid-template-columns: 1fr auto; }

.source-card,
.page-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}

.source-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

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

.progress-track {
  height: 8px;
  background: #e5e7eb;
  border-radius: 99px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-track > div {
  height: 100%;
  background: #111827;
  transition: width 0.2s ease;
}

.crawl-last {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  word-break: break-all;
}

.api-key-box {
  margin: 12px 0;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: #1f2937;
  overflow: auto;
}

.embed-code {
  white-space: pre-wrap;
  line-height: 1.55;
}

.section-note {
  color: var(--muted);
  margin: -2px 0 10px;
}

.section-note code {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 5px;
}

.color-control,
.upload-field {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-control span,
.upload-field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.color-control input[type="color"] {
  width: 100%;
  height: 32px;
  min-width: 72px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  box-shadow: none;
}

.upload-field input[type="file"] {
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: 0.82rem;
}

.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; font-weight: 800; }

.chart-box {
  position: relative;
  width: 100%;
  min-height: 220px;
  max-height: 360px;
}

.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.chart-box-sm { height: 260px; }
.chart-box-md { height: 300px; }
.chart-box-lg { height: 340px; }

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 800;
}

.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }

.auth-wrapper {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #111111;
}

.auth-card {
  width: min(450px, 100%);
  background: #fff;
  color: var(--text);
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.auth-card h1 { margin-top: 0; }
.auth-card input { background: #fff; }

.error { color: #b91c1c; font-size: 0.9rem; }
.success { color: #15803d; font-size: 0.9rem; }

@media (max-width: 980px) {
  .sidebar { position: static; width: 100%; height: auto; }
  .main-content { margin-left: 0; width: 100%; padding: 20px; }
  .app-container { flex-direction: column; }
  header { display: block; }
  .input-row, .training-layout, .setup-layout, .source-form, .settings-form { grid-template-columns: 1fr; }
  .source-head { flex-direction: column; }
  .source-actions { justify-content: flex-start; }
  .chart-box-sm, .chart-box-md, .chart-box-lg { height: 260px; }
  .project-actions, .project-metrics { grid-template-columns: 1fr; }
  .delete-project-form { grid-template-columns: 1fr; }
}
