@import url('https://fonts.googleapis.com/css2?family=Literata:ital,wght@0,300;0,400;0,500;1,300;1,400&family=IBM+Plex+Sans:wght@300;400;500&display=swap');

:root {
  --bg:            #f5f2ee;
  --bg-panel:      #faf8f5;
  --bg-card:       #fff;
  --bg-card-hover: #f7f5f1;
  --border:        #e0d8ce;
  --border-soft:   #ede8e0;

  --text:       #2c2825;
  --text-muted: #7a6f65;
  --text-faint: #b0a598;

  --accent:     #3d5a80;
  --accent-lt:  #d6e4f0;
  --accent-dim: #6b8fb5;

  --orange:    #c4732a;
  --orange-lt: #faebd7;
  --red:       #b04040;
  --red-lt:    #fce8e8;
  --green:     #3a7d44;
  --green-lt:  #d8f0dc;

  --radius:    6px;
  --radius-lg: 10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 2px 12px rgba(0,0,0,.10);

  --font-body:  'IBM Plex Sans', sans-serif;
  --font-serif: 'Literata', Georgia, serif;

  --header-h:  48px;
  --sidebar-w: 240px;
}

[x-cloak] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

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

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Header ── */
.header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-logo {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-stats {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  flex-wrap: nowrap;
}
.mobile-actions { display: none; }

.header-collection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--accent-lt);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--accent);
  flex-shrink: 0;
}
.header-collection-bar button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  opacity: .7;
  padding: 0;
  line-height: 1;
}
.header-collection-bar button:hover { opacity: 1; }

/* ── Layout ── */
.layout {
  display: flex;
  align-items: flex-start;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: 180px;
  max-width: 400px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-resizer {
  width: 6px;
  cursor: col-resize;
  background: var(--border-soft);
  flex-shrink: 0;
  position: relative;
  align-self: stretch;
  transition: background .15s;
}
.sidebar-resizer::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: -6px; right: -6px;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging { background: var(--accent); opacity: 0.5; }

.main-content { flex: 1; min-width: 0; }

/* ── Search (sidebar top) ── */
.sidebar-search {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border-soft);
}

.search-wrap { position: relative; }

.search-input {
  width: 100%;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent-dim); }
.search-input::placeholder { color: var(--text-faint); }

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}
.search-clear:hover { color: var(--text-muted); }

.date-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--accent-dim);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 100;
  overflow-y: auto;
}
.date-dropdown-item {
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text);
}
.date-dropdown-item:hover { background: var(--accent-lt); color: var(--accent); }

/* ── Sidebar filters ── */
.filter-group {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.filter-group:last-child { border-bottom: none; }

.filter-heading {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 6px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  line-height: 1.3;
}
.filter-item input[type="checkbox"],
.filter-item input[type="radio"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
}

.filter-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-faint);
  min-width: 20px;
  text-align: right;
}
.filter-item--dim { color: var(--border); }
.filter-item--dim .filter-count { color: var(--border-soft); }

/* Toggle switch */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 2px 0; }
.toggle-label { font-size: 13px; color: var(--text-muted); }

.toggle-switch { position: relative; display: inline-block; width: 38px; height: 21px; cursor: pointer; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 21px; transition: .2s; }
.toggle-slider:before { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(17px); }

/* Sort select */
.sort-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  cursor: pointer;
  outline: none;
}
.sort-select:focus { border-color: var(--accent-dim); }

/* Buttons */
.reset-btn {
  width: 100%;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background .12s;
}
.reset-btn:hover { background: var(--bg-card-hover); color: var(--text); }

.text-btn {
  width: 100%;
  padding: 5px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: color .12s;
}
.text-btn:hover { color: var(--text-muted); border-color: var(--accent-dim); }

.icon-btn {
  padding: 4px 7px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-card-hover); }
.icon-btn--danger:hover { background: var(--red-lt); border-color: var(--red); color: var(--red); }

.col-edit-btn { color: var(--text-faint); background: none; border: none; cursor: pointer; font-size: 13px; flex-shrink: 0; line-height: 1; padding: 0 2px; }
.col-edit-btn:hover { color: var(--accent); }

/* ── Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  padding: 20px;
  align-content: start;
}

/* ── Cards ── */
.card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 12px 14px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* author + date zone */
.card-meta {
  padding: 0 14px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
}

.author {
  font-weight: 500;
  font-size: 13.5px;
  flex: 1;
  min-width: 0;
}

