/* ===== Layout tổng ===== */
:root {
  --primary: #ff0000;
  --primary-weak: #ffe0e0;
  --text: #222;
  --muted: #555;
  --line: #eee;
  --shadow: 0 2px 5px rgba(0,0,0,0.1);

  --ring: 0 0 0 3px rgba(255,0,0,.15);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  display: flex;
  gap: 16px;
  padding: 16px;
  background: #fff;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 300px;
  background: linear-gradient(180deg, var(--primary-weak), #fff);
  padding: 15px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  height: fit-content;
}

.sidebar h3 {
  color: var(--primary);
  margin: 0 0 10px 0;
}

.story-section h4 {
  color: var(--primary);
  margin: 0 0 6px 0;
}

/* Danh sách truyện (có thumbnail bìa) */
#story-list {
  list-style: none;
  max-height: 400px;
  overflow-y: auto;
  padding-left: 0;
  margin: 0 0 10px 0;
}

/* scrollbar nhẹ nhàng */
#story-list::-webkit-scrollbar { width: 8px; }
#story-list::-webkit-scrollbar-thumb { background: #e6e6e6; border-radius: 8px; }
#story-list:hover::-webkit-scrollbar-thumb { background: #d2d2d2; }

#story-list li {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 30px 1fr auto; /* thumb | title | actions */
  gap: 8px;
  align-items: center;
  border-radius: 6px;
}

#story-list li:hover {
  background: var(--primary-weak);
}

#story-list img.thumb {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

/* Nút chọn truyện (title) */
.story-select {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  padding: 0;
  font: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.story-select:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; padding: 2px 4px; }

.story-item.active {
  background: #fff6f6;
  border: 1px solid #ffd2d2;
}
.story-item.active .story-select {
  font-weight: 700;
  text-decoration: underline;
}

/* Actions */
.story-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.story-actions button {
  background: #fff;
  border: 1px solid #ddd;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .2s, transform .05s;
}
.story-actions button:hover { background: #f9f9f9; }
.story-actions button:active { transform: translateY(1px); }

/* Nút xóa truyện (nếu còn dùng class này) */
.delete-story-btn {
  margin-left: 6px;
  padding: 4px 8px;
  font-size: 12px;
  background: #ff5555;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background .2s, transform .05s;
}
.delete-story-btn:hover { background: #e04646; }
.delete-story-btn:active { transform: translateY(1px); }

/* ===== Form chung (thêm truyện + chương) ===== */
.form-vertical,
#post-story-form,
#chapter-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#post-story-form input,
#post-story-form textarea,
#chapter-form input,
#chapter-form textarea {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font: inherit;
  font-size: 14px;
  background: #fff;
}
#post-story-form input:focus,
#post-story-form textarea:focus,
#chapter-form input:focus,
#chapter-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

#post-story-form button,
#chapter-form button {
  padding: 8px 12px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  transition: background .2s, transform .05s;
}
#post-story-form button:hover,
#chapter-form button:hover { background: #cc0000; }
#post-story-form button:active,
#chapter-form button:active { transform: translateY(1px); }

.btn-secondary { background: #aaa !important; color: #fff !important; }

/* ===== ẢNH BÌA TRUYỆN (upload + preview) ===== */
.cover-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  color: var(--text);
}
.cover-field input[type="file"] {
  padding: 6px 8px;
  border: 1px dashed #ddd;
  border-radius: 6px;
  background: #fff;
}
.cover-field input[type="file"]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.cover-preview {
  width: 140px;
  height: 180px;
  border: 2px dashed #cfe1d9;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b8a7a;
  background: #fafafa;
  overflow: hidden;
  font-size: 14px;
  user-select: none;
}
.cover-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== Main content ===== */
.main-article {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  min-width: 0;
}

/* ===== Khu vực chi tiết truyện + danh sách chương ===== */
#chapter-section { margin-top: 10px; }

#chapter-section h3 {
  color: var(--text);
  margin: 0;
}

#selected-story-intro {
  font-size: 14px;
  color: var(--muted);
  margin: 8px 0 12px 0;
}

/* Header truyện + nút */
.story-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.story-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.toggle-btn {
  cursor: pointer;
  font-size: 16px;
  color: var(--primary);
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  transition: background .2s, transform .05s ease;
}
.toggle-btn:hover { background: var(--primary-weak); }
.toggle-btn:active { transform: scale(0.98); }

.story-date {
  font-size: 12px;
  color: #888;
  margin-left: 5px;
}

/* Danh sách chương */
#chapter-list {
  list-style: none;
  padding-left: 0;
  max-height: 300px;
  overflow-y: auto;
  margin: 0 0 10px 0;
}

.chapter-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}
.chapter-left { max-width: calc(100% - 160px); }
.chapter-title { font-weight: 600; margin-bottom: 4px; }
.chapter-title a { color: inherit; text-decoration: none; }
.chapter-title a:hover { text-decoration: underline; }
.chapter-snippet { color: #555; margin-bottom: 4px; }
.chapter-meta { color: #888; font-size: 12px; }

.chapter-actions { display:flex; align-items:center; }
.chapter-actions button {
  margin-left: 6px;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: background .2s, transform .05s;
}
.chapter-actions button:hover { background: var(--primary-weak); }
.chapter-actions button:active { transform: translateY(1px); }

/* Nhóm nút trong form chương */
.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  body { gap: 12px; padding: 12px; }
}

@media (max-width: 768px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; margin: 0; }
  .main-article { width: 100%; }
  .chapter-left { max-width: 100%; }
  /* preview ảnh to hơn chút trên mobile */
  .cover-preview { width: 180px; height: 220px; }
}
