/*
 * CreativDB.
 *
 * Light and dark are both first-class: the palette follows the system by
 * default, and the header toggle writes an explicit data-theme that wins over
 * the media query in either direction.
 */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-alt: #f4f1ec;
  --text: #23201d;
  --muted: #6b645c;
  --border: #ded8d0;
  --accent: #4a3f8f;
  --accent-contrast: #ffffff;
  --danger: #a3322b;
  --focus: #4a3f8f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 6px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17161b;
    --surface: #1f1e25;
    --surface-alt: #26252d;
    --text: #e9e6e1;
    --muted: #a49d94;
    --border: #35333d;
    --accent: #a99cf5;
    --accent-contrast: #17161b;
    --danger: #f0857c;
    --focus: #a99cf5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #17161b;
  --surface: #1f1e25;
  --surface-alt: #26252d;
  --text: #e9e6e1;
  --muted: #a49d94;
  --border: #35333d;
  --accent: #a99cf5;
  --accent-contrast: #17161b;
  --danger: #f0857c;
  --focus: #a99cf5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

.wrap { max-width: 68rem; margin: 0 auto; padding: 0 1rem; }

a { color: var(--accent); }
a:hover { text-decoration: none; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------------------------ header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: baseline; justify-content: space-between;
  padding-top: 1rem; padding-bottom: 1rem;
}

.site-title { margin: 0; font-size: 1.5rem; letter-spacing: -.01em; }
.site-title a { color: inherit; text-decoration: none; }
.tagline { margin: .15rem 0 0; color: var(--muted); font-size: .9rem; }

.site-nav { display: flex; align-items: center; gap: 1rem; }
.site-nav a { text-decoration: none; font-size: .95rem; }
.site-nav a:hover { text-decoration: underline; }

.theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 50%; width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem;
  /* The shared `button` padding would leave a 4px content box inside these
     2rem, putting the glyph's top left corner at the middle of the circle.
     Centering is done here rather than by the text metrics, so a different
     glyph or font can't shift it off center again. */
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
}
.theme-toggle:hover { color: var(--text); }

.site-footer {
  margin-top: 3rem; padding: 1.5rem 0;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem;
}

main.wrap { padding-top: 1.5rem; padding-bottom: 2rem; }

/* ---------------------------------------------------------------- messages */

.messages { list-style: none; margin: 1rem 0 0; padding: 0; }
.message {
  padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: .5rem;
  background: var(--surface-alt); border-left: 3px solid var(--accent);
}
.message.error { border-left-color: var(--danger); }

/* ----------------------------------------------------------------- buttons */

button, .button-ish {
  font: inherit; font-size: .95rem;
  padding: .4rem .8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .button-ish:hover { border-color: var(--accent); }

button.primary, .button-ish.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
button.danger, .button-ish.danger { color: var(--danger); border-color: var(--border); }
button.danger:hover, .button-ish.danger:hover { border-color: var(--danger); }
button.small, .button-ish.small { padding: .2rem .5rem; font-size: .85rem; }

button[disabled] { opacity: .5; cursor: not-allowed; }
/* The wrapper carries the tooltip, since a disabled button gets no events. */
.blocked { cursor: help; display: inline-block; }

button.linkish {
  border: none; background: none; color: var(--accent);
  padding: 0; font-size: .95rem;
}
button.linkish:hover { text-decoration: underline; }

.inline-form { display: inline-flex; gap: .35rem; align-items: center; margin: 0; }

/* ------------------------------------------------------------ search form */

.search-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem;
}

.search-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.search-row input[type="text"] { flex: 1 1 18rem; }

input[type="text"], input[type="password"], input[type="url"], input[type="date"],
input[type="number"], input[type="file"], select, textarea {
  font: inherit;
  padding: .4rem .55rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  max-width: 100%;
}
textarea { width: 100%; font-family: var(--mono); font-size: .95rem; line-height: 1.55; }

