/* ThanTho.Com — design tokens (brief mục 3.2). Phẳng, sáng, xanh sage trung tính. */
:root {
  --bg: #F5F8F6;
  --surface: #FFFFFF;
  --primary: #477A63;      /* tối hơn #51836C để chữ trắng đạt WCAG AA (4.9:1) */
  --primary-dark: #315C49;
  --accent: #719D89;
  --soft: #E5EFE8;
  --text: #344A3E;
  --muted: #526B5C;
  --border: #DFE8E2;
  --danger: #A2433B;
  --danger-soft: #FBEEEC;
  --warn-soft: #FFF6E0;
  --warn-text: #6B5310;
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  overflow-wrap: anywhere;
}
h1, h2, h3, p, ul, fieldset { margin: 0; padding: 0; }
ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
a { color: var(--primary-dark); text-underline-offset: 2px; }
a:hover { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 50;
  background: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.skip-link:focus { top: 8px; }

.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 20px; }

/* Header / footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; }
/* Logo chính thức (ảnh đã gồm slogan). Chỉ đặt CHIỀU RỘNG, chiều cao tự theo tỉ lệ gốc 560:165 => không bao giờ méo. */
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--text); min-height: 44px; padding: 6px 0; flex: 0 1 auto; min-width: 0; border-radius: var(--radius-sm); }
.brand-img { display: block; width: 264px; height: auto; max-width: 100%; }
.brand-context { font-size: 14px; color: var(--muted); white-space: nowrap; }
@media (max-width: 1024px) { .brand-img { width: 236px; } }
.header-nav { display: flex; gap: 4px; flex: none; }
.header-nav a { white-space: nowrap; }
.header-nav a, .site-footer nav a, .side-links a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px;
  font-size: 15px; text-decoration: none; color: var(--muted); border-radius: var(--radius-sm);
}
.header-nav a:hover, .site-footer nav a:hover, .side-links a:hover { color: var(--primary-dark); background: var(--soft); }
.site-footer { margin-top: 40px; border-top: 1px solid var(--border); background: var(--surface); }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; padding-top: 14px; padding-bottom: 14px; font-size: 14px; color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; }

/* Layout */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; padding-top: 24px; }
/* Giữ chỗ một màn hình cho vùng feed: chân trang nằm dưới nếp gấp ngay từ đầu nên không bị đẩy khi feed nạp xong (CLS).
   align-content: start để các hàng của lưới KHÔNG giãn ra lấp chỗ trống (nếu giãn, khung soạn bài sẽ nhảy lên khi feed nạp). */
.layout { min-height: 100vh; align-content: start; }
.sidebar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.main { display: grid; gap: 20px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; transition: background-color .12s ease;
  white-space: nowrap; flex: none; overflow-wrap: normal;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); color: #fff; }
