/*
 * RTOP UI — các thành phần dùng chung, dựng lại theo giao diện RTOP hiện tại
 * (sidebar, topbar, page header, card, badge dạng pill viền, bảng, modal, form control).
 * Tham chiếu: document/UI/*.png (Dashboard, Survey List, Result List, Survey Result Details).
 */
:root {
  --bg: #eef0f4;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2433;
  --text-2: #4b5563;
  --muted: #6b7280;
  --navy: #0e2238;
  --navy-2: #1b3350;
  --brand: #f04e23;
  --brand-hover: #d9441c;
  --brand-soft: #fff1ec;
  --blue: #1a86b8;
  --blue-soft: #e7f3f9;
  --green: #1e8e50;
  --green-soft: #e8f6ee;
  --red: #d64545;
  --red-ink: #b42323;
  --red-soft: #fdeeee;
  --amber: #c77700;
  --amber-mark: #f2a33a;
  --amber-soft: #fff6e6;
  --neutral-mark: #c3c9d1;
  --unknown-mark: #e6e9ee;
  --grid: #edf0f3;
  --focus: #1a86b8;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-pop: 0 10px 30px rgba(14, 34, 56, .16);
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 64px;
  --font: 'Lexend', 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }

/* ---------------- App shell ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width .18s ease, transform .2s ease;
}
.sidebar__logo { height: var(--topbar-h); display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--border); }
.sidebar__logo img { height: 40px; width: auto; display: block; }
.sidebar__logo .logo-mini { display: none; font-weight: 800; font-style: italic; color: var(--navy); font-size: 22px; letter-spacing: -.5px; }
.sidebar__logo .logo-mini b { color: var(--brand); }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav__item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px; border: 0; background: none; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 15px; text-align: left; white-space: nowrap;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.is-active { background: var(--navy); color: #fff; }
.nav__item .nav__chev { margin-left: auto; }
.nav__sub { display: flex; flex-direction: column; margin: 4px 0 6px; }
.nav__sub .nav__item { padding-left: 44px; font-size: 14.5px; border-radius: 0; border-bottom: 1px solid var(--border); }
.nav__sub .nav__item.is-current { color: var(--brand); font-weight: 600; background: none; }
.nav__label { overflow: hidden; text-overflow: ellipsis; }
.sidebar__foot { border-top: 1px solid var(--border); padding: 10px; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); transition: margin-left .18s ease; }
.app.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app.is-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
.app.is-collapsed .nav__label, .app.is-collapsed .nav__chev, .app.is-collapsed .nav__sub { display: none; }
.app.is-collapsed .nav__item { justify-content: center; padding: 10px; }
.app.is-collapsed .sidebar__logo { justify-content: center; padding: 0; }
.app.is-collapsed .sidebar__logo img { display: none; }
.app.is-collapsed .sidebar__logo .logo-mini { display: block; }
.scrim { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.circle-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items: center;
  border: 1.5px solid var(--brand); background: var(--surface); color: var(--brand);
}
.circle-btn:hover { background: var(--brand-soft); }
.circle-btn--plain { border-color: var(--border); color: var(--text-2); }
.circle-btn--plain:hover { background: var(--surface-2); }
.topbar__org { color: var(--text-2); font-size: 15px; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #e9edf3; color: var(--navy); display: grid; place-items: center; font-weight: 600; }
.user { display: flex; align-items: center; gap: 10px; }
.user__name { font-size: 14.5px; line-height: 1.2; }
.user__role { font-size: 12.5px; color: var(--muted); }
.badge-dot { position: relative; }
.badge-dot::after { content: ''; position: absolute; top: 6px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }
.hamburger { display: none; }

.page-head { background: var(--surface); padding: 20px 24px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.2px; }
.breadcrumb { font-size: 13.5px; color: var(--text-2); margin-top: 2px; }
.breadcrumb a { color: var(--brand); }
.page-head__desc { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.page-head__actions { margin-left: auto; display: flex; gap: 8px; }
.content { padding: 20px 24px 40px; }

/* ---------------- Card ---------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card__head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 0; flex-wrap: wrap; }
.card__title { margin: 0; font-size: 16px; font-weight: 600; }
.card__sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card__tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card__body { padding: 14px 18px 18px; }
.card__foot { padding: 0 18px 16px; color: var(--muted); font-size: 12.5px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); }
.btn--outline-brand { border-color: var(--brand); color: var(--brand); }
.btn--outline-brand:hover { background: var(--brand-soft); }
.btn--ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn--link { border: 0; background: none; color: var(--blue); padding: 0; height: auto; font-weight: 500; }
.btn--link:hover { background: none; text-decoration: underline; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------------- Form controls ---------------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-size: 12px; color: var(--muted); font-weight: 500; }
.select, .input {
  height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 14px; min-width: 0; width: 100%;
}
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.select:hover, .input:hover { border-color: #b7bec9; }
.input.is-invalid { border-color: var(--red); }

.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 5px; font-size: 13px; color: var(--text-2); }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed='true'], .segmented button[aria-selected='true'] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(14, 34, 56, .12); }

/* ---------------- Badges (pill viền, như Survey List / Result List) ---------------- */
.pill { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 999px; border: 1.5px solid currentColor; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--surface); }
.pill--green { color: var(--green); background: var(--green-soft); }
.pill--red { color: var(--red-ink); background: var(--red-soft); }
.pill--amber { color: var(--amber); background: var(--amber-soft); }
.pill--blue { color: var(--blue); background: var(--blue-soft); }
.pill--gray { color: #5b6472; background: var(--surface-2); border-color: var(--border-strong); }
.pill--navy { color: var(--navy); }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 12px; white-space: nowrap; }

