/* CHANTIFA admin — same palette and type as the app (css/style.css), tuned for editing. */

@font-face {
  font-family: 'Barlow';
  font-weight: 400;
  font-display: swap;
  src: url('../../fonts/barlow-400.woff2') format('woff2');
}

@font-face {
  font-family: 'Barlow';
  font-weight: 600;
  font-display: swap;
  src: url('../../fonts/barlow-600.woff2') format('woff2');
}

@font-face {
  font-family: 'Barlow Condensed';
  font-weight: 800;
  font-display: swap;
  src: url('../../fonts/barlow-condensed-800.woff2') format('woff2');
}

:root {
  --bg: #0d0d0d;
  --bg-2: #181716;
  --bg-3: #221f1d;
  --paper: #f3eee4;
  --red: #e4002b;
  --red-dark: #a8001f;
  --muted: #9b968c;
  --line: #2c2a27;
  --line-2: #3d3a36;
  --changed: #f2b632;
  --ok: #4cc38a;
  --radius: 8px;
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --font-body: 'Barlow', system-ui, sans-serif;
  --topbar-h: 56px;
  --savebar-h: 64px;
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--paper);
  font: 16px/1.45 var(--font-body);
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.logo {
  margin: 0;
  font: 800 24px/1 var(--font-display);
  letter-spacing: 0.02em;
}

.logo span {
  color: var(--red);
}

/* ---------- buttons & fields ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg-3);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--muted);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  background: transparent;
  border-color: var(--red-dark);
  color: #ff6b81;
}

.btn-small {
  min-height: 30px;
  padding: 3px 10px;
  font-size: 14px;
}

.btn-icon {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
}

:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 2px;
}

input:not([type='checkbox']):not([type='radio']),
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg-2);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--paper);
}

textarea {
  resize: vertical;
  min-height: 64px;
  line-height: 1.4;
}

input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--red);
  width: 18px;
  height: 18px;
  margin: 0;
}

label {
  display: block;
}

.field {
  display: grid;
  gap: 6px;
  margin: 0 0 18px;
}

.field > .label,
.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.row-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ---------- login ---------- */

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.login {
  width: 100%;
  max-width: 360px;
}

.login .logo {
  margin-bottom: 24px;
  font-size: 40px;
  text-align: center;
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.form-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgb(228 0 43 / 0.18);
  color: #ff8fa0;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar .repo {
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .repo:hover {
  color: var(--paper);
}

.topbar .logout {
  margin-left: auto;
}

.loading {
  padding: 48px 16px;
  color: var(--muted);
  text-align: center;
}

/* ---------- tabs & notices ---------- */

.subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.tab[aria-selected='true'] {
  background: var(--paper);
  color: var(--bg);
}

.last-commit {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.notices:empty {
  display: none;
}

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 12px 16px 0;
  padding: 10px 14px;
  border: 1px solid var(--line-2);
  border-left: 4px solid var(--changed);
  border-radius: var(--radius);
  background: var(--bg-2);
}

.notice.error {
  border-left-color: var(--red);
}

.notice.success {
  border-left-color: var(--ok);
}

.notice-body {
  flex: 1;
  min-width: 0;
}

.notice ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.notice-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.notice-close {
  flex: none;
}

/* ---------- chants workspace ---------- */

/* Desktop: the app fills the window below the top bar; list and editor scroll on their own. */
#app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
}

#app.has-savebar {
  padding-bottom: var(--savebar-h);
}

.workspace {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  min-height: 0;
}

.listpane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar .search {
  grid-column: 1 / -1;
}

.toolbar .new-btn {
  grid-column: 1 / -1;
}

