:root {
  /* site brand: dark #2c2d29, gold #dab162; --gold here is the darker shade that passes contrast with white text */
  --bg: #f6f4ef; --panel: #fff; --line: #e6e1d6; --text: #262622; --muted: #6b665c;
  --gold: #8a6d36; --gold-bright: #dab162; --gold-soft: #f6efdf; --accent: #2c2d29; --danger: #b3261e; --ok: #2e7d32;
  --radius: 12px; --shadow: 0 1px 2px rgb(40 35 20 / .05), 0 4px 14px rgb(40 35 20 / .05);
  --font: 'Heebo', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 400 16px/1.6 var(--font); color: var(--text); background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.main:focus { outline: none; }
.muted { color: var(--muted); font-size: 14px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 60px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--accent); color: #fff; position: sticky; top: 0; z-index: 20; border-bottom: 3px solid var(--gold-bright); }
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .spacer { flex: 1; }
.topbar a, .topbar span { color: #fff; font-size: 14px; text-decoration: none; opacity: .9; }
.topbar a:hover { opacity: 1; text-decoration: underline; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.side { background: var(--panel); border-left: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 60px; height: calc(100vh - 60px); overflow: auto; }
.side a { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.side a:hover { background: var(--bg); }
.side a.active { background: var(--gold-soft); color: var(--gold); font-weight: 700; box-shadow: inset -3px 0 0 var(--gold-bright); }
.main { padding: 28px clamp(16px, 4vw, 48px) 120px; max-width: 980px; width: 100%; }
.main h1 { font-size: 26px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; }

/* cards / list */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--text); display: block; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; }
.card:hover { border-color: var(--gold-bright); transform: translateY(-2px); }
.card .ic { font-size: 26px; }
.card b { display: block; margin-top: 6px; font-size: 17px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list a { display: flex; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.list a:last-child { border-bottom: 0; }
.list a:hover { background: var(--bg); }
.list .meta { color: var(--muted); font-size: 14px; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: #eee; color: var(--muted); margin-inline-start: 8px; }
.tag.draft { background: #fff3cd; color: #7a5a00; }
.toolbar-row { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-row input[type=search] { flex: 1; min-width: 180px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 16px; cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500; }
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger:hover { border-color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--gold); font-weight: 700; text-decoration: underline; cursor: pointer; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

/* form */
.field { margin-bottom: 22px; }
.field > label, .field > .label { display: block; font-weight: 700; margin-bottom: 6px; }
.help { color: var(--muted); font-size: 14px; margin: -2px 0 8px; }
input[type=text], input[type=search], input[type=datetime-local], input[type=url], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus, textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
input[readonly] { background: #f6f6f3; color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { width: 20px; height: 20px; accent-color: var(--gold); }
fieldset.group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 18px 18px 4px; margin: 0 0 22px; box-shadow: var(--shadow); }
fieldset.group > legend { font-weight: 700; font-size: 18px; padding: 0 8px; }
.items { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: var(--radius); background: #fcfbf8; }
.item > .item-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; }
.item > .item-head .t { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item > .item-body { padding: 4px 14px 2px; border-top: 1px solid var(--line); }
.item.closed > .item-body { display: none; }
.strings .row { display: flex; gap: 8px; margin-bottom: 8px; }

/* image field */
.img-field { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding: 10px; border: 2px dashed transparent; border-radius: var(--radius); margin: -10px; transition: background .15s, border-color .15s; }
.img-field.dragging, .dropzone.dragging, .modal .body.dragging { border-color: var(--gold-bright); background: var(--gold-soft); }
.img-field .thumb { padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: zoom-in; background: #eee; box-shadow: var(--shadow); }
.img-field .thumb img { width: 240px; height: 160px; object-fit: cover; display: block; }
.img-field .empty { width: 240px; height: 160px; border: 2px dashed var(--line); border-radius: 10px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; color: var(--muted); background: #fbfaf7; }
.img-field .actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; flex: 1; min-width: 200px; }
.img-field .actions .help { margin: 4px 0 0; }

/* image library */
.dropzone { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; justify-content: center; text-align: center; padding: 26px 16px; margin-bottom: 18px; border: 2px dashed #d9cfb8; border-radius: var(--radius); background: var(--panel); color: var(--muted); transition: background .15s, border-color .15s; }
.dropzone b { width: 100%; color: var(--text); font-size: 17px; }
.dropzone small { width: 100%; }
.dropzone.small { padding: 14px; margin-bottom: 12px; }
.modal .body { border: 2px dashed transparent; transition: background .15s; }
.preview { display: grid; grid-template-columns: minmax(0, 3fr) minmax(200px, 2fr); gap: 20px; align-items: start; }
.preview img { width: 100%; max-height: 60vh; object-fit: contain; background: #f2f0ea; border-radius: 10px; }
.preview dl { margin: 0; }
.preview dt { color: var(--muted); font-size: 13px; margin-top: 12px; }
.preview dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.preview ul { margin: 0; padding-inline-start: 18px; }

/* rich text */
.rte { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.rte:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.rte-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); background: #faf9f6; border-radius: 8px 8px 0 0; position: sticky; top: 60px; z-index: 5; }
.rte-bar button { border: 0; background: none; border-radius: 6px; padding: 4px 10px; min-width: 34px; cursor: pointer; font-size: 15px; }
.rte-bar button:hover { background: var(--gold-soft); }
.rte-bar button.on { background: var(--gold); color: #fff; }
.rte-bar .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.rte-content { padding: 14px 16px; min-height: 140px; outline: none; font-size: 17px; line-height: 1.5; direction: rtl; text-align: right; }
.rte-content p { margin: 0; }
.rte-content h2 { font-size: 22px; font-weight: 600; color: var(--gold); margin: 0; }
.rte-content h3 { font-size: 19px; font-weight: 600; color: var(--gold); margin: 0; }
.rte-content ul, .rte-content ol { padding-inline-start: 24px; margin: 0; }
.rte-content a { color: var(--gold); text-decoration: underline; }
.rte-content img { max-width: 100%; height: auto; border-radius: 6px; margin: 8px 0; }

/* save bar, toast, modal */
.savebar { position: fixed; bottom: 0; left: 0; right: 240px; background: var(--panel); border-top: 1px solid var(--line); padding: 12px clamp(16px, 4vw, 48px); display: flex; gap: 12px; align-items: center; z-index: 15; }
.savebar .state { color: var(--muted); font-size: 14px; flex: 1; }
.savebar .state.dirty { color: #7a5a00; }
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 24px rgb(0 0 0 / .2); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.banner { background: #fff3cd; border: 1px solid #f0d78c; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(900px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.modal.small { width: min(440px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
.modal .body { padding: 16px 18px; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.media-grid .tile { margin: 0; padding: 0 0 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; overflow: hidden; text-align: right; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; display: flex; flex-direction: column; gap: 6px; }
.media-grid .tile:hover, .media-grid .tile:focus-visible { border-color: var(--gold-bright); transform: translateY(-2px); }
.media-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #eee; }
.media-grid .name { padding: 0 10px; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-grid .tag { margin: 0 10px; align-self: flex-start; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.used { background: #e8f2e9; color: #285b2c; }
.tag.unused { background: #f1efe9; color: var(--muted); }
.history li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history { list-style: none; margin: 0; padding: 0; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .side { position: fixed; top: 60px; right: 0; width: 260px; z-index: 30; transform: translateX(100%); transition: transform .2s; box-shadow: -4px 0 20px rgb(0 0 0 / .15); }
  .side.open { transform: none; }
  .savebar { right: 0; }
  .topbar .who { display: none; }
  .preview { grid-template-columns: 1fr; }
  .img-field .thumb img, .img-field .empty { width: 100%; max-width: 320px; }
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(400px, 100%); box-shadow: 0 10px 40px rgb(0 0 0 / .06); }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: right; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; }
.login-err { color: var(--danger); min-height: 1.6em; margin: 0 0 8px; }
.link-btn { background: none; border: 0; color: #fff; font-size: 14px; opacity: .9; cursor: pointer; padding: 0; }
.link-btn:hover { opacity: 1; text-decoration: underline; }