/* ---------------- Table ---------------- */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: .3px; padding: 11px 12px; background: var(--surface); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:nth-child(even) td { background: #fafbfc; }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover td { background: #f1f5f9; }
.table .ta-r { text-align: right; }
.table .ta-c { text-align: center; }

/* ---------------- Modal & drawer ---------------- */
.overlay { position: fixed; inset: 0; background: rgba(28, 36, 51, .5); z-index: 60; display: flex; }
.overlay--center { align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 720px; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; }
.modal__head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal__title { margin: 0; font-size: 17px; font-weight: 600; }
.modal__close { margin-left: auto; }
.modal__body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal__foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; }
.box__title { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.meta-grid dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.meta-grid dd { margin: 2px 0 0; }

.drawer-overlay { justify-content: flex-end; }
.drawer { width: min(960px, 100%); height: 100%; background: var(--bg); display: flex; flex-direction: column; box-shadow: var(--shadow-pop); animation: drawer-in .18s ease-out; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer__head { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; flex-direction: column; gap: 10px; }
.drawer__body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; }

/* ---------------- Toast ---------------- */
.toast-host { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--navy); color: #fff; padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); font-size: 13.5px; display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: #8fd0ee; font-weight: 600; padding: 0; }

/* ---------------- Tooltip (hover + focus) ---------------- */
.info { position: relative; display: inline-flex; vertical-align: middle; }
.info__btn { width: 20px; height: 20px; display: inline-grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 50%; padding: 0; }
.info__btn:hover, .info__btn:focus-visible { color: var(--text); }
/* position: fixed + toạ độ do JS tính → không bao giờ tràn mép màn hình hay làm trang cuộn ngang */
.info__tip {
  position: fixed; z-index: 90; top: 0; left: 0; display: none;
  width: min(290px, calc(100vw - 16px)); padding: 10px 12px; background: var(--navy); color: #e8eef5; border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.5; font-weight: 400; text-transform: none; letter-spacing: 0;
  box-shadow: var(--shadow-pop); pointer-events: none; text-align: left; white-space: normal;
}
.info.is-open .info__tip { display: block; }
.info__tip b { color: #fff; }

/* ---------------- Popover menu ---------------- */
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); min-width: 260px; padding: 6px; z-index: 50; }
.menu__item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 5px; font-size: 13.5px; }
.menu__item:hover { background: var(--surface-2); }
.menu__note { padding: 6px 10px 8px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }

/* ---------------- Responsive shell ---------------- */
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; box-shadow: var(--shadow-pop); }
  .app.is-mobile-open .sidebar { transform: none; }
  .app.is-mobile-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(28, 36, 51, .4); }
  .main, .app.is-collapsed .main { margin-left: 0; }
  .app.is-collapsed .nav__label, .app.is-collapsed .nav__chev { display: inline; }
  .app.is-collapsed .nav__sub { display: flex; }
  .app.is-collapsed .nav__item { justify-content: flex-start; padding: 10px 12px; }
  .app.is-collapsed .sidebar__logo img { display: block; }
  .app.is-collapsed .sidebar__logo .logo-mini { display: none; }
  .collapse-btn { display: none; }
  .hamburger { display: inline-grid; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar__org, .user__meta { display: none; }
  .page-head { padding: 16px; }
  .page-head h1 { font-size: 21px; }
  .content { padding: 16px 16px 32px; }
  .meta-grid { grid-template-columns: 1fr; }
  .overlay--center { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
  .drawer__head, .drawer__body { padding-left: 16px; padding-right: 16px; }
}