.date {
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.badge-approx {
  font-size: 10px;
  color: var(--orange);
  background: var(--orange-lt);
  border: 1px solid var(--orange);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.4;
}
.badge-copy {
  font-size: 10px;
  color: var(--red);
  background: var(--red-lt);
  border: 1px solid var(--red);
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.4;
}
.badge-hidden {
  font-size: 10px;
  color: var(--text-faint);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.4;
}

.source-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-lt);
  color: var(--accent);
  white-space: nowrap;
  font-weight: 500;
}

/* Dropdown "add to collection" items */
.add-to-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}
.add-to-item input[type="checkbox"] { flex-shrink: 0; accent-color: var(--accent); }
.col-chip--untagged { background: #f7fafc; color: #a0aec0; }
.col-chip--tag { background: #e6fffa; color: #2c7a7b; }
.add-to-item--active { background: var(--bg-panel); color: var(--text); }

/* Collection chips on card */
.col-chip {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  background: #eef2ff;
  color: #667eea;
  font-weight: 500;
  white-space: nowrap;
}

/* Card body */
.card-body { padding: 12px 14px; flex: 1; }

.review-text {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.note-preview {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
  border-left: 2px solid var(--border);
  padding-left: 8px;
}

/* Card footer */
.card-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}

.card-footer a,
.card-footer button {
  padding: 4px 9px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  text-decoration: none;
  font-size: 12px;
  color: var(--text-muted);
  transition: background .12s, color .12s;
  line-height: 1.4;
}
.card-footer a:hover,
.card-footer button:hover {
  background: var(--bg-card-hover);
  color: var(--text);
  text-decoration: none;
}

/* Top button */
.top-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--border); transition: color .15s; padding: 0; line-height: 1; flex-shrink: 0; }
.top-btn.active { color: var(--orange); }
.top-btn:hover { color: var(--orange); opacity: .7; }

/* ── Date filter banner ── */
.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-lt);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 7px 14px;
  margin: 12px 20px 0;
  font-size: 12.5px;
  color: var(--accent);
}
.date-filter-bar button {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  padding: 0;
  opacity: .7;
}
.date-filter-bar button:hover { opacity: 1; }

/* ── Group header ── */
.group-header {
  margin: 8px 20px 4px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.post-group-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.post-group-link:hover { text-decoration: underline; }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--text-faint);
  text-align: center;
}
.empty-state p { font-size: 15px; margin-bottom: 14px; }
.empty-reset-btn {
  padding: 8px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
}
.empty-reset-btn:hover { opacity: .85; }

/* ── Actions menu ── */
.actions-menu-item {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: none; background: none;
  cursor: pointer; font-size: 13px; color: var(--text);
  border-radius: var(--radius); white-space: nowrap;
}
.actions-menu-item:hover { background: var(--bg-card-hover); }
.actions-menu-item:disabled { opacity: 0.4; cursor: default; }

/* ── Linked projects ── */
.linked-projects-menu { position: relative; }
.linked-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
}
.linked-btn:hover { background: var(--bg-card-hover); }
.linked-dropdown { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); min-width: 180px; overflow: hidden; z-index: 100; }
.linked-projects-menu:hover .linked-dropdown { display: block; }
.linked-dropdown a { display: block; padding: 8px 12px; color: var(--text-muted); font-size: 13px; }
.linked-dropdown a:hover { background: var(--bg-card-hover); text-decoration: none; color: var(--text); }

/* ── Misc ── */
.loading { text-align: center; padding: 80px 24px; color: var(--text-faint); font-size: 15px; }

.error-box {
  background: var(--red-lt);
  border: 1px solid var(--red);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 24px;
  color: var(--red);
  line-height: 1.6;
}
.error-box strong { display: block; font-size: 15px; margin-bottom: 8px; }
.error-box code { display: inline-block; margin-top: 10px; background: var(--text); color: var(--green-lt); padding: 6px 12px; border-radius: var(--radius); font-family: monospace; font-size: 12px; }

/* ── Screenshots ── */
.screenshot-drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 12px;
  margin-bottom: 8px;
  transition: .15s;
}
.screenshot-drop-zone:hover { border-color: var(--accent-dim); color: var(--accent); }
.screenshot-wrap { position: relative; margin-bottom: 8px; }
.screenshot-img { width: 100%; border-radius: var(--radius); display: block; cursor: zoom-in; }
.screenshot-del {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px;
  border-radius: 50%; background: rgba(0,0,0,.5); border: none; color: white;
  font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.screenshot-del:hover { background: rgba(176,64,64,.85); }

/* ── Modals ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 1000; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.modal-img { max-width: 92vw; max-height: 92vh; border-radius: var(--radius); box-shadow: 0 8px 40px rgba(0,0,0,.5); cursor: default; }
.modal-close { position: fixed; top: 20px; right: 24px; background: none; border: none; color: white; font-size: 28px; cursor: pointer; opacity: .8; }
.modal-close:hover { opacity: 1; }
.modal-embed-box { background: var(--bg-card); border-radius: var(--radius-lg); padding: 20px; width: 520px; max-width: 92vw; box-shadow: var(--shadow-md); }

/* ── Selection ── */
.card-checkbox { position: absolute; top: 12px; left: 12px; width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; z-index: 2; }
.card-selected { outline: 2px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-lt); }