.btn-soft { background: var(--soft); color: var(--primary-dark); }
.btn-soft:hover:not(:disabled) { background: #D6E5DB; }
.btn-ghost { border-color: var(--border); color: var(--text); background: var(--surface); }
.btn-ghost:hover:not(:disabled) { background: var(--soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #863630; }
.btn-block { width: 100%; }
.link-btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; margin: 0;
  border: 0; background: none; color: var(--muted); font-size: 14px; cursor: pointer; border-radius: var(--radius-sm);
  white-space: nowrap; flex: none;
}
.link-btn:hover { color: var(--primary-dark); background: var(--soft); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-soft); }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, legend { font-size: 14px; font-weight: 600; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; background: var(--surface);
  border: 1px solid #C5D3CA; border-radius: var(--radius-sm); line-height: 1.5;
}
textarea { resize: vertical; display: block; }
input::placeholder, textarea::placeholder { color: #6E8478; opacity: 1; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent); outline-offset: 0; border-color: var(--primary); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; font-weight: 400; min-height: 44px; padding: 10px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--primary); flex: none; }
.field-error, .form-error { font-size: 13.5px; color: var(--danger); }
.field-error:empty, .form-error:empty { display: none; }
.form-error { margin-bottom: 10px; }
.microcopy { font-size: 13.5px; color: var(--muted); margin: 10px 0; }

/* Identity */
.identity { padding: 0; }
.identity-details > summary {
  list-style: none; cursor: pointer; padding: 16px 20px; display: grid; gap: 2px; min-height: 44px; border-radius: var(--radius);
}
.identity-details > summary::-webkit-details-marker { display: none; }
.identity-title { font-size: 17px; font-weight: 700; color: var(--primary-dark); }
.identity-hint { font-size: 13.5px; color: var(--muted); }
.identity-form { padding: 0 20px 20px; }
.identity-active { padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.identity-active .microcopy { margin: 0; }
.who { display: flex; gap: 12px; align-items: center; }
.who-name { font-weight: 700; }
.who-meta { font-size: 14px; color: var(--muted); }
.pending-box { background: var(--warn-soft); color: var(--warn-text); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.pending-title { font-weight: 600; }
.pending-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid #F0E2B8; margin-top: 6px; padding-top: 4px; }
.pending-list .pending-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.values { display: grid; gap: 6px; padding: 4px 20px; color: var(--muted); font-size: 15px; }
.values li::before { content: "·"; color: var(--accent); font-weight: 700; margin-right: 8px; }
.side-links { display: flex; padding: 0 10px; }

/* Avatar: chữ cái đầu, không liên kết */
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--soft); color: var(--primary-dark); font-weight: 700; font-size: 16px; text-transform: uppercase; user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 13px; }
.avatar[data-tone="1"] { background: #E8EEF3; color: #3B566B; }
.avatar[data-tone="2"] { background: #F1EBE2; color: #6A5536; }
.avatar[data-tone="3"] { background: #EEE8F1; color: #5B4A6B; }
.avatar[data-tone="4"] { background: #E3F0EE; color: #2F5F5A; }

/* Composer */
.composer-title { font-size: 19px; font-weight: 700; margin-bottom: 12px; color: var(--primary-dark); }
.composer textarea { min-height: 112px; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.counter { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter[data-over="true"] { color: var(--danger); font-weight: 600; }
.notice { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14.5px; background: var(--soft); color: var(--primary-dark); }
.notice[data-kind="error"] { background: var(--danger-soft); color: #7A2E28; }
.notice[data-kind="warn"] { background: var(--warn-soft); color: var(--warn-text); }

/* Feed */
.feed { display: grid; gap: 14px; min-width: 0; }
.feed-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.feed-head h2 { font-size: 17px; font-weight: 700; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); flex: none; white-space: nowrap; }
/* Màn hình rất hẹp (≤359px): giữ tiêu đề feed và chỉ báo cập nhật trên cùng một dòng */
@media (max-width: 359px) {
  .feed-head { flex-wrap: nowrap; gap: 8px; }
  .feed-head h2 { font-size: 15.5px; min-width: 0; }
  .live { font-size: 12.5px; gap: 6px; }
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #B7C6BC; }
.live[data-state="ok"] .live-dot { background: var(--primary); }
.live[data-state="error"] .live-dot, .live[data-state="offline"] .live-dot { background: #C99A2E; }
.banner { background: var(--warn-soft); color: var(--warn-text); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14.5px; }
.new-posts {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; /* nổi, không đẩy bố cục */
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--accent);
  background: var(--surface); color: var(--primary-dark); font-weight: 600; font-size: 14.5px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(49, 92, 73, .18); max-width: 92vw; white-space: nowrap;
}
.new-posts:hover { background: var(--soft); }
.feed-list { display: grid; gap: 14px; }
.feed-state { text-align: center; color: var(--muted); padding: 8px 0; font-size: 15px; }
.feed-state:empty { display: none; }
.feed-state .btn { margin-top: 10px; }
.feed-more { display: flex; justify-content: center; }

.post { padding: 18px 20px 8px; }
.post-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.author-line { font-size: 15px; }
.author-name { font-weight: 700; }
.author-meta { color: var(--muted); font-size: 14px; }
.post-time { font-size: 13px; color: var(--muted); }
.post-body, .comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.post-body { font-size: 16px; }
.post-actions { display: flex; align-items: center; gap: 4px; margin: 6px -8px 0; }
.spacer { flex: 1; }
.thread { border-top: 1px solid var(--border); padding: 6px 0 10px; }
.comment-list { display: grid; gap: 4px; }
.comment { display: flex; gap: 10px; padding: 8px 0 0; }
.comment-main { min-width: 0; flex: 1; background: var(--bg); border-radius: var(--radius-sm); padding: 8px 12px 0; }
.comment-body { font-size: 15px; }
.comment-actions { display: flex; align-items: center; gap: 4px; margin-left: -8px; }
.comment-actions .post-time { padding-left: 8px; margin-right: auto; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.comment-input { min-height: 44px; max-height: 160px; resize: none; }
.post.is-removing, .comment.is-removing { opacity: .4; }

/* Toast + dialog */
.toast-region { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--primary-dark); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14.5px; pointer-events: auto; }
.toast[data-kind="error"] { background: #7A2E28; }
.dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: min(92vw, 440px); color: var(--text); }
.dialog::backdrop { background: rgba(40, 60, 50, .45); }
.dialog h2 { font-size: 18px; margin-bottom: 10px; color: var(--primary-dark); }
.dialog legend { margin-bottom: 6px; }
.dialog p { margin-bottom: 10px; }
.radio-list { display: grid; margin-bottom: 12px; }
.radio-list label { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-weight: 400; font-size: 15px; }
.radio-list input { width: 20px; height: 20px; accent-color: var(--primary); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* Trang thông tin */
.prose-page { padding-top: 24px; max-width: 800px; }
.prose { padding: 28px; }
.prose h1 { font-size: 26px; color: var(--primary-dark); margin-bottom: 12px; line-height: 1.3; }
.prose h2 { font-size: 18px; margin: 22px 0 8px; color: var(--primary-dark); }
.prose p { margin-bottom: 12px; }
.prose .lead { font-size: 17px; }
.prose .cta { margin: 18px 0 6px; }
.prose .cta .btn { text-decoration: none; }
.prose ul { list-style: disc; padding-left: 22px; margin-bottom: 12px; display: grid; gap: 6px; }

/* Mobile: một cột */
@media (max-width: 768px) {
  .wrap { padding: 0 12px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; padding-top: 14px; }
  .brand-img { width: 216px; }
  .brand { gap: 10px; }
  .brand-context { font-size: 12.5px; }
  .header-inner { gap: 8px; }
  .header-nav { gap: 0; }
  .header-nav a { padding: 0 7px; font-size: 14px; }
  .values, .side-links { display: none; }
  .card { padding: 16px; }
  .identity { padding: 0; }
  .identity-details > summary { padding: 14px 16px; padding-right: 44px; position: relative; }
  .identity-details > summary::after {
    content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: translateY(-70%) rotate(45deg);
  }
  .identity-details[open] > summary::after { transform: translateY(-30%) rotate(-135deg); }
  .identity-form { padding: 0 16px 16px; }
  .identity-active { padding: 16px; }
  .post { padding: 16px 16px 6px; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
  .prose { padding: 20px 16px; }
}
@media (max-width: 480px) { .brand-img { width: 192px; } }
/* Màn rất hẹp: logo một hàng riêng để slogan trong logo còn đọc được, menu xuống hàng dưới */
@media (max-width: 359px) {
  .header-inner { flex-wrap: wrap; justify-content: space-between; row-gap: 0; padding-bottom: 2px; }
  .brand { padding-bottom: 0; }
  .brand-img { width: 184px; }
  .header-nav { margin-left: -7px; }
  .header-nav a { font-size: 13.5px; }
}
@media (max-width: 360px) {
  .composer-bar .btn { padding: 0 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
