/* ===== Модульная сетка закладок ===== */

:root {
  --gap: 20px;
  --cell: 100px;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #26292f;
  --text-pale: #9aa0aa;
  --accent: #3b82f6;
  --border: #dfe2e7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
  --shadow-hover: 0 12px 24px -4px rgba(16, 24, 40, .18), 0 4px 8px -2px rgba(16, 24, 40, .10);
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0 12px;
}

/* ===== Шапка ===== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(243, 244, 246, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e5e7eb;
}

.topbar-inner {
  max-width: 1420px;
  margin: 0 auto;
  padding: 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 14px;
}

.crumb {
  border: 0;
  background: none;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  transition: background .15s ease;
}

.crumb:hover { background: #e5e7eb; }

.crumb.current {
  color: var(--text);
  cursor: default;
  font-weight: 500;
}

.crumb.current:hover { background: none; }

.crumb-sep { color: var(--text-pale); }

.mode-switch {
  display: inline-flex;
  background: #e5e7eb;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.mode-switch button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #4b5563;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}

.mode-switch button:hover { color: var(--text); }

.mode-switch button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* ===== Контейнер и сетка ===== */

.container {
  max-width: 1420px;
  margin: 0 auto;
  padding: 8px 0 60px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin: 14px 0 20px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-edit-btn { flex: 0 0 auto; }

.title-input {
  font-family: inherit;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 4px 10px;
  margin: 14px 0 20px;
  width: 100%;
  max-width: 480px;
}

.title-input:focus { outline: 2px solid rgba(59, 130, 246, .35); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--cell));
  grid-auto-rows: var(--cell);
  grid-auto-flow: dense;
  gap: var(--gap);
  justify-content: center;
}

.empty-note {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-pale);
  padding: 40px 0;
  font-size: 14px;
}

/* ===== Карточки ===== */

.card {
  position: relative;
  display: block;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

a.card, .card.clickable { cursor: pointer; }

.size-small  { grid-column: span 1; grid-row: span 1; }
.size-middle { grid-column: span 2; grid-row: span 1; }
.size-long   { grid-column: span 4; grid-row: span 1; }
.size-big    { grid-column: span 4; grid-row: span 2; }

/* Small: только фавиконка по центру */
.size-small {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Фавиконка: строго 64×64, одинаковый отступ слева и сверху на всех карточках */
.card-icon {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  display: block;
  border-radius: 14px;
  object-fit: scale-down;
  background: #eef0f3;
}

/* Middle / Long: иконка слева, текст справа */
.card-body {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
}

.card-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.card-desc {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.35;
}

.card-url {
  font-size: 12px;
  font-weight: 300;
  color: var(--text-pale);
}

/* Middle / Long: описание и URL строго в одну строку с многоточием */
.size-middle .card-desc,
.size-middle .card-url,
.size-long .card-desc,
.size-long .card-url {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Big: текст физически обтекает фавиконку справа и снизу */
.size-big .card-icon {
  float: left;
  margin: 0 14px 8px 0;
}

.size-big .card-url { margin-top: 6px; }

/* ===== Режим редактирования ===== */

body[data-mode="edit"] .card { cursor: grab; }

.card.dragging {
  opacity: .45;
  cursor: grabbing;
}

.card-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s ease;
}

body[data-mode="edit"] .card-controls { opacity: 1; }

.card-btn {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: #f1f2f4;
  color: #4b5563;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  transition: background .15s ease, color .15s ease;
}

.card-btn:hover { background: #e2e4e8; }

.card-btn.danger:hover { background: #fee2e2; color: #dc2626; }

/* ===== Панель редактирования ===== */

.edit-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 18px;
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background .15s ease, box-shadow .15s ease;
}

.btn:hover { background: #f6f7f9; box-shadow: var(--shadow); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: #2f6fe0; }

/* ===== Исходный код ===== */

.source-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.source-hint {
  font-size: 13px;
  color: var(--text-pale);
}

.source-view pre {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 0;
  overflow: auto;
  max-height: 70vh;
  font-size: 13px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  user-select: text;
}

/* ===== Модальное окно ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .2);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal h2 {
  margin: 0 0 2px;
  font-size: 18px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #4b5563;
}

.field input,
.field select,
.field textarea {
  font: inherit;
  color: var(--text);
  border: 1px solid #d7dae0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}

.field textarea { resize: vertical; }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(59, 130, 246, .35);
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* ===== Адаптивность ===== */

/* Вьюпорт уже 4 колонок: широкие карточки занимают всю ширину сетки */
@media (max-width: 483px) {
  .size-long, .size-big { grid-column: 1 / -1; }
}

@media (max-width: 243px) {
  .size-middle { grid-column: 1 / -1; }
}
