/* ================================================================
   Khung ứng dụng: màn đăng nhập, menu trái (sidebar), tiêu đề trang, vùng nội dung, toast.
   ================================================================ */
:root {
  --sb-w: 252px;
  --sb-bg: #17323a;
  --sb-bg-2: #1e3f49;
  --sb-ink: rgba(255, 255, 255, .78);
  --sb-ink-2: rgba(255, 255, 255, .5);
}

.brand-mark {
  flex: none; width: 28px; height: 28px; border-radius: 7px;
  background: linear-gradient(135deg, #f4f7f8 0%, #9fb0b6 45%, #e9eef0 55%, #7f9198 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}

/* ---------------------------------------------------------------- Đăng nhập */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 20% -10%, #24505d 0%, transparent 60%), var(--sb-bg);
}
.login-card {
  width: min(400px, 100%); background: var(--panel); border-radius: 12px; padding: 32px 28px 28px; box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; margin-bottom: 24px; }
.login-brand b { font-weight: 700; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card > p { margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn-block { margin-top: 6px; }

/* ---------------------------------------------------------------- Bố cục */
.shell { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns .18s ease; }
.shell.collapsed { --sb-w: 68px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; padding: 20px 24px 40px; container-type: inline-size; container-name: content; min-width: 0; }
body[data-page="calc"] .content { padding-bottom: 20px; }
.page { min-width: 0; }

/* ---------------------------------------------------------------- Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100dvh; z-index: 40; overflow: hidden;
  display: flex; flex-direction: column; background: var(--sb-bg); color: var(--sb-ink);
}
.sb-head { display: flex; align-items: center; gap: 8px; height: var(--header-h); padding: 0 12px 0 18px; flex: none; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 17px; white-space: nowrap; min-width: 0; flex: 1; }
.brand b { font-weight: 700; }
.brand-text { overflow: hidden; text-overflow: ellipsis; }
.sb-collapse {
  flex: none; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--sb-ink-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.sb-collapse:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-collapse svg, .sidebar svg, .hamburger svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sb-collapse svg { transition: transform .18s; }
.collapsed .sb-collapse svg { transform: rotate(180deg); }

.sb-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 10px; display: grid; align-content: start; gap: 2px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 40px; padding: 0 10px; border-radius: 8px; border: 0;
  background: transparent; color: var(--sb-ink); text-decoration: none; font-weight: 500; font-size: 14px; cursor: pointer; text-align: left;
  white-space: nowrap; position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-group.has-active > .nav-item { color: #fff; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-caret { display: inline-flex; color: var(--sb-ink-2); }
.nav-caret svg { width: 16px; height: 16px; transition: transform .15s; }
.nav-group.open .nav-caret svg { transform: rotate(90deg); }
.nav-sub { display: none; padding: 2px 0 6px 42px; position: relative; }
.nav-sub::before { content: ""; position: absolute; left: 20px; top: 2px; bottom: 8px; width: 1px; background: rgba(255,255,255,.12); }
.nav-group.open .nav-sub { display: grid; gap: 1px; }
.nav-subitem {
  display: block; padding: 7px 10px; border-radius: 6px; color: var(--sb-ink-2); text-decoration: none; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-subitem:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-subitem.active { color: #fff; background: rgba(232, 113, 10, .22); box-shadow: inset 2px 0 0 var(--primary); font-weight: 600; }
.nav-empty { margin: 4px 0; font-size: 12px; color: var(--sb-ink-2); white-space: normal; }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--hl); color: #fff;
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.nav-item.active .nav-badge { background: #fff; color: var(--primary); }

.sb-user { flex: none; display: grid; gap: 10px; padding: 12px 12px 14px; border-top: 1px solid rgba(255,255,255,.07); background: rgba(0,0,0,.12); }
.sb-who { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 4px; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--sb-bg-2); color: #fff; font-weight: 700; font-size: 13px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.user-text { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.user-text b { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-text small { color: var(--sb-ink-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14); background: transparent; color: var(--sb-ink); cursor: pointer; font-size: 13px; font-weight: 500;
}
.sb-logout:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-logout svg { width: 17px; height: 17px; }
.sb-logout .nav-label { flex: none; }
.sb-backdrop { display: none; }

/* Sidebar thu gọn (chỉ biểu tượng) */
.collapsed .sb-head { padding: 0; justify-content: center; flex-direction: column; gap: 0; }
.collapsed .brand { flex: none; }
.collapsed .brand-text, .collapsed .nav-label, .collapsed .nav-caret, .collapsed .nav-sub, .collapsed .user-text { display: none !important; }
.collapsed .sb-head { height: auto; padding: 14px 0 8px; gap: 8px; }
.collapsed .nav-item { justify-content: center; padding: 0; }
.collapsed .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
.collapsed .nav-group.has-active > .nav-item { background: rgba(232, 113, 10, .25); }
.collapsed .sb-user { justify-items: center; padding: 12px 0; }
.collapsed .sb-who { padding: 0; }
.collapsed .sb-logout { padding: 0; width: 34px; }

/* ---------------------------------------------------------------- Tiêu đề trang */
.page-header {
  position: sticky; top: 0; z-index: 30; height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.hamburger { display: none; flex: none; width: 38px; height: 38px; margin-left: -8px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; align-items: center; justify-content: center; }
.hamburger:hover { background: var(--hover); }
.ph-titles { flex: 1; min-width: 0; }
.ph-titles h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; }
.breadcrumb a { color: var(--ink-3); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span:last-child { color: var(--ink-2); }
.crumb-sep { color: var(--line-2); }
.ph-actions { display: flex; gap: 8px; flex: none; }
.notice { margin: 16px 24px 0; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-weight: 500; }

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 60;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 24px);
  padding: 10px 12px 10px 16px; border-radius: 10px; background: var(--brand); color: #fff; box-shadow: var(--shadow-lg); font-size: 14px;
}
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.toast-btn { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff; border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; font-weight: 600; }
body[data-page="calc"] .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
@media (min-width: 901px) { body[data-page="calc"] .toast { bottom: 20px; } }

/* ---------------------------------------------------------------- Điện thoại / máy tính bảng nhỏ: menu thành ngăn kéo */
@media (max-width: 900px) {
  :root { --header-h: 56px; }
  .shell, .shell.collapsed { grid-template-columns: minmax(0, 1fr); --sb-w: 280px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(var(--sb-w), 86vw); height: 100dvh;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  .nav-open .sidebar { transform: none; }
  .sb-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(10, 20, 25, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .nav-open .sb-backdrop { opacity: 1; pointer-events: auto; }
  /* Trong ngăn kéo luôn hiện đầy đủ chữ */
  .collapsed .brand-text, .collapsed .nav-label, .collapsed .nav-caret, .collapsed .user-text { display: revert !important; }
  .collapsed .nav-group.open .nav-sub { display: grid !important; }
  .collapsed .sb-head { flex-direction: row; height: var(--header-h); padding: 0 12px 0 18px; }
  .collapsed .nav-item { justify-content: flex-start; padding: 0 10px; }
  .collapsed .nav-badge { position: static; }
  .collapsed .sb-user { justify-items: stretch; padding: 12px 12px 14px; }
  .collapsed .sb-who { padding: 0 4px; }
  .collapsed .sb-logout { width: auto; padding: 0 10px; }
  .sb-collapse svg { transform: none !important; }
  .hamburger { display: inline-flex; }
  .page-header { padding: 0 12px; gap: 8px; }
  .ph-titles h1 { font-size: 17px; }
  .breadcrumb { display: none; }
  .ph-actions .btn { height: 34px; padding: 0 10px; font-size: 13px; }
  .content { padding: 12px 12px 32px; }
  body[data-page="calc"] .content { padding-bottom: 0; }
  .notice { margin: 12px 12px 0; }
}
@media (max-width: 520px) {
  /* Nút hành động trên tiêu đề: chỉ giữ nút chính */
  .ph-actions .btn-ghost { display: none; }
}
