:root {
  /* Backgrounds */
  --bg-base:          #212121;
  --bg-surface:       #2a2a2a;
  --bg-elevated:      #2f2f2f;
  --bg-input:         #1a1a1a;
  --bg-row:           #1f1f1f;
  --bg-elevated-alpha: #2f2f2f22;

  /* Borders */
  --border:       #3f3f3f;
  --border-card:  #3a3a3a;
  --border-muted: #333;

  /* Text */
  --text-primary:   #ececec;
  --text-secondary: #ccc;
  --text-muted:     #888;
  --text-dim:       #666;
  --text-faint:     #555;
  --text-label:     #999;
  --text-white:     #fff;
  --text-subtle:    #aaa;

  /* Semantic colours */
  --color-error:      #f87171;
  --color-danger:     #ef4444;
  --color-danger-bg:  #ef444420;
  --color-success:    #4ade80;
  --color-success-bg: #4ade8020;

  /* Knowledge type badges */
  --badge-text-bg:     #1d4ed8;
  --badge-text-color:  #93c5fd;
  --badge-image-bg:    #065f46;
  --badge-image-color: #6ee7b7;
  --badge-video-bg:    #7c2d12;
  --badge-video-color: #fdba74;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
}

/* ── Gate ────────────────────────────────── */
#gate {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gate-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#gate-box h2 { font-size: 18px; font-weight: 600; }
#gate-box p  { font-size: 13px; color: var(--text-muted); }
#gate-error  { font-size: 13px; color: var(--color-error); display: none; }

/* ── Layout ──────────────────────────────── */
#app {
  display: none;
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

header h1 { font-size: 20px; font-weight: 600; }

header a {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}

header a:hover { color: var(--text-primary); }

/* ── Tabs ────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 28px;
  width: fit-content;
}

.tab-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section ─────────────────────────────── */
.section {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ── Form elements ───────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

label { font-size: 13px; color: var(--text-label); }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

textarea, input[type="text"], input[type="password"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

textarea:focus, input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--text-dim);
}

textarea { resize: vertical; line-height: 1.5; }

/* ── Buttons ─────────────────────────────── */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.35; cursor: default; }

.btn-primary { background: var(--text-primary); color: var(--bg-base); font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: var(--text-white); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  padding: 5px 12px;
  font-size: 12px;
}
.btn-danger:hover:not(:disabled) { background: var(--color-danger-bg); }

.btn-save-row {
  background: transparent;
  border: 1px solid var(--color-success);
  color: var(--color-success);
  padding: 5px 12px;
  font-size: 12px;
  display: none;
}
.btn-save-row:hover:not(:disabled) { background: var(--color-success-bg); }

.status-text {
  font-size: 13px;
  color: var(--color-success);
  margin-left: 12px;
  display: none;
}

/* ── Type tabs (add form) ────────────────── */
.type-tabs { display: flex; gap: 6px; margin-bottom: 14px; }

.type-tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all 0.15s;
}
.type-tab.active { background: var(--border); border-color: var(--text-faint); color: var(--text-primary); }

/* ── File upload ─────────────────────────── */
#file-field { display: none; }

.file-drop {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.file-drop:hover, .file-drop.drag-over { border-color: var(--text-muted); color: var(--text-subtle); }
.file-drop input { display: none; }
#file-name { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Knowledge table ─────────────────────── */
.k-table {
  width: 100%;
  border-collapse: collapse;
}

.k-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border-muted);
}

.k-table td {
  padding: 12px;
  border-bottom: 1px solid var(--bg-elevated);
  vertical-align: top;
}

.k-table tbody tr:last-child td { border-bottom: none; }

.k-table tbody tr:hover td { background: var(--bg-elevated-alpha); }

.k-type {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
}
.k-type.text  { background: var(--badge-text-bg);  color: var(--badge-text-color); }
.k-type.image { background: var(--badge-image-bg); color: var(--badge-image-color); }
.k-type.video { background: var(--badge-video-bg); color: var(--badge-video-color); }

.k-thumb {
  width: 48px;
  height: 48px;
  border-radius: 5px;
  object-fit: cover;
  border: 1px solid var(--border);
  margin-top: 6px;
  display: block;
}

.k-edit {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 7px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.k-edit:focus { border-color: var(--text-faint); background: var(--bg-input); color: var(--text-primary); }

.k-date { font-size: 11px; color: var(--text-faint); }

.k-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

#k-empty, #k-loading {
  font-size: 14px;
  color: var(--text-faint);
  text-align: center;
  padding: 24px 0;
}

/* ── Prompt list ─────────────────────────── */
#prompt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.prompt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-row);
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  padding: 10px 14px;
}

.prompt-row span {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}
