/* ── Content page ──────────────────────────────────────────────────────────── */

.ct-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 12px 16px;
  margin-bottom: 20px;
}

.ct-toolbar__label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.ct-type-toggle { display: flex; gap: 4px; }

.ct-type-btn {
  padding: 5px 13px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-app);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.ct-type-btn:hover { background: var(--bg-hover); }
.ct-type-btn--active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.ct-type-btn--paid.ct-type-btn--active  { background: var(--orange); border-color: var(--orange); }
.ct-type-btn--free.ct-type-btn--active  { background: var(--blue);   border-color: var(--blue);   }

/* ── Card grid ─────────────────────────────────────────────────────────────── */

.ct-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.ct-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 16px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ct-card:hover {
  border-color: #c0cad8;
  box-shadow: var(--shadow-sm);
}

.ct-card__head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ct-card__name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
  line-height: 1.35;
}

/* Status badge — top-right of card */
.ct-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}
.ct-status-badge--draft     { background: #f1f5f9; color: #64748b; }
.ct-status-badge--ready     { background: #fff7ed; color: var(--orange); }
.ct-status-badge--published { background: #dcfce7; color: #166534; }
.ct-status-badge--archive   { background: #f1f5f9; color: #94a3b8; }

.ct-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.ct-card__meta-item { display: flex; align-items: center; gap: 4px; }
.ct-card__meta-item svg { width: 12px; height: 12px; flex-shrink: 0; opacity: .7; }

.ct-card__dates {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.ct-card__dates svg { width: 12px; height: 12px; flex-shrink: 0; }

.ct-card__chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  overflow: hidden;
  min-width: 0;
}
.ct-chip {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 1;
}

.ct-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Content grouped layout ────────────────────────────────────────────────── */

.ct-content-groups {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
}

.ct-content-groups .period-group__head {
  padding: 13px 20px;
}

.ct-content-groups .period-group__total { display: none; }

.ct-grid--ingroup {
  padding: 16px 20px;
}

/* ── Modal overlay ─────────────────────────────────────────────────────────── */

.ct-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 900;
  opacity: 0;
  transition: opacity .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ct-modal-overlay--visible { opacity: 1; }

/* ── Modal window ──────────────────────────────────────────────────────────── */

.ct-modal {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(1180px, 97vw);
  height: min(760px, 95vh);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,.22);
  z-index: 901;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: scale(.97) translateY(6px);
  transition: opacity .2s, transform .2s cubic-bezier(.4,0,.2,1);
  pointer-events: none;
}
.ct-modal--open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.ct-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ct-modal__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: calc(100% - 48px);
}

.ct-modal__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.ct-modal__close svg { width: 16px; height: 16px; }
.ct-modal__close:hover { background: var(--bg-hover); }

/* ── Two-column body ───────────────────────────────────────────────────────── */

.ct-modal__body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.ct-modal__left {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ct-modal__right {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */

.ct-modal__foot {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.ct-modal__foot .spacer { flex: 1; }

.ct-modal__del {
  color: var(--red) !important;
  border-color: var(--red) !important;
}
.ct-modal__del:hover { background: #fff0f0 !important; }

/* ── Form fields ───────────────────────────────────────────────────────────── */

.ct-field { display: flex; flex-direction: column; gap: 5px; }
.ct-field__label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; }
.ct-field__input, .ct-field__select, .ct-field__textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-card);
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.ct-field__textarea { resize: none; min-height: 80px; }
.ct-field__input:focus, .ct-field__select:focus, .ct-field__textarea:focus {
  border-color: var(--border-focus);
}

.ct-field__row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Type toggle inside modal */
.ct-toggle-group { display: flex; gap: 6px; }
.ct-toggle-btn {
  flex: 1;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-app);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: center;
  transition: all .15s;
}
.ct-toggle-btn:hover { background: var(--bg-hover); }
.ct-toggle-btn--free.ct-toggle-btn--active  { background: var(--blue-light); color: var(--blue); border-color: var(--blue); font-weight: 600; }
.ct-toggle-btn--paid.ct-toggle-btn--active  { background: var(--orange-light); color: var(--orange); border-color: var(--orange); font-weight: 600; }

/* ── Content pane (preview + edit toggle) ──────────────────────────────────── */

.ct-content-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 16px 20px;
  gap: 10px;
  overflow: hidden;
}

.ct-content-pane__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ct-content-pane__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  cursor: text;
}

.ct-edit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-app);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.ct-edit-toggle svg { width: 13px; height: 13px; }
.ct-edit-toggle:hover { border-color: var(--green); color: var(--green); }
.ct-edit-toggle--active { background: var(--green); color: #fff; border-color: var(--green); }
.ct-edit-toggle--active:hover { background: var(--green-dark, #0e8c01); }

/* ── Editor textarea ───────────────────────────────────────────────────────── */

.ct-field__textarea--editor {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: none;
  font-family: 'JetBrains Mono', 'Fira Code', 'Menlo', monospace;
  font-size: 13px;
  line-height: 1.65;
  padding: 14px 16px;
  color: var(--text-primary);
  background: var(--bg-card);
  box-sizing: border-box;
}
.ct-field__textarea--editor:focus { outline: none; border-color: var(--border-focus); }

/* ── Tag picker ─────────────────────────────────────────────────────────────── */

.ct-tags-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 38px;
  cursor: text;
  transition: border-color .15s;
  position: relative;
}
.ct-tags-wrap:focus-within { border-color: var(--border-focus); }

.ct-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px 2px 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.ct-tag__rm {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 1px;
  border: none;
  background: none;
}
.ct-tag__rm:hover { color: var(--red); }

.ct-tags-input {
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
  min-width: 100px;
  flex: 1;
}

.ct-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
}
.ct-dropdown-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}
.ct-dropdown-item:last-child { border-bottom: none; }
.ct-dropdown-item:hover { background: var(--bg-hover); }
.ct-dropdown-item--dim { color: var(--text-muted); font-size: 12px; }

