/* ============================================================
   PROMPT VAULT — editorial / brutalist theme (ГРУНТ-inspired)
   ============================================================ */

:root {
  /* Light "paper" theme (default) */
  --paper:      #e9e4d5;
  --paper-2:    #e3ddca;
  --paper-3:    #dcd5bf;
  --ink:        #16140d;
  --ink-soft:   #514c3a;
  --ink-faint:  #908a76;
  --line:       #c6bfa8;
  --line-soft:  #d4cdb7;
  --dark:       #16140d;   /* black blocks */
  --on-dark:    #ece7d8;   /* text on black */
  --on-dark-dim:#a8a290;
  --badge-bg:   #16140d;
  --badge-fg:   #ece7d8;
  --frame:      #0a0a08;   /* outer frame */
  --star:       #16140d;

  --radius: 0px;
  --tick: #b3ab92;
  --sans: "Archivo", -apple-system, BlinkMacSystemFont, sans-serif;
  --display: "Anton", "Archivo", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

[data-theme="dark"] {
  --paper:      #222222;
  --paper-2:    #2a2a2a;
  --paper-3:    #323232;
  --ink:        #ece7d8;
  --ink-soft:   #b4ae9c;
  --ink-faint:  #837e6f;
  --line:       #3a3a3a;
  --line-soft:  #303030;
  --dark:       #ece7d8;   /* inverted blocks: light on dark */
  --on-dark:    #16140d;
  --on-dark-dim:#4a463a;
  --badge-bg:   #ece7d8;
  --badge-fg:   #16140d;
  --frame:      #181818;
  --star:       #ece7d8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--frame);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  padding: 10px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 280px 400px 1fr;
  height: calc(100vh - 20px);
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: var(--ink); }
::placeholder { color: var(--ink-faint); }
.hidden { display: none !important; }
em { font-style: normal; }

/* ---------- Reusable: corner ticks ---------- */
.ticked { position: relative; }
.ticked::before {
  content: "";
  position: absolute; inset: 5px;
  pointer-events: none;
  --s: 13px; --b: 1.5px; --c: var(--tick);
  background:
    linear-gradient(to right,  var(--c) var(--b), #0000 0) top left     / var(--s) var(--b),
    linear-gradient(to bottom, var(--c) var(--b), #0000 0) top left     / var(--b) var(--s),
    linear-gradient(to left,   var(--c) var(--b), #0000 0) top right    / var(--s) var(--b),
    linear-gradient(to bottom, var(--c) var(--b), #0000 0) top right    / var(--b) var(--s),
    linear-gradient(to right,  var(--c) var(--b), #0000 0) bottom left  / var(--s) var(--b),
    linear-gradient(to top,    var(--c) var(--b), #0000 0) bottom left  / var(--b) var(--s),
    linear-gradient(to left,   var(--c) var(--b), #0000 0) bottom right / var(--s) var(--b),
    linear-gradient(to top,    var(--c) var(--b), #0000 0) bottom right / var(--b) var(--s);
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.15s;
}
.ticked:hover::before, .ticked.active::before { opacity: 1; }

/* ---------- Reusable: corner-arrow buttons ---------- */
.corner-arrow { position: relative; overflow: hidden; }
.corner-arrow::after {
  content: "";
  position: absolute; top: 0; right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 9px 9px 0;
  border-color: transparent currentColor transparent transparent;
  opacity: 0.55;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 11px;
  padding: 16px 16px 18px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 42px; height: 42px;
  background: var(--dark); color: var(--on-dark);
  font-family: var(--display);
  font-size: 22px; letter-spacing: -0.02em;
  display: grid; place-items: center;
}
.brand-title {
  font-family: var(--display);
  font-size: 19px; line-height: 1.08;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.brand-sub { font-size: 11px; color: var(--ink-faint); margin-top: 4px; font-weight: 600; }

.theme-toggle {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  display: grid; place-items: center;
  font-size: 16px; color: var(--ink-soft);
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--dark); color: var(--on-dark); }
.theme-toggle .ic-sun { display: none; }
[data-theme="dark"] .theme-toggle .ic-sun { display: block; }
[data-theme="dark"] .theme-toggle .ic-moon { display: none; }

.nav { display: flex; flex-direction: column; padding: 10px; gap: 2px; border-bottom: 1px solid var(--line); }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px;
  color: var(--ink-soft);
  font-size: 13px; font-weight: 600; text-align: left; width: 100%;
  text-transform: uppercase; letter-spacing: 0.02em;
  transition: background 0.13s, color 0.13s;
}
.nav-item .ni-ic { font-size: 13px; width: 16px; text-align: center; }
.nav-item em { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--ink-faint); }
.nav-item:hover { background: var(--paper-3); color: var(--ink); }
.nav-item.active { background: var(--dark); color: var(--on-dark); }
.nav-item.active em { color: var(--on-dark-dim); }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-faint); padding: 16px 16px 8px; font-weight: 800;
}
.section-toggle { cursor: pointer; user-select: none; }
.section-toggle:hover { color: var(--ink-soft); }
.sec-caret {
  font-style: normal;
  width: 24px; height: 24px; flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 19px; line-height: 1; opacity: 1;
}
.tags-cloud.collapsed { display: none; }
.list-scroll.collapsed { display: none; }
.icon-btn {
  color: var(--ink-soft); border: 1px solid var(--line);
  width: 22px; height: 22px; display: grid; place-items: center;
  font-size: 15px; transition: background 0.13s, color 0.13s;
}
.icon-btn:hover { background: var(--dark); color: var(--on-dark); }
.icon-btn[hidden] { display: none; } /* атрибут hidden должен перебивать display:grid */
.icon-btn.lg { width: 34px; height: 34px; font-size: 16px; }
.icon-btn.danger:hover { background: var(--ink); color: var(--paper); }

.list-scroll { overflow-y: auto; max-height: 26vh; padding: 0 10px; }
.cat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  color: var(--ink-soft); font-size: 13px; width: 100%; text-align: left;
  font-weight: 500; transition: background 0.13s, color 0.13s;
}
.cat-item:hover { background: var(--paper-3); color: var(--ink); }
.cat-item.active { background: var(--dark); color: var(--on-dark); }
.cat-item .dot { width: 6px; height: 6px; background: currentColor; flex-shrink: 0; }
.cat-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cat-item .cnt { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.cat-item.active .cnt { color: var(--on-dark-dim); }
.cat-item .edit { opacity: 0; font-size: 12px; }
.cat-item:hover .edit { opacity: 0.6; }
.cat-item:hover .cnt { display: none; }
.cat-item .caret {
  width: 24px; height: 24px; flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 19px; line-height: 1; opacity: 1;
  cursor: pointer; border-radius: 2px;
  transition: background 0.12s, transform 0.12s;
}
.cat-item .caret:hover { background: var(--paper-3); transform: scale(1.15); }
.cat-item.active .caret:hover { background: rgba(255, 255, 255, 0.18); }
.cat-item .caret-empty { width: 24px; flex-shrink: 0; }
.cat-item.dragging { opacity: 0.45; }
.cat-item.drop-target { outline: 2px solid var(--ink); outline-offset: -2px; background: var(--paper-3); }
.cat-item.drop-before { box-shadow: inset 0 3px 0 var(--ink); }
.cat-item.drop-after { box-shadow: inset 0 -3px 0 var(--ink); }
.section-head.drop-target { outline: 2px dashed var(--ink); outline-offset: -3px; }
.cat-item .addsub { opacity: 0; font-size: 13px; line-height: 1; }
.cat-item:hover .addsub { opacity: 0.6; }
.cat-item .addsub:hover, .cat-item .edit:hover { opacity: 1; }

.tags-cloud { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 16px; overflow-y: auto; max-height: 16vh; }
.tag-chip {
  border: 1px solid var(--line); color: var(--ink-soft);
  padding: 3px 9px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em; transition: all 0.13s;
}
.tag-chip:hover { border-color: var(--ink); color: var(--ink); }
.tag-chip.active { background: var(--dark); color: var(--on-dark); border-color: var(--dark); }
.tag-chip .n { font-family: var(--mono); opacity: 0.55; margin-left: 4px; }

.sidebar-footer { margin-top: auto; padding: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; border-top: 1px solid var(--line); }
.sidebar-footer .ghost-btn { padding: 9px 4px; font-size: 10px; letter-spacing: 0.02em; text-align: center; }
.ghost-btn {
  flex: 1; padding: 10px; border: 1px solid var(--line);
  color: var(--ink); font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.06em; transition: background 0.13s, color 0.13s;
}
.ghost-btn:hover { background: var(--dark); color: var(--on-dark); }

/* ============================================================
   LIST COLUMN
   ============================================================ */
.list-col { background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.list-header { display: flex; gap: 8px; padding: 14px; border-bottom: 1px solid var(--line); align-items: stretch; }
.search-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.search-icon { position: absolute; left: 12px; font-size: 16px; opacity: 0.55; pointer-events: none; }
#search {
  width: 100%; background: var(--paper-2); border: 1px solid var(--line);
  padding: 10px 36px; outline: none; transition: border 0.13s;
  font-weight: 500;
}
#search:focus { border-color: var(--ink); }
.search-wrap kbd {
  position: absolute; right: 10px; border: 1px solid var(--line); color: var(--ink-faint);
  font-size: 11px; padding: 1px 6px; font-family: var(--mono); background: var(--paper);
}
.sort-select, .field {
  background: var(--paper-2); border: 1px solid var(--line);
  padding: 9px 11px; outline: none; transition: border 0.13s; font-weight: 500;
}
.sort-select:focus, .field:focus { border-color: var(--ink); }

.primary-btn {
  background: var(--dark); color: var(--on-dark);
  font-family: var(--display); font-size: 14px; letter-spacing: 0.03em;
  padding: 0 18px; white-space: nowrap; transition: opacity 0.13s;
  display: inline-flex; align-items: center;
}
.primary-btn:hover { opacity: 0.85; }
.primary-btn.corner-arrow::after { border-color: transparent var(--on-dark) transparent transparent; opacity: 0.7; }

.prompt-list { overflow-y: auto; flex: 1; padding: 14px; display: flex; flex-direction: column; gap: 0; }
.prompt-card {
  padding: 14px 13px;
  border: 1px solid var(--line);
  margin-top: -1px; /* collapse borders into a grid */
  cursor: pointer;
  background: var(--paper);
  transition: background 0.13s;
}
.prompt-card:first-child { margin-top: 0; }
.prompt-card:hover { background: var(--paper-2); }
.prompt-card.active { background: var(--paper-3); position: relative; z-index: 1; border-color: var(--ink); }
.pc-top { display: flex; align-items: flex-start; gap: 8px; }
.pc-title {
  font-family: var(--display); font-size: 16px; line-height: 1.06;
  text-transform: uppercase; flex: 1; letter-spacing: 0.01em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pc-star { color: var(--star); font-size: 13px; line-height: 1.2; }
.pc-snippet {
  color: var(--ink-soft); font-size: 12.5px; margin-top: 7px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pc-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 11px; }
.pc-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink); }
.badge {
  width: 18px; height: 18px; background: var(--badge-bg); color: var(--badge-fg);
  font-family: var(--display); font-size: 11px; display: inline-grid; place-items: center;
}
.pc-tag {
  font-size: 10px; color: var(--ink-faint); border: 1px solid var(--line);
  padding: 2px 7px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.pc-tag.used { font-family: var(--mono); }
.pc-cat mark, .pc-snippet mark, .pc-title mark { background: var(--ink); color: var(--paper); padding: 0 2px; }
.list-empty { text-align: center; color: var(--ink-faint); padding: 48px 20px; font-size: 13px; line-height: 1.6; }

/* ============================================================
   EDITOR COLUMN
   ============================================================ */
.editor-col { background: var(--paper-2); display: flex; flex-direction: column; overflow: hidden; }
.empty-state { margin: auto; text-align: center; color: var(--ink-soft); display: flex; flex-direction: column; gap: 18px; align-items: center; }
.empty-mark {
  width: 70px; height: 70px; border: 1.5px solid var(--line);
  display: grid; place-items: center; font-size: 34px; color: var(--ink-faint);
  font-family: var(--display);
}
.empty-state p { line-height: 1.4; font-weight: 600; text-transform: uppercase; font-size: 13px; letter-spacing: 0.04em; }
.editor-body { display: flex; flex-direction: column; height: 100%; }

.editor-tabs { display: flex; align-items: center; gap: 4px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 8px 14px; color: var(--ink-faint); font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.06em; transition: all 0.13s;
  border: 1px solid transparent;
}
.tab em { font-family: var(--mono); opacity: 0.6; margin-left: 3px; }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--dark); color: var(--on-dark); }
.editor-actions { margin-left: auto; display: flex; gap: 6px; }
#btn-fav.on { background: var(--dark); color: var(--on-dark); }

.tab-panel { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 13px; }
.title-input {
  background: transparent; border: none; outline: none; padding: 2px 0;
  font-family: var(--display); font-size: 30px; line-height: 1.02;
  text-transform: uppercase; letter-spacing: 0.005em;
}
.title-input::placeholder { color: var(--line); }
.row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.body-input, .notes-input {
  background: var(--paper); border: 1px solid var(--line);
  padding: 14px; outline: none; resize: vertical; line-height: 1.6; transition: border 0.13s;
}
.body-input { min-height: 300px; font-family: var(--mono); font-size: 13px; flex: 1; }
.notes-input { min-height: 60px; font-size: 13px; color: var(--ink-soft); }
.body-input:focus, .notes-input:focus { border-color: var(--ink); }

/* Экран заметки блокнота — та же колонка, что и редактор промпта */
.note-view { display: flex; flex-direction: column; height: 100%; padding: 20px; gap: 13px; }
.note-view-head { display: flex; align-items: center; justify-content: space-between; }
.note-view-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-faint); font-weight: 800; }
#note-body { font-family: var(--sans); font-size: 14px; min-height: 200px; }

.editor-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 4px; }
.editor-footer > div { display: flex; gap: 8px; }
.meta { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.02em; }
.editor-footer .ghost-btn, .editor-footer .primary-btn { flex: 0 0 auto; }
.primary-btn { padding: 11px 18px; }

