/* ---------- Khung ung dung: menu trai (sidebar) + vung noi dung ---------- */
.app-shell {
  --sidebar-w: 232px;
  --sidebar-collapsed-w: 68px;
  --sidebar-current-w: var(--sidebar-w); /* dung chung cho thanh cham diem co dinh (study.css) */
  display: flex;
  min-height: 100vh;
}
.app-shell.sidebar-collapsed { --sidebar-current-w: var(--sidebar-collapsed-w); }
.app-main { flex: 1; min-width: 0; }

/* Cuon toi 1 phan tu (vd o nhap Han tu) khong bi thanh tren cung che */
html { scroll-padding-top: 72px; }

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 0 0 var(--sidebar-current-w);
  width: var(--sidebar-current-w);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 12px;
  background: linear-gradient(180deg, var(--red), var(--red-dark));
  color: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 40;
  transition: width 0.2s ease, flex-basis 0.2s ease;
}

.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 4px; min-height: 48px; }
.brand-mark {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 26px;
  font-weight: 900;
  width: 44px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
}
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.brand-text p { margin: 2px 0 0; font-size: 12px; opacity: 0.85; line-height: 1.3; }

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; }
.tab-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.tab-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.tab-btn.active { background: rgba(255, 255, 255, 0.22); color: #fff; }
.tab-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.nav-icon { flex: none; width: 28px; font-size: 20px; line-height: 1; text-align: center; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }

.sidebar-backdrop { display: none; }

/* ---------- Thanh tren cung ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar-toggle {
  flex: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.topbar-toggle:hover { background: var(--bg); }
.topbar-title { margin: 0; flex: 1; font-size: 17px; }
.word-count {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Man hinh rong: thu gon thanh cot icon ---------- */
@media (min-width: 901px) {
  .app-shell.sidebar-collapsed .brand-text,
  .app-shell.sidebar-collapsed .nav-label { display: none; }
  .app-shell.sidebar-collapsed .sidebar { padding-left: 8px; padding-right: 8px; }
  .app-shell.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
  .app-shell.sidebar-collapsed .tab-btn { justify-content: center; padding: 10px 0; }
}

/* ---------- Man hinh hep: menu la ngan keo (drawer) mac dinh an ---------- */
@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed { --sidebar-current-w: 0px; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 264px;
    height: auto;
    flex: none;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
    z-index: 50;
  }
  .app-shell.sidebar-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }
  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 45;
  }
  .topbar { padding: 10px 16px; }
}