/* ── Markdown preview rendering ────────────────────────────────────────────── */

.md-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  word-break: break-word;
}

.md-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

.md-p  { margin: 0 0 10px; }

.md-h1 { font-size: 22px; font-weight: 700; margin: 0 0 12px; color: var(--text-primary); border-bottom: 2px solid var(--border); padding-bottom: 6px; }
.md-h2 { font-size: 18px; font-weight: 700; margin: 18px 0 8px; color: var(--text-primary); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-h3 { font-size: 15px; font-weight: 600; margin: 14px 0 6px; color: var(--text-primary); }
.md-h4 { font-size: 13.5px; font-weight: 600; margin: 10px 0 4px; color: var(--text-secondary); }

.md-hr { border: none; border-top: 2px solid var(--border); margin: 16px 0; }

.md-ul, .md-ol { margin: 0 0 10px 0; padding-left: 22px; }
.md-ul li, .md-ol li { margin-bottom: 3px; }
.md-ul { list-style: disc; }
.md-ol { list-style: decimal; }

.md-table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0 14px;
  font-size: 13px;
}
.md-table th, .md-table td {
  border: 1px solid var(--border);
  padding: 7px 11px;
  text-align: left;
}
.md-table thead { background: var(--bg-stripe, #f5f7fa); }
.md-table th { font-weight: 600; font-size: 12px; color: var(--text-secondary); }
.md-table tr:nth-child(even) { background: var(--bg-stripe, #f9fafb); }

.md-pre {
  background: #1e2433;
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0 14px;
}
.md-code-block {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12.5px;
  color: #e2e8f0;
  white-space: pre;
}

/* inline code (inside md-body) */
.md-body code:not(.md-code-block) {
  background: #eef0f3;
  color: #c0392b;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
