:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #5f6672;
  --line: #dfe2e8;
  --accent: #b4531f;
  --accent-soft: #fdf1ea;
  --danger: #a3271f;
  --ok: #1d6b45;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  background: #1b1e23;
  color: #e8eaee;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 22px 20px 16px; border-bottom: 1px solid #2c3037; }
.brand strong { display: block; font-size: 20px; letter-spacing: .08em; }
.brand span { font-size: 12px; color: #949aa5; text-transform: uppercase; letter-spacing: .12em; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c9ced7;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nav button:hover { background: #262a31; color: #fff; }
.nav button.active { background: var(--accent); color: #fff; }
.nav button .mark { width: 7px; height: 7px; border-radius: 50%; background: #f0a35f; flex: none; }

.sidebar-foot { flex: none; padding: 14px 20px 16px; border-top: 1px solid #2c3037; font-size: 11.5px; color: #949aa5; }
.sidebar-foot p { margin: 0 0 6px; }
.sidebar-foot code { font-family: var(--mono); color: #e8eaee; }

/* ------------------------------------------------------------------- main */

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 20px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; max-width: 70ch; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex: none; }

.dirty { font-size: 12px; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 4px 10px; }

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

.search-wrap { position: relative; }
#search {
  width: 260px;
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: min(620px, 70vw);
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(7, 24, 19, .18);
}
.results[hidden] { display: none; }
.results .no-hits { margin: 0; padding: 12px; color: var(--muted); font-size: 13px; }
.hit {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 9px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.hit:hover, .hit:focus-visible { background: var(--accent-soft); }
.hit-where { color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.hit-value { color: var(--ink); font-size: 13px; line-height: 1.45; }

@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.flash { animation: flash 1.8s ease-out; border-radius: 8px; }

.btn { border-radius: 8px; border: 1px solid var(--line); padding: 8px 16px; font: inherit; cursor: pointer; background: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: #e4c4c1; }

.errors {
  margin: 16px 28px 0;
  padding: 12px 16px;
  border: 1px solid #e4c4c1;
  background: #fdf1f0;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 14px;
}
.errors ul { margin: 6px 0 0; padding-left: 18px; }
.errors code { font-family: var(--mono); font-size: 12px; }

.editor { padding: 24px 28px 80px; display: flex; flex-direction: column; gap: 18px; }

/* ------------------------------------------------------------------ groups */

.group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.group > summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--muted); font-size: 12px; }
.group[open] > summary::before { content: "▾"; }
.group > summary .count { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.group-body { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 14px; }

.locale-tabs { display: flex; gap: 6px; padding: 0 18px 12px; }
.locale-tabs button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.locale-tabs button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.locale-tabs .btn-translate { margin-inline-start: auto; }

.btn-translate { border-color: var(--accent); color: var(--accent); background: #fff; white-space: nowrap; }
.btn-translate:hover:not(:disabled) { background: var(--accent-soft); }
.translate-row { display: flex; }

/* ------------------------------------------------------------------ fields */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field .note { font-size: 12px; color: var(--muted); }
.note.warn { color: var(--accent); font-weight: 600; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 78px; resize: vertical; line-height: 1.6; }
.short input[type="text"], .short input[type="number"] { max-width: 240px; }

[dir="rtl"] { text-align: right; }

.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.checkbox label { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); }

/* -------------------------------------------------------------- list items */

.items { display: flex; flex-direction: column; gap: 8px; }
.item-row { display: flex; gap: 8px; align-items: flex-start; }
.item-row > :first-child { flex: 1; min-width: 0; }
.item-tools { display: flex; gap: 4px; flex: none; }
.item-tools button { width: 30px; height: 34px; padding: 0; line-height: 1; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfbfc; }
.card > summary {
  cursor: pointer;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary .idx { font-family: var(--mono); font-size: 12px; color: var(--muted); flex: none; }
.card > summary .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card > summary .item-tools { margin-left: auto; }
.card-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; }

.add-row { display: flex; }

/* ------------------------------------------------------------------ images */

.image-field { display: flex; gap: 14px; align-items: flex-start; }
.image-preview {
  width: 132px;
  height: 96px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f0f1f4 center/contain no-repeat;
}
.image-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.image-meta code { font-family: var(--mono); font-size: 12px; word-break: break-all; color: var(--muted); }
.image-actions { display: flex; }
.image-actions button { width: auto; white-space: nowrap; }

/* -------------------------------------------------------------- image grid */

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.tile .thumb { height: 130px; background: #f0f1f4 center/contain no-repeat; }
.tile .meta { padding: 10px 12px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.tile .meta strong { color: var(--ink); font-size: 13px; word-break: break-all; }
.tile .used { color: var(--ok); }
.tile .unused { color: var(--muted); }
.tile .actions { padding: 0 12px 12px; }

/* ------------------------------------------------------------------- modal */

.modal { position: fixed; inset: 0; background: rgba(20, 22, 26, .55); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border-radius: 12px; width: min(940px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.upload, .upload-folder { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.upload-folder select { max-width: 280px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.picker-grid button { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0; cursor: pointer; overflow: hidden; text-align: left; }
.picker-grid button.selected { outline: 2px solid var(--accent); }
.picker-grid .thumb { height: 104px; background: #f0f1f4 center/contain no-repeat; }
.picker-grid .name { padding: 8px 10px; font-size: 11px; color: var(--muted); word-break: break-all; font-family: var(--mono); }

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

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 40;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}
