/* PKM/EKM Cloud — design system */
:root {
  --primary: #5b47e0;
  --primary-h: #4a38cc;
  --primary-light: #ede9ff;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f8f8fc;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #22c55e;
  --success-bg: #dcfce7;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --gray: #9ca3af;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.1);
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.55; font-size: 14px; min-height: 100vh; }

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

.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; display: flex; flex-direction: column; position: fixed;
  height: 100vh; overflow-y: auto; gap: 2px; z-index: 10;
}
.sidebar-logo { font-size: 15px; font-weight: 700; color: var(--primary); padding: 4px 8px 16px; letter-spacing: -.3px; }
.sidebar-logo span { color: var(--text-muted); font-weight: 400; }
.nav-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border-radius: var(--radius); color: var(--text-muted); text-decoration: none;
  font-size: 13.5px; cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav-link:hover, .nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-link .icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-user { font-size: 12px; color: var(--text-muted); padding: 4px 10px 8px; }
.sidebar-user strong { display: block; color: var(--text); font-size: 13px; }

.main { margin-left: var(--sidebar-w); padding: 28px 32px; flex: 1; max-width: 1100px; }

/* ── Typography ── */
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }

/* ── Page header ── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }

/* ── Card ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow);
}
.card-sm { padding: 16px; }

/* ── Button ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: var(--radius); border: 1px solid transparent; font-size: 13.5px;
  font-weight: 500; cursor: pointer; transition: background .12s, opacity .12s;
  text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; border-color: var(--error); }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 8px; }

/* ── Form ── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
label { font-size: 13px; font-weight: 500; color: var(--text); }
label .hint { color: var(--text-muted); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
textarea, select {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13.5px; background: var(--surface);
  color: var(--text); transition: border-color .12s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
input::placeholder { color: var(--gray); }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row > * { flex: 1; }
.input-row .btn { flex: none; }
.form-hint { font-size: 12px; color: var(--text-muted); }

/* ── Badge / Status ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
}
.badge-queued   { background: #f3f4f6; color: #6b7280; }
.badge-extracting, .badge-analyzing, .badge-generating, .badge-running { background: var(--info-bg); color: var(--info); }
.badge-done     { background: var(--success-bg); color: #16a34a; }
.badge-error    { background: var(--error-bg); color: #dc2626; }
.badge-overload { background: var(--warning-bg); color: #d97706; }
.badge-pkm      { background: var(--primary-light); color: var(--primary); }
.badge-ekm      { background: #fef9c3; color: #a16207; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted);
  padding: 8px 12px; border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .4px; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.td-filename { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.td-actions { display: flex; gap: 6px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%;
  max-width: 520px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  max-height: 90vh;
}
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }

/* ── Alert ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13.5px; margin-bottom: 16px; }
.alert-error { background: var(--error-bg); color: #dc2626; border: 1px solid #fca5a5; }
.alert-success { background: var(--success-bg); color: #16a34a; border: 1px solid #86efac; }
.alert-info { background: var(--info-bg); color: #1d4ed8; border: 1px solid #93c5fd; }
.alert-warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fcd34d; }

/* ── Progress bar ── */
.progress { height: 4px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); transition: width .4s ease; border-radius: 99px; }

/* ── Wizard stepper ── */
.stepper { display: flex; align-items: center; margin-bottom: 32px; }
.step { display: flex; align-items: center; gap: 8px; flex: 1; }
.step:last-child { flex: none; }
.step-circle {
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
  border: 2px solid var(--border); background: var(--surface); color: var(--text-muted);
  transition: all .2s;
}
.step.active .step-circle  { border-color: var(--primary); background: var(--primary); color: #fff; }
.step.done .step-circle    { border-color: var(--success); background: var(--success); color: #fff; }
.step-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.step.active .step-label   { color: var(--text); }
.step.done .step-label     { color: var(--success); }
.step-line { flex: 1; height: 2px; background: var(--border); margin: 0 8px; }
.step-line.done { background: var(--success); }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; gap: 4px; }
.tab-btn {
  padding: 8px 16px; font-size: 13.5px; font-weight: 500; color: var(--text-muted);
  background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color .12s, border-color .12s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Toggle switch ── */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--border); cursor: pointer; transition: background .2s;
}
.toggle-track::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: white;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ── Upload area ── */
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 32px; text-align: center; cursor: pointer; transition: all .15s;
}
.upload-area:hover, .upload-area.drag { border-color: var(--primary); background: var(--primary-light); }
.upload-area .upload-icon { font-size: 32px; margin-bottom: 8px; }
.upload-area p { color: var(--text-muted); font-size: 13.5px; }
.upload-area strong { color: var(--primary); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f0eff8 0%, #e8e4ff 100%); padding: 24px;
}
.login-card { width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .name { font-size: 22px; font-weight: 800; color: var(--primary); }
.login-logo .sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.login-mode { text-align: center; margin-bottom: 20px; }

/* ── Misc helpers ── */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.spin { animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.code-block { background: #1a1a2e; color: #e2e8f0; padding: 12px 16px; border-radius: var(--radius); font-family: monospace; font-size: 12.5px; word-break: break-all; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 12px; color: var(--text-muted); }
