/* =====================================================================
   domood-os, bộ giao diện dùng chung (ứng dụng, trang đọc, bộ HTML kiến trúc)
   Màu cam lấy từ logo gốc (#EB4900). Chỉ giao diện sáng.
   Quy tắc: thẻ và khối nền trắng có viền xám, cam chỉ dùng cho nút chính,
   mục đang chọn và liên kết; ba màu trạng thái chỉ dùng cho huy hiệu trạng thái.
   ===================================================================== */
:root {
  color-scheme: light;
  --brand: #EB4900;
  --brand-ink: #C23C00;
  --brand-hover: #A83400;
  --brand-soft: #FFF1E8;
  --bg: #FBF6F2;
  --surface: #FFFFFF;
  --surface-2: #FBF9F7;
  --ink: #26211F;
  --ink-2: #4A423D;
  --muted: #5E514A;
  --line: #E8DDD5;
  --line-2: #CBB9AE;
  --ok: #1F6F50;     --ok-soft: #E6F4EE;
  --warn: #8A5A00;   --warn-soft: #FFF4DB;
  --danger: #A22316; --danger-soft: #FDECEA;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Plus Jakarta Sans", "Be Vietnam Pro", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --r: 12px;
  --r-sm: 10px;
  --topbar: 60px;
  --sidebar: 252px;
  --focus: 0 0 0 3px rgba(235, 73, 0, 0.22);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  hyphens: none;
  word-break: normal;
  overflow-wrap: normal;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); margin: 0; text-wrap: balance; line-height: 1.3; }
h1 { font-size: clamp(22px, 2.4vw, 26px); font-weight: 700; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; line-height: 1.35; }
h4 { font-size: 14.5px; font-weight: 600; }
p { margin: 0; }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
pre { background: #26211F; color: #FCEFE6; border-radius: var(--r-sm); padding: 14px 16px; overflow-x: auto; white-space: pre; line-height: 1.5; }
pre code { background: none; border: 0; padding: 0; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.xs { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ===== Khung ứng dụng ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; min-width: 0; }
.topbar .brand img { height: 22px; width: auto; display: block; }
.topbar .brand span { font-weight: 600; font-size: 15px; white-space: nowrap; border-left: 1px solid var(--line); padding-left: 12px; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.topbar .who strong { color: var(--ink); font-weight: 600; white-space: nowrap; }
.impersonate-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 20px; background: var(--warn-soft); color: var(--warn); font-size: 13.5px; font-weight: 600;
  border-bottom: 1px solid #F0D9A8;
}
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: calc(100vh - var(--topbar)); }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 10px 32px;
  position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow-y: auto;
}
.nav-group { margin-bottom: 14px; }
.nav-label { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 0 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 38px;
  padding: 8px 12px; margin-bottom: 2px;
  border: 0; border-left: 3px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 500; text-align: left; text-decoration: none;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand-ink); border-left-color: var(--brand); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--brand-ink); }
.main { padding: 24px 28px 56px; max-width: 1240px; width: 100%; margin: 0 auto; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 72ch; }
.nav-toggle { display: none; }
.scrim { display: none; }

/* ===== Thành phần ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
}
.card + .card, .stack > * + * { margin-top: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px 18px; }
.stat b { display: block; font-family: var(--font-display); font-size: 28px; line-height: 1.1; font-weight: 700; }
.stat span { color: var(--muted); font-size: 13.5px; }
a.card:hover { border-color: var(--line-2); text-decoration: none; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.list-row:first-child { border-top: 0; padding-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; color: var(--ink); }
.list-row .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap;
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink-2); text-decoration: none; }
.btn.primary { background: var(--brand-ink); border-color: var(--brand-ink); color: #FFFFFF; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--danger); border-color: #E3B7B1; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

label.field { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }
label.field > span.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.input, select.input, textarea.input {
  display: block; width: 100%; margin-top: 6px;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14.5px; font-weight: 400;
}
textarea.input { min-height: 140px; line-height: 1.5; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.notice { border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: var(--r-sm); padding: 10px 14px; background: var(--surface); font-size: 14px; }
.notice.danger { border-left-color: var(--danger); }
.notice.ok { border-left-color: var(--ok); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 14px; border: 0; border-bottom: 2px solid transparent; background: none; font: inherit; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--brand-ink); border-bottom-color: var(--brand); font-weight: 600; }

/* ===== Ma trận năng lực và RACI ===== */
.matrix th.sticky, .matrix td.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 200px; }
.matrix th.sticky { background: var(--surface-2); }
.matrix th.rot { white-space: normal; min-width: 92px; font-weight: 600; line-height: 1.3; }
.matrix td.cell { text-align: center; padding: 6px; }
.cell-btn {
  width: 34px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; color: var(--ink-2);
}
.cell-btn.on { color: var(--ok); }
.cell-btn.off { color: var(--line-2); }
.cell-btn.over { border-color: var(--brand); border-width: 1.5px; }
.cell-btn.r, .cell-btn.a, .cell-btn.ra { color: var(--brand-ink); }
.matrix tr.group td { background: var(--surface-2); font-weight: 600; font-size: 13px; color: var(--muted); }

