/* Admin panel. Plain and functional; independent of the public design. */

:root {
  --bg: #f6f6f4; --surface: #fff; --text: #1d1d1b; --muted: #6b6a66; --rule: #dedcd6;
  --accent: #1d1d1b; --ok: #1d6b35; --warn: #8a5a00; --error: #a32020; --focus: #2a5bd7;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
body.admin { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
a { color: inherit; }
img { max-width: 100%; height: auto; display: block; }
code { font-size: 0.9em; background: #ecebe7; padding: 0.05em 0.3em; border-radius: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.ok { color: var(--ok); }
.warning { color: var(--warn); }
.error, .danger { color: var(--error); }
.optional { font-weight: 400; color: var(--muted); font-size: 0.85em; }

/* Header */
.admin-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem;
  padding: 0.75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--rule);
}
.admin-brand { font-weight: 600; text-decoration: none; }
.admin-header nav ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin: 0; padding: 0; list-style: none; }
.admin-header nav a { text-decoration: none; color: var(--muted); }
.admin-header nav a[aria-current="page"], .admin-header nav a:hover { color: var(--text); }
.admin-header nav a[aria-current="page"] { text-decoration: underline; text-underline-offset: 0.3em; }
.admin-account { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.admin-account form { margin: 0; }
.badge { display: inline-block; min-width: 1.4em; padding: 0 0.35em; border-radius: 1em; background: var(--text); color: #fff; font-size: 0.75rem; text-align: center; }

.admin-main { max-width: 84rem; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 0.75rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }

.flash { background: #eef5ee; border: 1px solid #c9dfca; padding: 0.6rem 0.85rem; border-radius: 4px; }
.flash--error { background: #f8eded; border-color: #e6c6c6; color: var(--error); }

.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.panel--notice { border-color: #e3cf9d; background: #fdf8ea; }
.panel--notice ul { margin: 0; padding-left: 1.2rem; }

/* Buttons */
.button, .link-button {
  font: inherit; cursor: pointer;
}
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 0.9rem; border: 1px solid var(--accent); border-radius: 4px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 500; line-height: 1.2;
}
.button:disabled { opacity: 0.5; cursor: default; }
.button--quiet { background: transparent; color: var(--text); border-color: var(--rule); }
.button--accent { background: var(--ok); border-color: var(--ok); }
.button--danger { background: transparent; color: var(--error); border-color: #e2bcbc; }
.button--small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.button--block { width: 100%; }
.link-button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; }

/* Forms */
.field { margin: 0 0 1rem; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend, .field > .label, .sublabel { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.9rem; }
.sublabel { margin-top: 0.75rem; }
input[type="text"], input:not([type]), input[type="date"], input[type="email"], select, textarea {
  width: 100%; font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--rule); border-radius: 4px; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
[aria-invalid="true"] { border-color: var(--error) !important; }
.input-title { font-size: 1.35rem; font-weight: 600; }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix span { padding: 0.5rem 0.4rem 0.5rem 0.6rem; background: #ecebe7; border: 1px solid var(--rule); border-right: 0; border-radius: 4px 0 0 4px; color: var(--muted); }
.input-prefix input { border-radius: 0 4px 4px 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0 0; }
.field-error { color: var(--error); font-size: 0.85rem; margin: 0.3rem 0 0; }
.field-error:empty { display: none; }
.checkbox, .radio { display: flex; align-items: center; gap: 0.4rem; font-weight: 400; }
.needs-attention { border-color: #e3cf9d; background: #fffbea; }

/* Editor layout */
.editor-layout { display: grid; gap: 1rem; }
@media (min-width: 64rem) {
  .editor-layout { grid-template-columns: minmax(0, 1fr) 20rem; align-items: start; }
  .panel--sticky { position: sticky; top: 1rem; z-index: 2; }
}
.editor-main { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem; }
.save-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.save-message { margin: 0.6rem 0 0; font-size: 0.9rem; }
.save-message:empty { display: none; }
.restore-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; background: #fdf8ea; border: 1px solid #e3cf9d; border-radius: 6px; padding: 0.6rem 0.85rem; margin-bottom: 1rem; }
.restore-banner[hidden] { display: none; }
.restore-banner p { margin: 0; }
.danger-zone { margin-top: 2rem; }
.status { display: inline-block; font-size: 0.8rem; padding: 0.1rem 0.5rem; border-radius: 1em; border: 1px solid var(--rule); }
.status--published { border-color: #b5d3bc; background: #eef5ee; color: var(--ok); }
.status--draft { background: #f1f0ec; color: var(--muted); }

/* Quill */
.editor { background: #fff; }
.editor .ql-editor { min-height: 22rem; font: 17px/1.65 Georgia, "Iowan Old Style", serif; }
.editor--small .ql-editor { min-height: 8rem; font-size: 15px; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--rule); }
.ql-toolbar.ql-snow { position: sticky; top: 0; background: #fff; z-index: 1; border-radius: 4px 4px 0 0; }
.ql-container.ql-snow { border-radius: 0 0 4px 4px; }
.ql-editor figure.ql-photo { margin: 1rem 0; padding: 0.5rem; border: 1px dashed var(--rule); border-radius: 4px; cursor: pointer; text-align: center; user-select: none; }
.ql-editor figure.ql-photo:hover { border-color: var(--text); }
.ql-editor figure.ql-photo img { margin: 0 auto; max-height: 18rem; width: auto; }
.ql-editor figure.ql-photo[data-size="text"] img { max-height: 12rem; }
.ql-editor figure.ql-photo figcaption { font: 13px/1.4 var(--sans); color: var(--muted); margin-top: 0.4rem; }
.ql-editor figure.ql-photo::after { content: attr(data-size) " width · click to edit"; display: block; font: 11px var(--sans); color: var(--muted); margin-top: 0.3rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* Image fields */
.image-field { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-start; }
.image-field__preview { flex: 0 1 18rem; }
.image-field--small .image-field__preview { flex-basis: 10rem; }
.image-field__preview img { max-height: 14rem; width: auto; border: 1px solid var(--rule); }
.image-field__preview p { margin: 0.3rem 0 0; }
.image-field__buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.image-field:not(.has-image) [data-clear] { display: none; }

/* Project photo list */
.photo-list { display: grid; gap: 0.5rem; margin-bottom: 0.75rem; }
.photo-row { display: grid; grid-template-columns: 6rem minmax(0, 1fr) auto; gap: 0.75rem; align-items: center; padding: 0.5rem; border: 1px solid var(--rule); border-radius: 4px; background: #fff; }
.photo-row img { max-height: 5rem; width: auto; margin: 0 auto; }
.photo-row__fields p { margin: 0.25rem 0 0; }
.photo-row__buttons { display: flex; gap: 0.25rem; }
@media (max-width: 40rem) {
  .photo-row { grid-template-columns: 4rem minmax(0, 1fr); }
  .photo-row__buttons { grid-column: 1 / -1; }
}

/* Dialogs */
dialog { border: 1px solid var(--rule); border-radius: 8px; padding: 1rem; max-width: min(64rem, calc(100vw - 2rem)); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.photo-dialog { max-width: 28rem; }
.photo-dialog fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.photo-dialog legend { font-weight: 600; margin-bottom: 0.3rem; }
.photo-dialog label { display: block; margin-bottom: 0.3rem; }
.photo-dialog__buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.picker__head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.picker__head h2 { margin: 0 auto 0 0; }
.picker__grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: 0.5rem; max-height: 65vh; overflow: auto; }
.picker__item { position: relative; width: 100%; height: 8.5rem; padding: 0.25rem; border: 2px solid transparent; border-radius: 4px; background: #f1f0ec; cursor: pointer; }
.picker__item img { max-width: 100%; max-height: 100%; width: auto; margin: 0 auto; object-fit: contain; }
.picker__item[aria-pressed="true"] { border-color: var(--focus); background: #e6ecfb; }
.picker__flag { position: absolute; left: 0.25rem; bottom: 0.25rem; font-size: 0.7rem; background: #fffbea; padding: 0 0.3rem; border-radius: 2px; }
.picker__foot { display: flex; justify-content: flex-end; margin-top: 0.75rem; }

/* Media library */
.upload-log { margin: 0.5rem 0 0; padding-left: 1.2rem; font-size: 0.9rem; }
.media-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 1rem; }
.media-item { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.media-item__image { display: flex; align-items: center; justify-content: center; height: 12rem; background: #f1f0ec; }
.media-item__image img { max-height: 12rem; width: auto; }
.media-item__info { padding: 0.75rem; }
.media-item__info p { margin: 0 0 0.4rem; }
.media-form label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.media-form input { margin-top: 0.2rem; font-weight: 400; }

/* Tables and lists */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; }
.table th, .table td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.table tr.unread td { font-weight: 600; }
.row-actions { white-space: nowrap; text-align: right; }
.order-buttons { display: flex; gap: 0.25rem; }
.order-buttons form { margin: 0; }
@media (max-width: 40rem) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; }
  .table tr { border-bottom: 1px solid var(--rule); padding: 0.4rem 0; }
  .table td { border: 0; padding: 0.2rem 0.7rem; }
  .row-actions { text-align: left; }
}
.stats { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; }
.stats a { display: block; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 0.75rem; text-decoration: none; color: var(--muted); }
.stats strong { display: block; font-size: 1.5rem; color: var(--text); }
.plain-list { margin: 0; padding-left: 1.2rem; }
.message-body { white-space: normal; max-width: 42rem; line-height: 1.6; }
.settings-form { max-width: 42rem; }

/* Login */
.admin-login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-box { width: 100%; max-width: 22rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 1.5rem; }
.login-box h1 { margin-bottom: 1.25rem; }

/* Staging tray and gallery approval */
.badge--quiet { background: var(--muted); }
.staging__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; position: sticky; top: 0; z-index: 2; }
.staging__bar input[type="search"] { flex: 1 1 14rem; }
.staging-item__pick { display: block; position: relative; cursor: pointer; }
.staging-item__pick input { position: absolute; top: 0.5rem; left: 0.5rem; width: 1.2rem; height: 1.2rem; z-index: 1; }
.staging-item__pick input:checked + .media-item__image { outline: 3px solid var(--focus); outline-offset: -3px; }
.pending { color: var(--warn); }
.key-value { display: flex; gap: 0.5rem; }
.key-value input { flex: 1; font-family: ui-monospace, monospace; }
