:root {
  --bg: #f4f5f9;
  --card: #fff;
  --fg: #1b1d2a;
  --muted: #646a80;
  --line: #e2e4ee;
  --accent: #5b5bf0;
  --danger: #d23a4f;
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
small { font-weight: 400; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px; margin-bottom: 18px; }
label { display: block; margin: 12px 0 0; font-weight: 600; font-size: 0.92rem; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 4px 16px 0 0; font-weight: 400; }
input:not([type='checkbox']):not([type='radio']):not([type='file']), select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px; font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 12px 0 0; }
legend { font-weight: 600; font-size: 0.92rem; padding: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 18px; }

button { font: inherit; border-radius: 9px; padding: 9px 16px; cursor: pointer; border: 1px solid var(--line); background: #fff; color: inherit; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.6; cursor: wait; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.login button { width: 100%; margin-top: 18px; }
.error { color: var(--danger); margin: 12px 0 0; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; }
.brand span { font-weight: 400; color: var(--muted); margin-left: 6px; }
.top-actions { display: flex; gap: 12px; align-items: center; }
.top-actions a { color: var(--accent); text-decoration: none; font-weight: 600; }
.content { max-width: 860px; margin: 24px auto; padding: 0 16px 80px; }

.switch { display: flex; align-items: center; gap: 12px; font-weight: 400; margin-top: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.slider { flex: none; width: 44px; height: 26px; border-radius: 999px; background: #cfd2de; position: relative; transition: background 0.2s; }
.slider::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.switch input:checked + .slider { background: #1f9d55; }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

.usage { margin: 16px 0 4px; padding: 12px 14px; background: var(--bg); border-radius: 10px; font-size: 0.92rem; }
.usage b { font-variant-numeric: tabular-nums; }

.savebar { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; margin: 0 0 18px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05); }

.kb-list { list-style: none; padding: 0; margin: 16px 0; }
.kb-list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.kb-list li:last-child { border-bottom: 1px solid var(--line); }
.kb-list .text { flex: 1; min-width: 0; }
.kb-list .text p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.kb-list .empty { color: var(--muted); }
.kb-form { border-top: 1px dashed var(--line); padding-top: 16px; }
.kb-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.kb-actions .spacer { flex: 1; }
label.file { margin: 0; font-weight: 400; color: var(--accent); cursor: pointer; }
label.file input { display: none; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1b1d2a; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 10; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2); }
.toast.bad { background: var(--danger); }

@media (max-width: 600px) {
  .top { padding: 12px 16px; }
  .savebar { flex-direction: column; align-items: stretch; }
}