.list-count {
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.chantlist {
  flex: 1;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.chant-row {
  display: block;
  width: 100%;
  padding: 10px 16px 10px 13px;
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.chant-row:hover {
  background: var(--bg-2);
}

.chant-row[aria-current='true'] {
  border-left-color: var(--red);
  background: var(--bg-3);
}

.chant-row.is-disabled .row-text {
  color: var(--muted);
  text-decoration: line-through;
}

.row-text {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-resp {
  display: block;
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  align-items: center;
}

.row-id {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 18px;
  text-transform: uppercase;
}

.badge-new {
  background: var(--red);
  color: #fff;
}

.badge-disabled {
  background: var(--line-2);
  color: var(--paper);
}

.badge-changed {
  background: var(--changed);
  color: var(--bg);
}

.badge-error {
  background: #ff6b81;
  color: var(--bg);
}

.empty {
  padding: 32px 16px;
  color: var(--muted);
  text-align: center;
}

/* ---------- chant editor ---------- */

.editorpane {
  min-height: 0;
  overflow-y: auto;
}

.editor {
  max-width: 820px;
  padding: 16px 24px 48px;
}

.editor-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.editor-head h2 {
  margin: 0;
  font: 800 28px/1.1 var(--font-display);
}

.editor-head .actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.back-btn {
  display: none;
}

.seg {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
}

.seg label {
  padding: 3px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg label:has(input:checked) {
  background: var(--paper);
  color: var(--bg);
}

.seg label:has(input:focus-visible) {
  outline: 2px solid var(--paper);
  outline-offset: 1px;
}

.rounds {
  display: grid;
  gap: 8px;
}

.round {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 34px;
  gap: 8px;
  align-items: center;
}

.round-no {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cat-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cat-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 8px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
}

.cat-pick:has(input:checked) {
  border-color: var(--red);
  background: rgb(228 0 43 / 0.18);
}

.cat-pick .order {
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.flags {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-bottom: 18px;
}

.errors {
  margin: 0 0 18px;
  padding: 10px 14px 10px 32px;
  border-radius: var(--radius);
  background: rgb(228 0 43 / 0.15);
  color: #ff8fa0;
}

.preview {
  position: relative;
  padding: 20px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--bg);
}

.preview.is-disabled::after {
  content: 'Hidden in the app';
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--paper);
  font-size: 12px;
  font-weight: 600;
}

.preview-call,
.preview-resp {
  margin: 0;
  font: 800 26px/1.1 var(--font-display);
  text-transform: uppercase;
  white-space: pre-line;
}

.preview-resp {
  color: var(--red);
  margin-bottom: 10px;
}

.preview-call + .preview-call {
  margin-top: 10px;
}

.preview-comment {
  margin: 12px 0 0;
  font-size: 14px;
  font-style: italic;
}

.preview-empty {
  color: #8a857c;
}

.placeholder {
  display: grid;
  height: 100%;
  min-height: 300px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

/* ---------- categories ---------- */

.cats {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 48px;
}

.cats > * {
  max-width: 1100px;
}

.cats-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.cats-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.cat-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px 16px;
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 3px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-2);
}

.cat-card.is-changed {
  border-left-color: var(--changed);
}

.cat-card.has-error {
  border-left-color: #ff6b81;
}

.cat-order {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.cat-order .row-id {
  margin: 0 0 2px;
}

.cat-fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.cat-fields label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cat-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.cat-count {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

.cat-errors {
  grid-column: 2 / -1;
  margin: 0;
  color: #ff8fa0;
  font-size: 14px;
}

/* ---------- save bar ---------- */

.savebar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--savebar-h);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-2);
  background: var(--bg-2);
  box-shadow: 0 -8px 24px rgb(0 0 0 / 0.4);
}

.savebar-text {
  flex: 1;
  min-width: 0;
}

.savebar-text strong {
  color: var(--changed);
}

.savebar-problems {
  color: #ff8fa0;
  margin-left: 8px;
}

.savebar-problems button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- dialogs ---------- */

dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--bg-2);
  color: var(--paper);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.7);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 50px);
}

.dialog-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font: 800 26px/1.1 var(--font-display);
}

.dialog-body {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.changes {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.change {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.change-title {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.change-kind {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.change-added .change-kind {
  color: var(--ok);
}

.change-changed .change-kind {
  color: var(--changed);
}

.change-removed .change-kind {
  color: #ff6b81;
}

.diff {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 8px 0 0;
  font-size: 14px;
}

.diff dt {
  color: var(--muted);
}

.diff dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.diff del {
  display: block;
  color: #ff8fa0;
  text-decoration: line-through;
}

.diff ins {
  display: block;
  color: #8be0b4;
  text-decoration: none;
}

.diff .none {
  color: var(--muted);
  font-style: italic;
}

.confirm-text {
  margin: 0;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--savebar-h) + 16px);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--bg);
  font-weight: 600;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.5);
}

/* ---------- small screens ---------- */

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

  .cat-fields label:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 800px) {
  .topbar .repo {
    display: none;
  }

  .last-commit {
    margin-left: 0;
  }

  #app {
    display: block;
    height: auto;
  }

  .workspace {
    display: block;
  }

  .cats {
    overflow: visible;
  }

  .listpane {
    border-right: 0;
  }

  .chantlist {
    overflow: visible;
  }

  .workspace.editing .listpane {
    display: none;
  }

  .workspace:not(.editing) .editorpane {
    display: none;
  }

  .back-btn {
    display: inline-flex;
  }

  .editor {
    padding: 12px 16px 48px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .round {
    grid-template-columns: 20px 1fr 34px;
  }

  .round .round-resp {
    grid-column: 2;
  }

  .cat-card {
    grid-template-columns: 1fr;
  }

  .cat-order {
    flex-direction: row;
  }

  .cat-side {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .cat-errors {
    grid-column: 1;
  }

  .savebar .btn-ghost {
    display: none;
  }
}
