/* ===================================================================
   BỐ CỤC KHUNG ỨNG DỤNG: rail | sidebar | main | info
   =================================================================== */
#app { position: fixed; inset: 0; display: flex; background: var(--bg); }

.app-shell { display: flex; width: 100%; height: 100%; min-width: 0; }

/* ---------- Thanh điều hướng trái ---------- */
.app-rail {
  width: var(--rail-w); flex: none; display: flex; flex-direction: column; align-items: center;
  padding: var(--sp-3) 0; gap: var(--sp-1);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--accent-text); z-index: 5;
}
html[data-theme="dark"] .app-rail { background: linear-gradient(180deg, hsl(var(--accent-h) calc(var(--accent-s) * 0.45) 22%), hsl(var(--accent-h) calc(var(--accent-s) * 0.5) 16%)); }
.app-rail__me { margin: var(--sp-2) 0 var(--sp-4); position: relative; border-radius: 50%; padding: 2px; border: 0; background: transparent; }
.app-rail__me:hover { filter: brightness(1.08); }
.app-rail__me .kit-avatar { box-shadow: 0 0 0 2px rgba(255, 255, 255, .55); }
.app-rail__nav { display: flex; flex-direction: column; gap: 6px; width: 100%; align-items: center; }
.app-rail__spacer { flex: 1; }
.app-rail__btn {
  position: relative; width: 48px; height: 48px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, .82);
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.app-rail__btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.app-rail__btn:active { transform: scale(.94); }
.app-rail__btn.is-active { background: rgba(255, 255, 255, .24); color: #fff; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18); }
.app-rail__btn .kit-badge { position: absolute; top: 2px; right: 2px; }
.app-rail__dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: #ff5d5d; box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Cột giữa ---------- */
.app-sidebar {
  width: var(--sidebar-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
}
.app-sidebar[hidden] { display: none !important; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; background: var(--bg); position: relative; }
.app-main__view { flex: 1; min-height: 0; display: flex; flex-direction: column; min-width: 0; }
.app-info {
  width: var(--info-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--border);
}
.app-info[hidden] { display: none !important; }

.app-banner {
  display: flex; align-items: center; gap: var(--sp-2); justify-content: center;
  padding: 6px var(--sp-3); font-size: var(--fs-sm); background: var(--warning); color: #231a00;
}

/* ---------- Màn hình trống ---------- */
.app-welcome { flex: 1; display: grid; place-items: center; padding: var(--sp-8); text-align: center; color: var(--text-2); background: var(--chat-bg); }
.app-welcome__card { max-width: 440px; display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.app-welcome__logo { width: 92px; height: 92px; border-radius: 28px; display: grid; place-items: center; color: var(--accent-text);
  background: linear-gradient(135deg, var(--accent-2), var(--accent-strong)); box-shadow: var(--shadow-2); }
.app-welcome h2 { font-size: var(--fs-xl); color: var(--text); }
.app-welcome__tips { display: grid; gap: var(--sp-2); margin-top: var(--sp-3); width: 100%; text-align: left; }
.app-welcome__tip { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); font-size: var(--fs-sm); }
.app-welcome__tip kbd { margin-left: auto; font-family: var(--mono); font-size: var(--fs-xs); padding: 2px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }

/* ---------- Màn hình tải đầu tiên ---------- */
.app-boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 1; }
.app-boot__inner { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4); color: var(--text-2); }

/* ---------- Máy tính bảng: gọn sidebar, ẩn info ---------- */
@media (max-width: 1180px) {
  :root { --sidebar-w: 320px; --info-w: 320px; }
}
@media (max-width: 1024px) {
  .app-info { position: absolute; top: 0; right: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-3); width: min(var(--info-w), 92vw); }
}

/* ---------- Điện thoại: một cột + thanh dưới ---------- */
@media (max-width: 820px) {
  :root { --rail-w: 0px; --sidebar-w: 100vw; }
  .app-shell { flex-direction: column; }
  .app-rail {
    order: 3; width: 100%; height: calc(58px + var(--safe-b)); flex-direction: row; padding: 0 var(--sp-2) var(--safe-b);
    justify-content: space-around; align-items: center; background: var(--surface); color: var(--text-3); border-top: 1px solid var(--border);
  }
  html[data-theme="dark"] .app-rail { background: var(--surface); }
  .app-rail__me, .app-rail__spacer, .app-rail__extra { display: none; }
  .app-rail__nav { flex-direction: row; justify-content: space-around; }
  .app-rail__btn { color: var(--text-3); width: 56px; height: 46px; }
  .app-rail__btn:hover { background: var(--hover); color: var(--text); }
  .app-rail__btn.is-active { background: transparent; color: var(--accent); box-shadow: none; }
  .app-rail__dot { box-shadow: 0 0 0 2px var(--surface); }
  .app-sidebar { width: 100%; flex: 1; border-right: 0; order: 1; }
  .app-main { order: 1; flex: 1; }
  .app-shell .app-main, .app-shell .app-sidebar { min-height: 0; }
  /* Khi đang xem một hội thoại: ẩn sidebar và thanh dưới, chat toàn màn hình */
  .app-shell.has-detail .app-sidebar { display: none; }
  .app-shell.has-detail .app-rail { display: none; }
  .app-shell:not(.has-detail) .app-main { display: none; }
  .app-shell.sidebar-less .app-sidebar { display: none; }
  .app-shell.sidebar-less .app-main { display: flex; }
  .app-info { width: 100%; }
}

