/* ============ HDC Study — Giáo trình web ============ */

:root {
  --brand: #0f3d5c;
  --brand-dark: #082238;
  --brand-light: #e8f1f8;
  --accent: #f59e0b;
  --text: #1c1e21;
  --text-muted: #64748b;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --sidebar-w: 300px;
  --topbar-h: 60px;
  --content-max: 780px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg-soft);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Topbar ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow-md);
  gap: 16px;
}
.brand {
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  background: var(--accent);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-name { font-weight: 600; }

.menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  flex-direction: column;
  gap: 4px;
}
.menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

.search-wrap {
  flex: 1;
  max-width: 320px;
  margin-left: auto;
}
.search-wrap input {
  width: 100%;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: background 0.15s;
}
.search-wrap input::placeholder { color: rgba(255, 255, 255, 0.7); }
.search-wrap input:focus { background: rgba(255, 255, 255, 0.25); }

.edit-link {
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  white-space: nowrap;
}
.edit-link:hover { background: rgba(255, 255, 255, 0.1); text-decoration: none; }

/* ============ Layout ============ */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
  overflow-y: auto;
}
.sidebar-inner { padding: 20px 0; }
.sidebar-header {
  padding: 0 20px 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.chapter-nav { display: flex; flex-direction: column; }
.chapter-nav a {
  padding: 10px 20px;
  color: var(--text);
  border-left: 3px solid transparent;
  font-size: 14px;
  line-height: 1.5;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}
.chapter-nav a:hover {
  background: var(--brand-light);
  text-decoration: none;
}
.chapter-nav a.active {
  background: var(--brand-light);
  border-left-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
}
.chapter-nav a.hidden { display: none; }

/* ============ Viewer ============ */
.viewer {
  background: var(--bg);
  min-height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
}
.viewer-inner {
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: 40px 32px 60px;
  flex: 1;
}

/* Content typography */
.viewer-inner h1 {
  font-size: 28px;
  color: var(--brand-dark);
  margin: 48px 0 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--brand-light);
  line-height: 1.3;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.viewer-inner h1:first-child { margin-top: 0; }
.viewer-inner h2 {
  font-size: 22px;
  color: var(--brand);
  margin: 36px 0 16px;
  line-height: 1.35;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.viewer-inner h3 {
  font-size: 18px;
  color: var(--text);
  margin: 28px 0 12px;
  line-height: 1.4;
}
.viewer-inner h4 {
  font-size: 16px;
  margin: 24px 0 10px;
}
.viewer-inner p {
  margin: 12px 0;
  font-size: 16px;
  line-height: 1.75;
}
.viewer-inner ul, .viewer-inner ol {
  margin: 12px 0;
  padding-left: 28px;
}
.viewer-inner li {
  margin: 6px 0;
  line-height: 1.7;
}
.viewer-inner strong { font-weight: 700; color: var(--brand-dark); }
.viewer-inner em { color: var(--text); }

.viewer-inner img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.viewer-inner table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
  overflow: hidden;
}
.viewer-inner th, .viewer-inner td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}
.viewer-inner th {
  background: var(--brand-light);
  color: var(--brand-dark);
  font-weight: 600;
}
.viewer-inner tr:nth-child(even) td { background: var(--bg-soft); }

.viewer-inner blockquote {
  border-left: 4px solid var(--accent);
  padding: 8px 20px;
  margin: 20px 0;
  background: #fffbeb;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.viewer-inner hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* Chuẩn hoá style của Google Docs */
.viewer-inner .c1, .viewer-inner .c2, .viewer-inner .c3,
.viewer-inner [class^="c"] {
  font-family: inherit !important;
}
.viewer-inner span[style*="color"] { color: inherit !important; }
.viewer-inner span[style*="font-family"] { font-family: inherit !important; }
.viewer-inner p[style*="text-align"] { text-align: inherit !important; }
.viewer-inner body { max-width: none !important; padding: 0 !important; }

/* Loading */
.loading-hero {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 20px; color: var(--text-muted); font-size: 14px; }
.tiny { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.viewer-footer {
  padding: 24px 32px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

/* Chapter pager (prev/next) */
.chapter-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.chapter-pager > a {
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
}
.chapter-pager > a:hover {
  border-color: var(--brand);
  background: var(--brand-light);
  text-decoration: none;
}
.pager-next { text-align: right; align-items: flex-end; }
.pager-label { font-size: 12px; color: var(--text-muted); }
.pager-title { font-weight: 600; color: var(--brand-dark); margin-top: 4px; }

@media (max-width: 600px) {
  .chapter-pager { grid-template-columns: 1fr; }
}

/* Error */
.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 16px 20px;
  border-radius: var(--radius);
  margin: 20px 0;
}

/* Backdrop cho mobile menu */
.backdrop {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 90;
}
.backdrop.show { display: block; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 280px;
  }
  .menu-btn { display: flex; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: var(--sidebar-w);
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 95;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .brand-name { display: none; }
  .search-wrap { max-width: 200px; }
  .edit-link { display: none; }
  .viewer-inner { padding: 24px 20px 48px; }
  .viewer-inner h1 { font-size: 24px; }
  .viewer-inner h2 { font-size: 19px; }
}

@media (max-width: 500px) {
  .search-wrap { display: none; }
  .brand-name { display: none; }
  .viewer-inner { padding: 20px 16px 40px; }
}
