@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/static/fonts/bricolage-grotesque.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --cream: #eef0f4;
  --paper: #fff;
  --ink: #171719;
  --ink-soft: #35363a;
  --muted: #777980;
  --line: rgba(18, 19, 22, 0.13);
  --accent: #2e6fb5;
  --accent-dark: #1e5a96;
  --ok-bg: #eaf6d9;
  --ok-ink: #4d6b1f;
  --err-bg: #fff0ef;
  --err-ink: #bd302b;
  --radius: 12px;
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Code", Consolas, monospace;
  --sans: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgba(23, 21, 18, 0.06);
  padding: 0.12em 0.35em;
  border-radius: 5px;
}

/* layout */
.layout {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 24px 16px;
  background: #fff;
  border-right: 1px solid var(--line);
  color: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  flex: none;
}

.brand-text { font-weight: 600; letter-spacing: -0.01em; }

.nav { display: flex; flex-direction: column; gap: 14px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav a {
  padding: 9px 12px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a:hover { background: #e7e9ed; color: var(--ink); }
.nav a.active { background: #dce8fa; color: var(--accent); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

.ghost-link {
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.ghost-link:hover { color: var(--accent); text-decoration: underline; }
.sidebar .ghost-link { color: var(--muted); }
.sidebar .ghost-link:hover { color: var(--accent); }
.ghost-link.as-button { cursor: pointer; }

.main {
  padding: 32px 40px 56px;
  max-width: 1440px;
  width: 100%;
}

/* header */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.eyebrow { display: none; }

h1 { margin: 0; font-size: 28px; letter-spacing: -0.035em; line-height: 1.15; }
h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* flash */
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 14px;
  border: 1px solid transparent;
}
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: #d7e8b8; }
.flash.err { background: var(--err-bg); color: var(--err-ink); border-color: #f2cec6; }

/* stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat p { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.stat strong { display: block; font-size: 29px; letter-spacing: -0.04em; line-height: 1.1; }
.stat span { font-size: 12.5px; color: var(--muted); }

/* panels */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.split .panel { margin-bottom: 18px; }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rows li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.rows li:first-child { border-top: 0; }
.rows a { text-decoration: none; font-weight: 500; }
.rows a:hover { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill.live { background: #eaf6d9; color: #4d6b1f; }
.pill.draft { background: #f2e7c7; color: #7a6a42; }

.api-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
}

/* buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.button:hover { border-color: #c9ccd2; background: #f2f3f5; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button.ghost { background: transparent; }
.button.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.button.danger { color: var(--err-ink); border-color: #edd2cb; background: transparent; }
.button.danger:hover { background: var(--err-bg); border-color: #e3b7ac; }

/* table */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #f2f3f5;
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td a { text-decoration: none; }
.table td a:hover { color: var(--accent); }
.table .right { text-align: right; }

.project-preview {
  display: block;
  width: 104px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f3f5;
}
.project-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.project-preview-empty { display: grid; width: 100%; height: 100%; place-items: center; color: var(--muted); font-size: 11px; }
.project-tech-list { display: flex; max-width: 260px; flex-wrap: wrap; align-items: center; gap: 5px; }
.project-tech-tag { padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font-size: 11px; white-space: nowrap; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* forms */
.editor { display: block; }
.stack { display: flex; flex-direction: column; gap: 14px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 120, 246, 0.14);
}

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

label.check {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f2f3f5;
  font-size: 13.5px;
  align-self: end;
  margin-bottom: 14px;
}
label.check input { width: auto; }

.hint { font-size: 11.5px; font-weight: 400; color: var(--muted); }

.grid-2, .grid-3, .grid-4 { display: grid; gap: 0 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.code-area {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: #f2f3f5;
  tab-size: 2;
}
.body-area { font-size: 13px; }

.md-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(23, 21, 18, 0.025);
}

.md-toolbar .button {
  min-width: 34px;
}

.md-area {
  min-height: 460px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  tab-size: 2;
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
}

.inline-actions { display: flex; gap: 8px; }

/* project sections */
.sections { display: flex; flex-direction: column; gap: 14px; }

.section-row {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px 16px 14px;
  background: #fafbfc;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-number {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-actions { display: flex; align-items: center; gap: 6px; }
.section-actions .button { min-width: 0; padding: 3px 9px; font-size: 11.5px; }
.section-actions .danger-link:disabled { opacity: 0.35; cursor: not-allowed; text-decoration: none; }
.section-markdown { min-height: 180px; }
.md-toolbar .section-count { margin-left: auto; align-self: center; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* beats */
.beats { display: flex; flex-direction: column; gap: 14px; }

.beat-row {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px 16px 2px;
  background: #fafbfc;
}

.beat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.beat-number {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.danger-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 12px;
  color: var(--err-ink);
  cursor: pointer;
}
.danger-link:hover { text-decoration: underline; }

/* empty */
.empty {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.empty p { margin: 0 0 14px; }

/* login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--cream);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 30px 24px;
  box-shadow: 0 16px 44px rgba(23, 21, 31, 0.08);
}

.login-card .brand-mark { margin-bottom: 16px; }
.login-card h1 { font-size: 26px; margin-bottom: 6px; }
.login-card .ghost-link { display: inline-block; margin-top: 18px; font-size: 13px; }

.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 68px; }
.reveal {
  position: absolute;
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
  border: 0;
  background: #eef0f4;
  color: var(--ink-soft);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
}
.reveal:hover { background: #e7e9ed; }
.reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    padding: 14px 18px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .main { padding: 24px 20px 48px; }
  .split, .grid-3, .grid-2, .api-grid { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  h1 { font-size: 24px; }
}

/* uploads */
.upload { display: flex; flex-direction: column; gap: 8px; }
.upload-row { display: flex; gap: 8px; align-items: stretch; }
.upload-row .upload-input { flex: 1; }
.upload-pick { cursor: pointer; white-space: nowrap; }
.upload-pick.busy { opacity: 0.6; pointer-events: none; }
.upload-preview img { max-width: 100%; max-height: 180px; border-radius: 10px; border: 1px solid var(--line); margin-top: 4px; display: block; }
.upload-preview audio { width: 100%; margin-top: 4px; }
.upload[data-preview="image"] .upload-preview img { max-height: 120px; }
.upload-current, .upload-empty, .upload-missing { margin: 6px 0 0; }
.upload-current code { font-size: 12px; word-break: break-all; }
.upload-missing { color: var(--err-ink); }

/* editor lists + photo cards */
.editor-list { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.editor-list .editor { padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 16px; }
.photo-card { margin: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.photo-card img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 9px; background: rgba(23, 21, 18, 0.04); }
.photo-card figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.self-end { align-self: flex-end; }

/* home sections */
.sub-card { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.55); }
.folder-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.folder-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.folder-row form { margin: 0 0 0 auto; flex: none; }
.folder-icon { width: 38px; height: 38px; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: rgba(23, 21, 18, 0.04); object-fit: contain; }
.folder-text { display: flex; flex-direction: column; min-width: 0; }
.folder-text strong { font-size: 14.5px; }
.folder-text span { word-break: break-all; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.55); }
.file-row p { margin: 0; }
.file-name { font-weight: 600; word-break: break-all; }
.file-actions { display: flex; gap: 8px; flex: none; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-size: 13.5px; font-weight: 500; }
.chip form { display: flex; }
.chip-remove { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: 0; border-radius: 999px; background: rgba(23, 21, 18, 0.06); color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer; transition: background 0.15s ease, color 0.15s ease; }
.chip-remove:hover { background: var(--err-bg); color: var(--err-ink); }

@media (max-width: 720px) {
  .file-row { flex-direction: column; align-items: flex-start; }
  .folder-row { flex-wrap: wrap; }
  .folder-row form { margin-left: 0; width: 100%; }
  .folder-row form button { width: 100%; }
}

/* health + status helpers */
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; word-break: break-word; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 999px; background: var(--muted); margin-right: 7px; vertical-align: middle; }
.dot.ok { background: #65b94b; box-shadow: 0 0 0 3px rgba(101, 185, 75, 0.18); }
.dot.err { background: #d43d1f; box-shadow: 0 0 0 3px rgba(212, 61, 31, 0.18); }
.code-area pre { margin: 0; max-height: 260px; overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }

.status-line { font-size: 14.5px; font-weight: 600; margin: 2px 0 4px; }
.pill.method { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; }
.kv-list { display: flex; flex-direction: column; }
.attention { display: flex; flex-direction: column; gap: 10px; }
.attention-item { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.attention-item .dot { margin-top: 5px; flex: none; }

/* toasts */.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast { padding: 11px 15px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 30px rgba(23, 21, 18, 0.18); background: #fff; border: 1px solid var(--line); animation: toast-in 0.2s ease-out; }
.toast.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.toast.err { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all 0.3s ease; }

/* sidebar groups */
.nav-label {
  padding: 0 12px 5px;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* edit-in-place rows (folders, music) */
.inline-edit { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; margin: 0; }
.inline-edit input { min-width: 0; padding: 7px 10px; font-size: 13.5px; }
.inline-edit .grow { flex: 2 1 0; }
.inline-edit .grow-sm { flex: 1 1 0; }
.inline-edit select.mini { width: auto; flex: none; padding: 7px 8px; font-size: 12.5px; }
.folder-row > form:last-of-type { margin: 0 0 0 auto; flex: none; }
.track-cover {
  width: 42px;
  height: 42px;
  flex: none;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(23, 21, 18, 0.04);
}

/* collapsed extra controls */
.mini-details { border-top: 1px solid var(--line); padding-top: 8px; }
.mini-details > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}
.mini-details > summary::-webkit-details-marker { display: none; }
.mini-details > summary::after { content: " +"; }
.mini-details[open] > summary::after { content: " –"; }
.mini-details > summary:hover { color: var(--accent); }
.mini-details[open] > summary { margin-bottom: 12px; }

@media (max-width: 820px) {
  .nav-group { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav-group + .nav-group { margin-top: 0; }
  .nav-label { display: none; }
  .inline-edit { flex-wrap: wrap; }
  .inline-edit .grow, .inline-edit .grow-sm { flex: 1 1 140px; }
}

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