.select-mode-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: background .12s;
}
.select-mode-btn:hover { background: var(--bg-card-hover); color: var(--text); }

.collection-create-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.collection-create-btn:disabled { opacity: .5; cursor: default; }

.active-collection-bar {
  background: var(--accent-lt);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 3px 10px;
  font-size: 12px;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.active-collection-bar button { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 14px; opacity: .7; padding: 0; line-height: 1; }
.active-collection-bar button:hover { opacity: 1; }

/* ── Highlights ── */
mark.hl { background: var(--orange-lt); border-radius: 2px; padding: 1px 2px; }

/* ── Sidebar inline form inputs ── */
.sidebar-input {
  width: 100%;
  margin-bottom: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}
.sidebar-input:focus { border-color: var(--accent-dim); }

.save-btn {
  flex: 1;
  padding: 6px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.cancel-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--bg-card);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-muted);
}

.col-form {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 6px;
  margin-bottom: 4px;
}

/* ── Showcase ── */
.showcase-page { max-width: 900px; margin: 0 auto; padding: 24px 20px; }
.showcase-header { text-align: center; margin-bottom: 14px; }
.showcase-header h1 { font-size: 28px; color: var(--text); font-weight: 500; }
.showcase-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 20px; }
.showcase-card { background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 18px; box-shadow: var(--shadow); }
.showcase-footer { text-align: center; margin-top: 60px; padding: 40px; background: var(--bg-panel); border-radius: var(--radius-lg); }
.showcase-cta { display: inline-block; margin-top: 16px; padding: 12px 28px; background: var(--accent); color: white; border-radius: var(--radius-lg); text-decoration: none; font-size: 15px; font-weight: 500; }
.showcase-cta:hover { opacity: .9; text-decoration: none; }

body.embed-mode { background: transparent; }
body.embed-mode .showcase-page { padding: 12px; }

@media (max-width: 640px) {
  .showcase-page { padding: 14px 12px; }
  .showcase-header { margin-bottom: 14px; }
  .showcase-header h1 { font-size: 22px; }
  .showcase-header p { font-size: 14px; }
  .showcase-grid { grid-template-columns: 1fr; gap: 14px; }
  .showcase-footer { margin-top: 36px; padding: 24px 16px; }
}

/* ── Mobile editor ── */
.mobile-search-bar { display: none; }
.mobile-filters-btn { display: none; }

@media (max-width: 768px) {
  /* Layout: одна колонка */
  .layout { flex-direction: column; align-items: stretch; }

  /* Сайдбар: раскладывается на всю ширину, не sticky */
  .sidebar {
    position: static !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }
  .sidebar.mobile-hidden { display: none; }

  /* Прячем встроенный поиск сайдбара (на мобиле он в mobile-search-bar) */
  .sidebar .sidebar-search { display: none; }

  .sidebar-resizer { display: none; }

  /* Поисковая строка поверх карточек */
  .mobile-search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: var(--header-h);
    z-index: 5;
  }

  .mobile-filters-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12.5px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .mobile-filters-btn.active {
    background: var(--accent-lt);
    border-color: var(--accent-dim);
    color: var(--accent);
  }

  /* Карточки — одна колонка */
  .grid { grid-template-columns: 1fr; padding: 0 8px; }

  /* Заголовок группы — нормальный перенос */
  .group-header {
    margin: 8px 8px 4px;
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Хедер: убрать лишнее на малых экранах */
  .header-stats { display: none; }
  .header-actions { display: none; }
  .mobile-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 0 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
}

/* ── PNG export ── */
.exporting .card-footer,
.exporting .card-checkbox,
.exporting .screenshot-del,
.exporting .screenshot-drop-zone,
.exporting .top-btn,
.exporting .badge-hidden,
.exporting .note-editor { display: none !important; }
.exporting-with-screenshot .review-text,
.exporting-with-screenshot .note-preview { display: none !important; }
