:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #eff4ff;
  --ink: #101828;
  --muted: #667085;
  --border: #e4e7ec;
  --bg: #f7f8fa;
  --card: #ffffff;
  --green: #12b76a;
  --green-bg: #ecfdf3;
  --amber: #f79009;
  --amber-bg: #fffaeb;
  --red: #f04438;
  --red-bg: #fef3f2;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Auth pages ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(16,24,40,0.06);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), #6366f1);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
}
.auth-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.auth-sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--ink); font-size: 14px; font-weight: 500; cursor: pointer;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; }
.btn-danger { color: var(--red); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.helper-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin: -8px 0 16px; }
.helper-row a { color: var(--blue); font-weight: 500; }
.divider-text { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid #fecdca; }
.alert-success { background: var(--green-bg); color: #067647; border: 1px solid #abefc6; }
.sso-row { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex: none; background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 16px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px 20px; font-weight: 600; font-size: 15px; }
.nav-cta {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--blue); color: #fff; border-radius: 8px; padding: 10px; font-weight: 500;
  margin-bottom: 20px;
}
.nav-cta:hover { background: var(--blue-dark); }
.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px;
}
.nav-item:hover { background: #f9fafb; color: var(--ink); }
.nav-item.active { background: var(--blue-light); color: var(--blue); }
.nav-icon { width: 18px; text-align: center; }
.sidebar-spacer { flex: 1; }
.sidebar-divider { height: 1px; background: var(--border); margin: 16px 0; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.user-chip:hover { background: #f9fafb; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--blue-light); color: var(--blue);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex: none;
}
.user-chip-meta { min-width: 0; }
.user-chip-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-email { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; }
.topbar {
  display: none; align-items: center; justify-content: space-between; padding: 12px 16px;
  background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.content { max-width: 1440px; margin: 0 auto; padding: 32px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0; font-size: 14px; }
.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.breadcrumb a:hover { text-decoration: underline; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.card-header h2 { font-size: 16px; margin: 0; }
.card-link { color: var(--blue); font-size: 13px; font-weight: 500; }
.card-body { padding: 20px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.02em; padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }
.role-cell-title { font-weight: 600; }
.role-cell-sub { color: var(--muted); font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-high { background: var(--green-bg); color: #067647; }
.badge-high .badge-dot { background: var(--green); }
.badge-medium { background: var(--amber-bg); color: #b54708; }
.badge-medium .badge-dot { background: var(--amber); }
.badge-low { background: var(--red-bg); color: #b42318; }
.badge-low .badge-dot { background: var(--red); }
.badge-status { background: var(--border); color: var(--muted); }
.badge-status.completed { background: var(--green-bg); color: #067647; }
.badge-status.processing { background: var(--amber-bg); color: #b54708; }
.badge-status.failed { background: var(--red-bg); color: #b42318; }
.badge-status.draft { background: #eef2ff; color: #4338ca; }
.badge-status.archived { background: var(--border); color: var(--muted); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.activity-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-top: 5px; flex: none; }
.activity-time { color: var(--muted); font-size: 12px; }
.market-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.market-bar-label { width: 90px; flex: none; color: var(--muted); }
.market-bar-track { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.market-bar-fill { height: 100%; background: var(--blue); border-radius: 999px; }
.market-bar-value { width: 28px; text-align: right; font-weight: 600; }

.actions-menu { position: relative; }
.actions-trigger { border: none; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); }
.actions-trigger:hover { background: #f2f4f7; }
.actions-dropdown {
  display: none; position: absolute; right: 0; top: 32px; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,0.12); min-width: 160px; z-index: 30; overflow: hidden;
}
.actions-dropdown.open { display: block; }
.actions-dropdown a, .actions-dropdown button {
  display: block; width: 100%; text-align: left; padding: 9px 14px; font-size: 13.5px; border: none; background: none; cursor: pointer;
}
.actions-dropdown a:hover, .actions-dropdown button:hover { background: #f9fafb; }
.actions-dropdown .danger { color: var(--red); }

/* ---------- New analysis ---------- */
.new-analysis-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: start; }
.tab-strip { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-strip button { border: none; background: none; padding: 10px 14px; font-size: 13.5px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-strip button.active { color: var(--blue); border-color: var(--blue); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px dashed var(--border); border-radius: 10px; padding: 48px 20px; text-align: center; color: var(--muted);
  font-size: 13.5px; cursor: pointer; background: #fafbfc; min-height: 320px; box-sizing: border-box;
}
.dropzone:hover { border-color: var(--blue); }
.dropzone input { display: none; }
textarea.jd-textarea { width: 100%; min-height: 320px; border: 1px solid var(--border); border-radius: 10px; padding: 14px; font-size: 13.5px; resize: vertical; font-family: inherit; box-sizing: border-box; }
.char-count { text-align: right; color: var(--muted); font-size: 12px; margin-top: 6px; }
.depth-option {
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.depth-option-head { display: flex; align-items: center; gap: 8px; }
.depth-option input { margin: 0; }
.depth-option.selected { border-color: var(--blue); background: var(--blue-light); }
.depth-title { font-weight: 600; font-size: 13.5px; }
.depth-sub { color: var(--muted); font-size: 12px; margin-left: 22px; }

/* ---------- Analysis detail ---------- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.detail-meta { color: var(--muted); font-size: 13.5px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 8px; }
.freshness-banner { display: flex; align-items: center; justify-content: space-between; background: var(--amber-bg); border: 1px solid #fedf89; color: #b54708; padding: 10px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; gap: 12px; flex-wrap: wrap; }
.summary-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; margin-bottom: 16px; }
.pill { display: inline-block; background: var(--blue-light); color: var(--blue); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 500; margin: 3px 4px 0 0; }
.range-track { position: relative; height: 8px; background: var(--border); border-radius: 999px; margin: 28px 0 8px; }
.range-fill { position: absolute; height: 100%; background: var(--blue); border-radius: 999px; }
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.range-marker { position: absolute; top: -22px; transform: translateX(-50%); font-size: 11px; font-weight: 600; white-space: nowrap; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.metric-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.metric-value { font-size: 22px; font-weight: 700; }
.metric-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.detail-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.list-plain { margin: 0; padding-left: 18px; font-size: 13.5px; }
.list-plain li { margin-bottom: 6px; }

@media (max-width: 960px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .content { padding: 20px; }
  .stat-grid, .two-col, .new-analysis-grid, .summary-grid, .metric-grid, .detail-grid-3 { grid-template-columns: 1fr; }
}