/* ===== Sơ đồ quy trình theo lớp, từ trên xuống ===== */
.flow { position: relative; }
.flow-layer { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 10px; }
.flow-layer > .layer-name { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); border-radius: var(--r) var(--r) 0 0; }
.flow-step { display: grid; grid-template-columns: 210px 1fr 200px; gap: 16px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: start; }
.flow-layer > .flow-step:first-of-type { border-top: 0; }
.flow-step .no { display: flex; gap: 10px; align-items: baseline; font-weight: 600; }
.flow-step .no b { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--brand); color: var(--brand-ink); align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.flow-step .who { color: var(--muted); font-size: 13.5px; }
.flow-arrow { text-align: center; color: var(--line-2); font-size: 18px; line-height: 1; margin: -4px 0 6px; }
.flow-loop { border: 1px dashed var(--line-2); border-radius: var(--r-sm); padding: 10px 14px; color: var(--muted); font-size: 13.5px; }

/* ===== Trang đọc tài liệu ===== */
.reader { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.reader-toc { position: sticky; top: calc(var(--topbar) + 16px); max-height: calc(100vh - var(--topbar) - 32px); overflow-y: auto; font-size: 13.5px; }
.reader-toc a { display: block; color: var(--ink-2); padding: 5px 10px; border-left: 2px solid var(--line); }
.reader-toc a.h3 { padding-left: 22px; font-size: 13px; }
.reader-toc a.active { color: var(--brand-ink); border-left-color: var(--brand); font-weight: 600; }
.reader-body { font-size: var(--reader-size, 16.5px); line-height: 1.72; max-width: 78ch; }
.reader-body h2 { font-size: 1.3em; margin: 1.6em 0 0.6em; }
.reader-body h3 { font-size: 1.1em; margin: 1.3em 0 0.5em; }
.reader-body p, .reader-body ul, .reader-body ol { margin: 0 0 0.9em; }
.reader-body li { margin-bottom: 0.3em; }
.reader-body table { font-size: 0.88em; margin: 0 0 1em; display: block; overflow-x: auto; }
.reader-body blockquote { margin: 0 0 1em; padding: 10px 16px; border-left: 3px solid var(--line-2); background: var(--surface-2); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.reader-body mark { background: #FFE2CC; color: inherit; border-radius: 3px; }
.reader-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ===== Thông báo ===== */
.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #FFF7F2; border-radius: var(--r-sm); padding: 12px 16px; font-size: 14px; box-shadow: 0 12px 32px rgba(38, 33, 31, 0.18); }
.toast.error { background: var(--danger); }
.modal-back { position: fixed; inset: 0; background: rgba(38, 33, 31, 0.35); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 150; }
.modal { background: var(--surface); border-radius: var(--r); border: 1px solid var(--line); width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px 22px; }

/* ===== Màn hình hẹp ===== */
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: var(--topbar); left: 0; bottom: 0; height: auto;
    width: min(300px, 86vw); z-index: 80;
    transform: translateX(-102%); transition: transform 0.18s ease;
    box-shadow: 0 12px 40px rgba(38, 33, 31, 0.12);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(38, 33, 31, 0.28); z-index: 70; }
  .main { padding: 16px; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reader { grid-template-columns: 1fr; }
  .reader-toc { position: static; max-height: none; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 8px 0; }
  .flow-step { grid-template-columns: 1fr; gap: 6px; }
}
@media (max-width: 640px) {
  .topbar .brand span, .topbar .who .email { display: none; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .card { padding: 14px 16px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ===== Trang đăng nhập ===== */
.login-page { background: #FFF7F2; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: min(420px, 100%); padding: 28px; }
.login-logo { height: 28px; width: auto; display: block; margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card form { margin-top: 18px; }
.login-btn { width: 100%; margin-top: 6px; }
.login-foot { margin-top: 14px; }

/* Thẻ trong lưới không cộng khoảng cách dọc của thẻ liền kề */
.grid > * + * { margin-top: 0 !important; }
.topbar .who .email { white-space: nowrap; }
@media (max-width: 1024px) { .topbar .who .email { display: none; } }
@media (min-width: 1025px) { .nav-toggle { display: none !important; } }
.img-missing { display: inline-block; padding: 6px 10px; border: 1px dashed var(--line-2); border-radius: 8px; color: var(--muted); font-size: 13px; }
