:root {
  --bg: #fbfafd;
  --surface: #ffffff;
  --surface-2: #f4f3f7;
  --border: #e3e1ea;
  --text: #2a2833;
  --muted: #6e6b7a;
  --accent: #6b4fbb;
  --accent-soft: #efeaff;
  --danger: #c4314b;
  --add-bg: #e6f6ea;
  --add-fg: #1b6b33;
  --del-bg: #fdeaea;
  --del-fg: #a3202f;
  --hunk: #eef1fb;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18171c;
    --surface: #201f26;
    --surface-2: #2a2931;
    --border: #383641;
    --text: #ecebf1;
    --muted: #a19eae;
    --accent: #a48cf0;
    --accent-soft: #2f2747;
    --danger: #f06b80;
    --add-bg: #17331f;
    --add-fg: #8fe0a6;
    --del-bg: #3d1a20;
    --del-fg: #ff9aa8;
    --hunk: #252a3d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 14px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 20px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 28px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.01em; color: var(--text); }
.brand img { height: 40px; width: auto; }
.brand:hover { text-decoration: none; }
#nav { display: flex; align-items: center; gap: 14px; }
#nav .btn { padding: 8px 16px; }
#nav .svg { width: 18px; height: 18px; }
#nav summary .icon { width: 38px; height: 38px; font-size: 14px; }
#nav .menu-items { min-width: 220px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12); padding: 6px; display: flex; flex-direction: column;
}
.menu-items a, .menu-items button {
  padding: 7px 10px; border-radius: 6px; color: var(--text); text-align: left;
  background: none; border: 0; font: inherit; cursor: pointer;
}
.menu-items a:hover, .menu-items button:hover { background: var(--surface-2); text-decoration: none; }
.menu-items hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }

/* ---- layout ---- */
main { max-width: 1400px; margin: 0 auto; padding: 32px 32px 72px; }
.page-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.page-head .grow { flex: 1; min-width: 0; }
.page-head p { margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card-pad { padding: 20px 24px; }
.card-head {
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0; font-weight: 600;
}
.empty { padding: 32px; text-align: center; color: var(--muted); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-bottom: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.crumbs .sep { opacity: .6; }

/* ---- icons ---- */
.icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 8px; overflow: hidden;
  color: #fff; font-weight: 700; font-size: 15px; text-transform: uppercase; object-fit: cover;
}
.icon.round { border-radius: 50%; }
.icon.xs { width: 22px; height: 22px; font-size: 10px; border-radius: 5px; }
.icon.sm { width: 30px; height: 30px; font-size: 12px; }
.icon.lg { width: 80px; height: 80px; font-size: 30px; border-radius: 14px; }
.svg { width: 16px; height: 16px; flex: none; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list .title { font-weight: 600; color: var(--text); }
.list .grow { flex: 1; min-width: 0; }
.list .desc { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px; font-size: 13px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag { background: var(--accent-soft); color: var(--accent); border: 0; }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 600; }

/* ---- forms ---- */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 14px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
textarea.mono { font-family: var(--mono); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.form-narrow { max-width: 680px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form > * { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 14px; }
button:disabled { opacity: .55; cursor: default; }

/* ---- clone box ---- */
.clone { min-width: 320px; padding: 12px; gap: 10px; }
.clone label { font-size: 14px; margin: 0; }
.copy { display: flex; }
.copy input { border-radius: 6px 0 0 6px; font-family: var(--mono); font-size: 13px; }
.copy button { border-radius: 0 6px 6px 0; border-left: 0; }

/* ---- files ---- */
.files td { padding: 10px 20px; border-top: 1px solid var(--border); }
.files tr:first-child td { border-top: 0; }
.files a { color: var(--text); display: inline-flex; gap: 8px; align-items: center; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; padding: 10px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
td { padding: 10px 20px; border-top: 1px solid var(--border); }
tr:first-child td { border-top: 0; }

.code { overflow-x: auto; }
.code table { font-family: var(--mono); font-size: 14px; }
.code td { border: 0; padding: 0 12px; white-space: pre; vertical-align: top; }
.code td.ln { width: 1%; text-align: right; color: var(--muted); user-select: none; border-right: 1px solid var(--border); }

.markdown { padding: 8px 28px 20px; overflow-wrap: anywhere; }
.markdown img { max-width: 100%; }
.markdown pre { background: var(--surface-2); padding: 12px; border-radius: 6px; overflow-x: auto; }
.markdown code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.markdown pre code { background: none; padding: 0; }
.markdown table td, .markdown table th { border: 1px solid var(--border); }
.markdown h1, .markdown h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; margin: 20px 0 12px; }

/* ---- diff ---- */
.diff-file { margin-bottom: 16px; }
.diff-file .card-head { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.diff { font-family: var(--mono); font-size: 13.5px; overflow-x: auto; }
.diff div { white-space: pre; padding: 0 12px; min-height: 1.5em; }
.diff .add { background: var(--add-bg); color: var(--add-fg); }
.diff .del { background: var(--del-bg); color: var(--del-fg); }
.diff .hunk { background: var(--hunk); color: var(--muted); }

.hash { font-family: var(--mono); font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.commit-body { white-space: pre-wrap; font-family: var(--mono); font-size: 14px; margin: 10px 0 0; color: var(--muted); }

/* ---- grid & misc ---- */
.settings-grid { display: grid; grid-template-columns: 280px 1fr; gap: 32px; padding: 28px 0; border-top: 1px solid var(--border); }
.settings-grid:first-child { border-top: 0; padding-top: 0; }
.settings-grid p { margin: 4px 0 0; }
@media (max-width: 760px) { .settings-grid { grid-template-columns: 1fr; } }
.auth-box { max-width: 440px; margin: 72px auto; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / .2); max-width: 380px;
}
.toast.error { background: var(--danger); color: #fff; }
