/* SOP Flow — Task 1.2: trang giới thiệu, đăng nhập, khung ứng dụng desktop/mobile.
   Tông navy giữ từ Task 01. Mobile-first; desktop thực thụ từ 1024px (D-05, ONB-010). */
:root {
  --navy: #0f2a4a;
  --navy-2: #16395f;
  --navy-3: #1d4e80;
  --accent: #2f9e6e;
  --accent-dark: #1e6b46;
  --bg: #0b1f36;
  --page: #f2f5f9;
  --card: #ffffff;
  --text: #1d2b3a;
  --muted: #5b6b7d;
  --line: #e3e9f0;
  --danger: #c0392b;
  --amber: #b7791f;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(11, 31, 54, 0.12);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--page);
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 { color: var(--navy); line-height: 1.3; margin: 0 0 0.6em; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { margin: 0 0 1em; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hint { display: block; font-size: 12.5px; color: var(--muted); margin-top: 4px; }

:focus-visible {
  outline: 3px solid #7fb3e8;
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Nút bấm ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 600;
  border: 1px solid transparent; border-radius: 10px;
  padding: 11px 20px; cursor: pointer; text-decoration: none;
  min-height: 44px; transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-3); }
.btn.primary:disabled { background: #8fa3b8; cursor: wait; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.secondary:hover { background: #f0f4f9; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: 13.5px; min-height: 38px; }

.icon-btn {
  background: none; border: none; font-size: 20px; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; color: var(--navy); min-width: 44px; min-height: 44px;
}
.icon-btn:hover { background: #eef2f7; }

.link {
  background: none; border: none; color: var(--navy-3); cursor: pointer;
  font-size: 13.5px; font-weight: 600; padding: 6px 8px; border-radius: 6px;
  text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { background: #eef4fa; }
.link.danger { color: var(--danger); }

.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff;
  animation: spin 0.7s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form ---------- */
label { display: block; font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 14px; }
input[type="text"], input[type="password"], input[type="email"], select {
  display: block; width: 100%; margin-top: 6px;
  font-size: 16px; padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus { border-color: var(--navy-3); outline: 3px solid #7fb3e8; outline-offset: 0; }
input:disabled { background: #f0f3f7; color: var(--muted); }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 6px; bottom: 6px;
  background: #eef2f7; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--navy); cursor: pointer; padding: 0 12px;
  min-width: 52px;
}
.pw-toggle:hover { background: #e0e8f2; }
.pw-toggle.icon { min-width: 40px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; }
.pw-toggle.icon svg { display: block; }

.form-error {
  background: #fdecea; border: 1px solid #f5c6c0; color: #8f2b20;
  font-size: 14px; border-radius: 10px; padding: 10px 14px; margin: 0 0 14px;
}
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0 0 14px; }
legend { font-size: 13px; font-weight: 700; color: var(--muted); padding: 0 6px; }
.roles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; margin: 0; padding: 6px 0; }
.check input { width: 18px; height: 18px; accent-color: var(--navy); }

/* ---------- Thẻ ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); border: 1px solid #e8edf3;
}
.cards { display: grid; gap: 16px; grid-template-columns: 1fr; }

/* ---------- TRANG GIỚI THIỆU ---------- */
#landing {
  min-height: 100vh; display: flex; flex-direction: column;
  background: radial-gradient(1200px 800px at 50% -10%, var(--navy-2) 0%, var(--bg) 60%) fixed, var(--bg);
  color: #eaf1f8;
}
#landing h1 { color: #fff; }

.landing-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; max-width: 1200px; width: 100%; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: 0.01em; color: #fff; }
.badge {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--navy); background: #e8eef5; border-radius: 999px; padding: 5px 12px;
}

.landing-main {
  flex: 1; width: 100%; max-width: 1200px; margin: 0 auto;
  padding: 12px 20px 32px;
  display: grid; gap: 28px; grid-template-columns: 1fr;
  align-items: start;
}
.intro .lede { font-size: 16px; color: #c6d6e8; max-width: 34em; }

.caps { list-style: none; margin: 22px 0; padding: 0; display: grid; gap: 12px; }
.caps li {
  display: flex; gap: 12px; align-items: flex-start;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px; padding: 12px 14px;
}
.cap-ic { font-size: 22px; line-height: 1.2; }
.caps strong { display: block; color: #fff; font-size: 14.5px; }
.caps span span { font-size: 13px; color: #a9bfd6; }

.illo { width: 100%; max-width: 560px; height: auto; margin-top: 8px; }

.login-col { display: flex; justify-content: center; }
.login-card {
  background: #fff; color: var(--text); border-radius: 18px;
  padding: 26px 24px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  align-self: start;
}
.login-card h2 { margin-bottom: 4px; }
.login-note { font-size: 12.5px; color: var(--muted); margin: 14px 0 0; text-align: center; }

.landing-foot {
  text-align: center; padding: 16px; color: rgba(255, 255, 255, 0.5); font-size: 12.5px;
}

/* ---------- KHUNG ỨNG DỤNG ---------- */
#app { min-height: 100vh; }
.app-layout { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--navy); color: #dbe7f4;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
#sidebar .brand { padding: 16px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
#sidebar-nav { padding: 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  color: #c6d6e8; text-decoration: none; font-size: 14.5px; font-weight: 600;
  padding: 11px 12px; border-radius: 10px; min-height: 44px;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, 0.14); color: #fff; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: #7fa8d0; flex: 0 0 auto; }
.nav-item.active .nav-dot { background: var(--accent); }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
#sidebar-scrim { display: none; }

/* Thu gọn sidebar (desktop) */
#btn-collapse {
  margin-left: auto; background: none; border: 1px solid rgba(255,255,255,0.2);
  color: #c6d6e8; border-radius: 8px; cursor: pointer; padding: 6px 10px; font-size: 14px;
}
body.sidebar-collapsed #sidebar { width: 68px; flex-basis: 68px; }
body.sidebar-collapsed #sidebar .brand-name,
body.sidebar-collapsed #sidebar .nav-item span:last-child,
body.sidebar-collapsed #sidebar .sidebar-foot,
body.sidebar-collapsed #btn-collapse { display: none; }
body.sidebar-collapsed .nav-item { justify-content: center; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 8px 16px; position: sticky; top: 0; z-index: 20;
  min-height: 60px;
}
#btn-menu { display: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--navy); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}

#page { padding: 20px 16px 40px; max-width: 1200px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.roles { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.role-badge {
  font-size: 12px; font-weight: 700; color: var(--navy);
  background: #e8eef5; border-radius: 999px; padding: 4px 12px;
}
.role-badge.sm { font-size: 11px; padding: 3px 9px; }
.empty { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

.pill { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 11px; white-space: nowrap; }
.pill.green { background: #e3f4ea; color: var(--accent-dark); }
.pill.red { background: #fdecea; color: #8f2b20; }
.pill.amber { background: #fdf3e0; color: #8a5a13; }
.pill.gray { background: #eef1f5; color: var(--muted); }

/* ---------- Bảng ---------- */
.table-wrap {
  overflow-x: auto; background: #fff; border-radius: var(--radius);
  border: 1px solid #e8edf3; box-shadow: var(--shadow);
}
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.tbl th, .tbl td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl thead th { background: #f6f9fc; color: var(--navy); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #f8fbfe; }
.tbl td.actions { white-space: nowrap; }

/* ---------- Dialog ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(11, 31, 54, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; z-index: 100; overflow-y: auto;
}
.dialog { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 480px; box-shadow: var(--shadow); }
.dialog h3 { margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Bắt buộc đổi mật khẩu ---------- */
#force-change { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(1200px 800px at 50% -10%, var(--navy-2) 0%, var(--bg) 60%) fixed, var(--bg); }
#force-change[hidden] { display: none; }
.force-wrap { width: 100%; max-width: 420px; }
.force-card h2 { margin-bottom: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--navy); color: #fff; font-size: 14px; font-weight: 600;
  padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 200; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #8f2b20; }

/* ---------- Responsive ---------- */

/* Mobile: sidebar thành ngăn kéo */
@media (max-width: 1023px) {
  #btn-menu { display: inline-flex; }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%); transition: transform 0.22s ease;
    height: 100dvh;
  }
  body.sidebar-open #sidebar { transform: none; }
  body.sidebar-open #sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: rgba(11, 31, 54, 0.5);
  }
  #btn-collapse { display: none; }
  .user-chip .user-name { display: none; }
  #btn-logout { font-size: 13px; padding: 8px 12px; }
}

/* Desktop: trang giới thiệu 2 cột (ONB-001) */
@media (min-width: 1024px) {
  h1 { font-size: 38px; }
  .landing-main { grid-template-columns: 1.15fr 0.85fr; gap: 48px; padding-top: 40px; align-items: center; }
  .login-card { padding: 32px 30px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  #page { padding: 28px 28px 48px; }
}

/* Màn hình rộng: 3 cột thẻ */
@media (min-width: 1440px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  #page { max-width: 1400px; }
}
@media (min-width: 1920px) {
  #page { max-width: 1600px; }
}

/* Mobile nhỏ */
@media (max-width: 380px) {
  .landing-main { padding: 8px 14px 24px; }
  h1 { font-size: 26px; }
  .login-card { padding: 20px 18px; }
  .roles-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  #sidebar { transition: none; }
}