/* Variables / Use */
.vars-form { display: flex; flex-direction: column; gap: 11px; }
.var-row { display: flex; flex-direction: column; gap: 5px; }
.var-row label { font-size: 11px; color: var(--ink); font-family: var(--mono); font-weight: 700; }
.var-row input, .var-row textarea {
  background: var(--paper); border: 1px solid var(--line); padding: 9px 11px; outline: none;
}
.var-row input:focus, .var-row textarea:focus { border-color: var(--ink); }
.no-vars { color: var(--ink-faint); font-size: 12.5px; line-height: 1.5; }
.preview-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 800; }
.preview {
  background: var(--dark); color: var(--on-dark); border: 1px solid var(--dark);
  padding: 15px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono);
  font-size: 13px; line-height: 1.65; flex: 1; overflow-y: auto; min-height: 120px;
}
.preview .filled { background: var(--on-dark); color: var(--dark); padding: 0 3px; }

/* Versions */
.versions { display: flex; flex-direction: column; gap: 10px; }
.version-item { background: var(--paper); border: 1px solid var(--line); padding: 14px; }
.version-item .vh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; gap: 10px; }
.version-item .vdate { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.version-item .vtitle { font-family: var(--display); font-size: 15px; text-transform: uppercase; }
.version-item .vbody { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); white-space: pre-wrap; max-height: 90px; overflow: hidden; line-height: 1.5; }
.version-item .restore {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink); border: 1px solid var(--line); padding: 6px 11px; white-space: nowrap;
}
.version-item .restore:hover { background: var(--dark); color: var(--on-dark); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--dark); color: var(--on-dark); padding: 12px 20px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  opacity: 0; pointer-events: none; transition: all 0.22s; z-index: 100;
  border: 1px solid var(--ink);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast::before { content: "▸ "; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1080px) {
  #app { grid-template-columns: 240px 1fr; }
  .editor-col { display: none; }
  #app.show-editor { grid-template-columns: 1fr; }
  #app.show-editor .sidebar, #app.show-editor .list-col { display: none; }
  #app.show-editor .editor-col { display: flex; }
}