.modifiers { margin-top: .9rem; border-top: 1px solid var(--border); padding-top: .6rem; }
.modifiers summary { cursor: pointer; color: var(--muted); font-size: .9rem; }

.modifier-grid {
  display: grid; gap: 1rem; margin-top: .9rem;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}
.modifier-wide { grid-column: 1 / -1; }
.modifier-label, .modifier label { font-size: .9rem; }
.modifier-label { display: block; font-weight: 600; margin-bottom: .35rem; }
.modifier-wide input[type="text"] { width: 100%; }

.inline-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline-controls ul { list-style: none; display: flex; gap: .6rem; margin: 0; padding: 0; }
.checkbox-row ul { list-style: none; display: flex; flex-wrap: wrap; gap: .75rem; margin: 0; padding: 0; }
.checkbox { display: inline-flex; align-items: center; gap: .35rem; }
.unit { color: var(--muted); font-size: .9rem; }

.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: .3rem 0 0; }
.form-errors {
  color: var(--danger); background: var(--surface-alt);
  border-left: 3px solid var(--danger); border-radius: var(--radius);
  padding: .6rem .9rem; margin: 0 0 1rem; list-style-position: inside;
}
.danger-text { color: var(--danger); }

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex; flex-wrap: wrap; gap: .25rem;
  border-bottom: 1px solid var(--border); margin-bottom: -1px;
}
.tab {
  padding: .45rem .9rem; text-decoration: none; color: var(--muted);
  border: 1px solid transparent; border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-alt); }
.tab.active {
  background: var(--surface); color: var(--text);
  border-color: var(--border); font-weight: 600;
}
.tab .count { color: var(--muted); font-size: .8rem; font-weight: 400; }

.tab-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius); padding: .5rem;
}

/* ------------------------------------------------------------------ table */

/* Wide tables scroll inside their own box; the page never scrolls sideways. */
.table-scroll { overflow-x: auto; }

table.entries { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.entries th, table.entries td {
  text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.entries th { font-size: .85rem; color: var(--muted); white-space: nowrap; }
table.entries th a { color: inherit; text-decoration: none; }
table.entries th a:hover { color: var(--text); }
table.entries th.sorted { color: var(--text); }
table.entries tbody tr:hover { background: var(--surface-alt); }
table.entries td.empty, .lookup-table td.empty { color: var(--muted); text-align: center; padding: 1.5rem; }
.col-length, .col-created { white-space: nowrap; }
.col-public, .col-mine { text-align: center; }

.pagination {
  display: flex; gap: 1rem; align-items: center; justify-content: center;
  padding: .8rem; font-size: .9rem;
}
.pagination .disabled { color: var(--muted); }
.page-of { color: var(--muted); }

.empty-state { color: var(--muted); padding: 2rem 0; text-align: center; }
.export-links { margin-top: 1.5rem; font-size: .85rem; color: var(--muted); }

/* ------------------------------------------------------------------ chips */

.chip, .chip-static {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 999px; padding: .1rem .6rem;
  font-size: .85rem; margin: .1rem .15rem .1rem 0;
}
.chip-static { text-decoration: none; color: var(--text); }
a.chip-static:hover { border-color: var(--accent); }

.chip-remove {
  border: none; background: none; color: var(--muted);
  padding: 0 0 0 .1rem; font-size: 1rem; line-height: 1; cursor: pointer;
}
.chip-remove:hover { color: var(--danger); }

.tag-input {
  position: relative;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); padding: .35rem; min-height: 5rem; cursor: text;
}
.tag-input:focus-within { border-color: var(--accent); }
.tag-input .chips { display: flex; flex-wrap: wrap; }
.tag-input input {
  border: none; background: none; padding: .25rem; min-width: 12rem;
  font: inherit; color: var(--text); outline: none;
}

.suggestions {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
  margin: .2rem 0 0; padding: .25rem; list-style: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 12rem; overflow-y: auto;
}
.suggestions li { padding: .3rem .5rem; border-radius: 4px; cursor: pointer; }
.suggestions li:hover, .suggestions li.active { background: var(--surface-alt); }

/* ------------------------------------------------------------------ forms */

.field { margin-bottom: 1.1rem; }
.field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field input[type="text"], .field input[type="password"],
.field input[type="url"], .field select { width: 100%; max-width: 32rem; }
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.with-button { display: flex; gap: .5rem; align-items: center; }
.with-button select, .with-button input[type="text"] { flex: 1 1 auto; }
fieldset.field { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
fieldset.field legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.checkboxes { display: flex; flex-wrap: wrap; gap: 1.2rem; align-items: center; }
.form-actions { display: flex; gap: .6rem; align-items: center; margin-top: 1.4rem; }
.settings-form, .login-form, .entry-form { max-width: 44rem; }
.inline-label { font-size: .85rem; color: var(--muted); }
.attachment-edit-list { list-style: none; padding: 0; margin: 0 0 .8rem; }
.attachment-edit-list li {
  display: flex; flex-wrap: wrap; gap: .75rem; align-items: center;
  padding: .4rem 0; border-bottom: 1px solid var(--border);
}

/* ----------------------------------------------------------------- modals */

dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); padding: 1.2rem; min-width: min(22rem, 90vw);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }
dialog.modal h3 { margin-top: 0; }
dialog.modal input[type="text"] { width: 100%; }
.modal-actions { display: flex; gap: .5rem; margin-top: 1rem; }
/* The duplicate-name warning, per spec: small, red, italic, under the field. */
.modal-warning {
  color: var(--danger); font-style: italic; font-size: .85rem; margin: .5rem 0 0;
}
.confirm-text { margin: .4rem 0; }