/* ---------- Giao diện cổ điển: thanh trái sáng, viền mảnh như các mạng xã hội ---------- */
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail { background: var(--bg-elev); color: var(--text); border-right: 1px solid var(--border); }
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail__me .kit-avatar { box-shadow: 0 0 0 2px var(--border-strong); }
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail__btn { color: var(--text-2); }
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail__btn:hover { background: var(--hover); color: var(--text); }
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail__btn.is-active { background: var(--surface-3); color: var(--text); box-shadow: none; }
html:is([data-accent="classic"], [data-accent="tam"]) .app-rail__dot { box-shadow: 0 0 0 2px var(--bg-elev); }

/* ===================================================================
   DIỆN MẠO RIÊNG CỦA TÁM CHAT (màu nhấn "tam")
   =================================================================== */
html[data-accent="tam"] body { background: #eef0fb; }
html[data-theme="dark"][data-accent="tam"] body { background: #0d0f17; }

@media (min-width: 821px) {
  /* Thanh trái: nút đang chọn là viên thuốc gradient */
  html[data-accent="tam"] .app-rail { background: var(--bg-elev); border-right: 1px solid var(--border); }
  html[data-accent="tam"] .app-rail__btn { border-radius: 16px; }
  html[data-accent="tam"] .app-rail__btn.is-active { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; box-shadow: 0 8px 18px hsl(var(--accent-h) 90% 60% / .35); }
  html[data-accent="tam"] .app-rail__me .kit-avatar { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px hsl(var(--accent-h) 90% 65% / .55); }
}
@media (min-width: 1000px) {
  /* Máy tính: ứng dụng là một thẻ bo góc nổi trên nền màu mờ */
  html[data-accent="tam"] body {
    background:
      radial-gradient(55% 60% at 8% 0%, hsl(226 90% 70% / .38), transparent 70%),
      radial-gradient(50% 55% at 100% 8%, hsl(310 80% 74% / .30), transparent 70%),
      radial-gradient(60% 60% at 70% 100%, hsl(262 85% 70% / .30), transparent 70%), #eef0fb;
    background-attachment: fixed;
  }
  html[data-theme="dark"][data-accent="tam"] body {
    background:
      radial-gradient(55% 60% at 8% 0%, hsl(226 80% 45% / .30), transparent 70%),
      radial-gradient(50% 55% at 100% 8%, hsl(310 70% 45% / .22), transparent 70%),
      radial-gradient(60% 60% at 70% 100%, hsl(262 75% 45% / .24), transparent 70%), #0d0f17;
    background-attachment: fixed;
  }
  html[data-accent="tam"] #app { background: transparent; padding: 20px 24px; justify-content: center; }
  html[data-accent="tam"] .app-shell {
    max-width: 1560px; border-radius: 28px; overflow: hidden; background: var(--bg-elev);
    box-shadow: 0 30px 80px rgba(50, 60, 150, .22), 0 0 0 1px var(--border);
  }
  html[data-accent="tam"] .app-auth { background: transparent; }
  html[data-accent="tam"] .au-root {
    max-width: 1180px; min-height: 0; height: calc(100% - 48px); margin: 24px auto; border-radius: 28px; overflow: hidden;
    background: var(--bg); box-shadow: 0 30px 80px rgba(50, 60, 150, .22), 0 0 0 1px var(--border);
  }
}

/* Khung chat: tiêu đề và ô soạn tin nhẹ nhàng hơn */
html[data-accent="tam"] .ch-header { height: 66px; border-bottom: 1px solid var(--border); }
html[data-accent="tam"] .cp { border-top: 0; box-shadow: 0 -8px 24px rgba(50, 60, 150, .05); }
html[data-accent="tam"] .cp-field { background: var(--surface-2); border-radius: 24px; }
html[data-accent="tam"] .cp-send { background: linear-gradient(135deg, var(--accent-2), var(--accent)); box-shadow: 0 6px 14px hsl(var(--accent-h) 90% 60% / .35); }
html[data-accent="tam"] .ch-bubble { box-shadow: 0 1px 2px rgba(40, 50, 120, .08); }
html[data-accent="tam"] .ch-msg.is-me .ch-bubble { box-shadow: 0 4px 12px hsl(var(--accent-h) 90% 60% / .25); }
html[data-accent="tam"] .sb-list .is-active, html[data-accent="tam"] .conv-item.is-active { box-shadow: inset 3px 0 0 var(--accent); }