/* ---------- Drag-and-drop импорт ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--frame) 78%, transparent);
  padding: 28px;
}
.drop-overlay[hidden] { display: none; }
.drop-box {
  background: var(--paper);
  border: 1px solid var(--line);
  outline: 2px dashed var(--ink);
  outline-offset: 10px;
  padding: 48px 64px;
  text-align: center;
  max-width: 520px;
  box-shadow: 14px 14px 0 var(--dark);
  pointer-events: none;
}
.drop-mark {
  font-family: var(--display);
  font-size: 64px;
  line-height: 1;
  color: var(--ink);
  animation: drop-bob 1s ease-in-out infinite;
}
@keyframes drop-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(6px); } }
.drop-title {
  font-family: var(--display);
  font-size: 34px;
  letter-spacing: 1px;
  margin-top: 12px;
  color: var(--ink);
}
.drop-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 8px;
}

/* ---------- Иллюстрации к промпту ---------- */
.img-block { margin: 10px 0 2px; }
.img-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.img-strip:empty { display: none; }
.img-thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border: 1px solid var(--line);
  background: var(--paper-3);
  overflow: hidden;
  display: block;
}
.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.img-del {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  background: var(--dark);
  color: var(--on-dark);
  border: 1px solid var(--paper);
  opacity: 0;
  transition: opacity .12s;
}
.img-thumb:hover .img-del { opacity: 1; }
.img-drop {
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  background: var(--paper-2);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: center;
}
.img-drop.full { opacity: .45; }
.link-btn {
  font: inherit;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.img-strip.ro { margin-top: 12px; }
.img-strip.ro:empty { display: none; }