/* ---------------------------------------------------------------- details */

.entry-detail { max-width: 46rem; }
.entry-title { margin: 0; font-size: 1.8rem; line-height: 1.2; }
.attribution { margin: .3rem 0 1rem; color: var(--muted); }
.performed-by { font-style: italic; }
.no-attribution { color: var(--muted); }

.entry-meta {
  display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem;
  margin: 0 0 1.5rem; padding: .8rem 0; font-size: .9rem;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.entry-meta dt { color: var(--muted); }
.entry-meta dd { margin: 0; }

/* Poetry depends on its own line breaks and indentation; preserve both. */
.entry-content {
  white-space: pre-wrap;
  font-family: var(--serif);
  font-size: 1.05rem; line-height: 1.7;
  overflow-wrap: break-word;
}

.attachments { margin-top: 2rem; }
.attachment-list { list-style: none; padding: 0; }
.attachment { margin-bottom: 1rem; }
.attachment-label { margin: 0 0 .3rem; font-size: .9rem; }
.attachment audio { width: 100%; max-width: 34rem; }
.attachment img { max-width: 100%; height: auto; border-radius: var(--radius); }

.entry-footer { margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.record-times { color: var(--muted); font-size: .85rem; }
.entry-actions { display: flex; gap: .6rem; }

/* --------------------------------------------------------------- settings */

.lookup-group { margin-bottom: 2.5rem; }
.lookup-table { width: 100%; border-collapse: collapse; max-width: 42rem; }
.lookup-table th, .lookup-table td {
  text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border);
}
.lookup-table th { font-size: .85rem; color: var(--muted); }
.lookup-table .numeric { text-align: right; width: 6rem; }
.add-lookup { margin-top: .8rem; }
.settings-links ul { line-height: 1.9; }

/* ------------------------------------------------------------------ busy */

.busy {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .12);
  display: flex; align-items: center; justify-content: center;
}
.busy[hidden] { display: none; }
.busy-spinner {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .busy-spinner { animation-duration: 2.4s; }
}

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

@media (max-width: 40rem) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .entry-meta { grid-template-columns: 1fr; }
  .entry-meta dt { font-weight: 600; margin-top: .4rem; }
  .form-actions { flex-wrap: wrap; }
}
