:root {
  --bg: #f0f4f8;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #0284c7;
  --green: #0d9488;
  --amber: #d97706;
  --violet: #7c3aed;
  --red: #dc2626;
  --teal: #0f766e;
  --shadow: 0 1px 3px rgba(15, 118, 110, .06), 0 8px 24px rgba(15, 118, 110, .05);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Inter', Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 14px 12px;
  background: linear-gradient(195deg, #0f766e 0%, #134e4a 40%, #1a2332 100%);
  color: #fff;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: width .18s ease, padding .18s ease;
  overflow-x: hidden;
  overflow-y: auto;
}

h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.menu-toggle {
  flex: 0 0 36px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: rgba(255, 255, 255, .1);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  transition: background .15s, border-color .15s;
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, .18);
  border-color: rgba(255, 255, 255, .3);
}

body.sidebar-collapsed header {
  width: 56px;
  padding: 14px 10px;
}

body.sidebar-collapsed h1,
body.sidebar-collapsed .section-nav,
body.sidebar-collapsed .sidebar-filters,
body.sidebar-collapsed .global-search-trigger,
body.sidebar-collapsed .sidebar-status {
  display: none;
}

.global-search-trigger {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  color: rgba(255, 255, 255, .86);
  background: rgba(255, 255, 255, .09);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}

.global-search-trigger:hover {
  color: #fff;
  background: rgba(255, 255, 255, .15);
  border-color: rgba(255, 255, 255, .25);
}

.global-search-trigger kbd,
.global-search-input-wrap kbd {
  padding: 2px 5px;
  border: 1px solid currentColor;
  border-radius: 5px;
  font-family: inherit;
  font-size: 10px;
  line-height: 1.2;
  opacity: .65;
  white-space: nowrap;
}

.global-search-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: start center;
  padding: min(11vh, 90px) 18px 24px;
  background: rgba(15, 23, 42, .56);
  backdrop-filter: blur(5px);
}

.global-search-dialog {
  width: min(760px, 100%);
  max-height: min(720px, 80vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, .35);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}

.global-search-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 10px;
}

.global-search-head h2 { margin: 0 0 3px; font-size: 18px; }
.global-search-head p { margin: 0; color: var(--muted); font-size: 12px; }
.global-search-close {
  flex: 0 0 34px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: none;
  font-size: 24px;
  line-height: 1;
}

.global-search-input-wrap {
  margin: 0 20px;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 2px solid #99d8d1;
  border-radius: 10px;
  background: #f8fffe;
  color: var(--teal);
}

.global-search-input-wrap:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .1);
}

.global-search-input-wrap input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 42px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
}

.global-search-status {
  padding: 10px 20px 8px;
  color: var(--muted);
  font-size: 11px;
}

.global-search-results {
  min-height: 80px;
  overflow-y: auto;
  padding: 0 10px 12px;
}

.global-search-result {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  box-shadow: none;
  text-align: left;
}

.global-search-result:hover,
.global-search-result.is-active {
  background: #f0fdfa;
  border-color: #b6e4de;
}

.global-search-result-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #eef2ff;
  font-size: 17px;
}

.global-search-result-icon.is-order { background: #e0f2fe; }
.global-search-result-icon.is-issue { background: #fef3c7; }
.global-search-result-icon.is-deviation { background: #fee2e2; }
.global-search-result-icon.is-capa { background: #ede9fe; }
.global-search-result-icon.is-ra { background: #dcfce7; }
.global-search-result-icon.is-appraisal { background: #ccfbf1; }
.global-search-result-main { min-width: 0; display: grid; gap: 2px; }
.global-search-result-main strong,
.global-search-result-main > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.global-search-result-main strong { font-size: 13px; }
.global-search-result-main > span:last-child { color: var(--muted); font-size: 11px; }
.global-search-result-type {
  color: var(--teal) !important;
  font-size: 9px !important;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.global-search-result time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.issue-card.is-search-hit { animation: global-search-hit 2.4s ease; }

.record-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
}

.record-pager button,
.record-pager select {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 11px;
}

.record-pager strong { color: var(--ink); }

.record-filter-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) repeat(3, minmax(105px, .72fr)) minmax(280px, 1.45fr);
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.record-filter-toolbar-compact {
  grid-template-columns: minmax(300px, 2fr) repeat(2, minmax(130px, .72fr)) minmax(280px, 1.35fr);
}

.record-filter-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.record-filter-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.record-filter-control {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  box-sizing: border-box;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
}

.record-filter-control:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, .12);
  outline: none;
}

.record-filter-dates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.record-filter-date {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.record-filter-date > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

@media (max-width: 1120px) {
  .record-filter-toolbar,
  .record-filter-toolbar-compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .record-filter-search {
    grid-column: span 2;
  }

  .record-filter-period {
    grid-column: span 3;
  }

  .record-filter-toolbar-compact .record-filter-period {
    grid-column: 2 / span 2;
  }
}

@media (max-width: 700px) {
  .record-filter-toolbar,
  .record-filter-toolbar-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-filter-search,
  .record-filter-period,
  .record-filter-toolbar-compact .record-filter-period {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .record-filter-toolbar,
  .record-filter-toolbar-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-filter-search,
  .record-filter-period,
  .record-filter-toolbar-compact .record-filter-period {
    grid-column: 1 / -1;
  }
}

@keyframes global-search-hit {
  0%, 100% { box-shadow: none; }
  18%, 72% { box-shadow: 0 0 0 4px rgba(15, 118, 110, .25); border-color: var(--teal); }
}

@media (max-width: 560px) {
  .global-search-backdrop { padding: 12px; }
  .global-search-dialog { max-height: calc(100vh - 24px); border-radius: 12px; }
  .global-search-head { padding: 14px 14px 8px; }
  .global-search-input-wrap { margin: 0 14px; }
  .global-search-status { padding-inline: 14px; }
  .global-search-result { grid-template-columns: 36px minmax(0, 1fr); }
  .global-search-result time { display: none; }
  .record-pager { justify-content: center; flex-wrap: wrap; }
}

.section-nav {
  display: grid;
  gap: 8px;
  margin: 0;
}

.section-nav button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  color: rgba(216, 225, 234, .8);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .18s ease;
}

.section-nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .08);
  border-left-color: rgba(94, 234, 212, .4);
}

.section-nav button.is-active {
  color: #fff;
  background: rgba(255, 255, 255, .12);
  border-left-color: #5eead4;
  font-weight: 700;
}

.app-main {
  margin-left: 248px;
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  transition: margin-left .18s ease;
}

body.sidebar-collapsed .app-main {
  margin-left: 56px;
}

.sidebar-filters {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

.sidebar-filters label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: rgba(216, 225, 234, .65);
  font-weight: 700;
}

.sidebar-filters input,
.sidebar-filters select {
  background: rgba(255, 255, 255, .09);
  border-color: rgba(255, 255, 255, .16);
  color: #fff;
  min-height: 30px;
  font-size: 12px;
  padding: 5px 8px;
  width: 100%;
  box-sizing: border-box;
}

.sidebar-filters input[type="file"] {
  font-size: 11px;
  cursor: pointer;
  padding: 4px 6px;
}

.sidebar-filters input::placeholder {
  color: rgba(255, 255, 255, .28);
}

.sidebar-filters select option {
  background: #1a2332;
  color: #fff;
}

.sidebar-filters button {
  width: 100%;
  font-size: 12px;
  min-height: 32px;
}

.sidebar-status {
  font-size: 11px;
  color: rgba(216, 225, 234, .45);
  line-height: 1.4;
  word-break: break-all;
  padding-top: 2px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input, select, button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 6px 9px;
}

button {
  border-color: var(--blue);
  background: linear-gradient(135deg, #0284c7, #0d9488);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(2, 132, 199, .25);
}

button:active {
  transform: translateY(0);
}

main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  min-height: 0;
  overflow: hidden;
}

.dashboard-section {
  display: grid;
  gap: 10px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.dashboard-section[hidden] {
  display: none;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 2px 2px 0;
}

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

#san-xuat {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.section-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 2px 0;
}

.section-filters label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  min-width: 0;
}

.section-filters input,
.section-filters select {
  min-height: 30px;
  font-size: 12px;
  padding: 4px 8px;
  width: 140px;
}

.section-filters input[type="search"] { width: 160px; }
.section-filters input[type="datetime-local"] { width: 168px; }

.section-filters .filter-check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding-bottom: 4px;
}

.section-filters .filter-check input[type="checkbox"] {
  width: auto;
  min-height: auto;
  accent-color: var(--blue);
}

#chat-luong {
  grid-template-rows: auto auto minmax(0, 1fr);
}

#bao-cao-loi-web {
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
}

.web-issues-heading { align-items: center; }
.web-issues-heading > div { min-width: 0; }
.web-issues-source-status {
  padding: 8px 11px;
  border: 1px solid #bae6fd;
  border-radius: 9px;
  background: #f0f9ff;
  color: #075985;
  font-size: 11px;
  line-height: 1.45;
}
.web-issues-source-status.is-loading { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.web-issues-source-status.is-error { border-color: #fecaca; background: #fff1f2; color: #b91c1c; }
.web-issues-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}
.web-issues-toolbar label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.web-issues-toolbar input,
.web-issues-toolbar select {
  min-width: 130px;
  min-height: 32px;
  padding: 5px 8px;
  font-size: 12px;
}
.web-issues-toolbar .web-issues-search-label { flex: 1 1 280px; }
.web-issues-toolbar .web-issues-search-label input { width: 100%; }
.web-issues-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 7px;
}
.web-issues-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}
.web-issues-stat span { color: var(--muted); font-size: 10px; font-weight: 700; }
.web-issues-stat strong { color: var(--ink); font-size: 16px; line-height: 1; }
.web-issues-stat.is-blue { border-color: #bae6fd; background: #f0f9ff; }
.web-issues-stat.is-blue strong { color: #0369a1; }
.web-issues-stat.is-warning { border-color: #fed7aa; background: #fff7ed; }
.web-issues-stat.is-warning strong { color: #c2410c; }
.web-issues-stat.is-serious { border-color: #fecaca; background: #fff1f2; }
.web-issues-stat.is-serious strong { color: #b91c1c; }
.web-issues-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
}
.web-issues-table-wrap { min-height: 0; overflow: auto; }
.web-issues-table {
  width: 100%;
  min-width: 1220px;
  border-collapse: collapse;
  font-size: 12px;
}
.web-issues-table th,
.web-issues-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.web-issues-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7fb;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  white-space: nowrap;
}
.web-issues-table tbody tr:hover { background: #f0f9ff; }
.web-issues-table tbody tr.is-linked-target { background: #dbeafe; outline: 2px solid #38bdf8; outline-offset: -2px; }
.web-issues-table td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  line-height: 1.4;
}
.web-issue-date { white-space: nowrap; }
.web-issue-description { min-width: 260px; max-width: 420px; line-height: 1.45; }
.web-issue-attachments { min-width: 115px; }
.web-issue-attachments a { color: #0369a1; font-weight: 700; }
.web-issue-actions { display: flex; gap: 5px; white-space: nowrap; }
.web-issue-actions .btn-create-dev,
.web-issue-actions .btn-create-capa { min-height: 28px; padding: 4px 8px; font-size: 11px; }
.web-issue-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.web-issue-badge,
.web-issue-severity {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.web-issue-badge.is-serious { background: #fee2e2; color: #991b1b; }
.web-issue-severity.is-unclassified { background: #fff7ed; color: #c2410c; }

#nhap-kho {
  grid-template-rows: auto auto minmax(0, 1fr);
}

#tong-ket {
  grid-template-rows: auto minmax(0, 1fr);
}

#lenh-dung {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.issue-card.is-clickable {
  cursor: pointer;
}

.issue-card.is-clickable:hover {
  border-color: #b9c7d8;
  box-shadow: 0 2px 8px rgba(23, 32, 42, .07);
}

.issue-gmail-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
  transition: border-color .12s, color .12s;
  flex: 0 0 auto;
}

.issue-gmail-link:hover {
  border-color: #2563eb;
  color: #2563eb;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(226, 232, 240, .7);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  transition: box-shadow .2s ease;
}

#san-xuat > .panel:first-of-type {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

#san-xuat > .panel:nth-of-type(2),
#tong-ket > .panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#nhap-kho > .panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.filter-chips-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-chips-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: auto;
  line-height: 1.5;
  transition: border-color .1s, background .1s, color .1s;
}

.chip:hover { border-color: #b9c7d8; color: var(--ink); }

.chip.active               { border-color: var(--blue);  background: var(--blue);    color: #fff; }
.chip.chip-high.active     { border-color: #16803c;      background: #16803c;         color: #fff; }
.chip.chip-mid.active      { border-color: #a35f00;      background: #a35f00;         color: #fff; }
.chip.chip-low.active      { border-color: var(--red);   background: var(--red);      color: #fff; }
.chip.chip-none.active     { border-color: #68727d;      background: #68727d;         color: #fff; }
.chip.chip-serious.active  { border-color: var(--red);   background: var(--red);      color: #fff; }

/* tô nhẹ khi chưa active để gợi ý màu */
.chip.chip-high  { color: #16803c; border-color: #b6dec5; background: #f0faf4; }
.chip.chip-mid   { color: #a35f00; border-color: #f0d48a; background: #fffbee; }
.chip.chip-low   { color: var(--red); border-color: #f4bab6; background: #fff5f4; }
.chip.chip-none  { color: #68727d; }
.chip.chip-serious { color: var(--red); border-color: #f4bab6; background: #fff5f4; }

#chat-luong > .panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

#bao-cao > .panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

#ipc-kpi {
  grid-template-rows: auto minmax(0, 1fr);
}

#ipc-kpi > .panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
}

.ipc-kpi-score-guide {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
  padding: 12px 12px 6px;
}

.ipc-kpi-score-card {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid #64748b;
  border-radius: 10px;
  background: #f8fafc;
}

.ipc-kpi-score-card strong { color: var(--ink); font-size: 18px; }
.ipc-kpi-score-card span { color: var(--muted); font-size: 12px; font-weight: 700; }
.ipc-kpi-score-card.is-error { border-left-color: #8b5cf6; background: #f5f3ff; }
.ipc-kpi-score-card.is-weigh { border-left-color: #0ea5e9; background: #f0f9ff; }
.ipc-kpi-score-card.is-mix { border-left-color: #0f766e; background: #f0fdfa; }
.ipc-kpi-score-card.is-machine { border-left-color: #d97706; background: #fffbeb; }
.ipc-kpi-score-card.is-finish { border-left-color: #16a34a; background: #f0fdf4; }

.ipc-kpi-month-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
}

.ipc-kpi-filter-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ipc-kpi-month-blocks {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 1px 5px;
  scrollbar-width: thin;
}

.ipc-kpi-month-block {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.ipc-kpi-month-block.active {
  border-color: var(--blue);
  background: linear-gradient(135deg, var(--teal), var(--blue));
  color: #fff;
}

.ipc-kpi-clear-aliases {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
}

.ipc-kpi-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 4px 12px 10px;
}

.ipc-kpi-summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.ipc-kpi-summary-card span { color: var(--muted); font-size: 12px; font-weight: 600; }
.ipc-kpi-summary-card strong { color: var(--ink); font-size: 20px; }
.ipc-kpi-summary-card.is-points { border-color: #99f6e4; background: #f0fdfa; }
.ipc-kpi-summary-card.is-points strong { color: #0f766e; }

.ipc-kpi-table-wrap {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.ipc-kpi-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.ipc-kpi-table th,
.ipc-kpi-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: center;
  white-space: nowrap;
}

.ipc-kpi-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3f7;
  color: #334155;
  font-size: 11px;
}

.ipc-kpi-table thead small {
  display: block;
  margin-top: 2px;
  color: #64748b;
  font-weight: 600;
}

.ipc-kpi-table tbody tr:hover { background: #f8fafc; }
.ipc-kpi-table td small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.ipc-kpi-table .ipc-kpi-employee { min-width: 180px; text-align: left; font-weight: 700; }
.ipc-kpi-table tr.ipc-kpi-unresolved { background: #fff7ed; }
.ipc-kpi-alias-editor {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}
.ipc-kpi-alias-editor select {
  min-width: 142px;
  max-width: 190px;
  height: 30px;
  padding: 3px 6px;
  border: 1px solid #fdba74;
  border-radius: 7px;
  background: #fff;
  color: #334155;
  font-size: 11px;
}
.ipc-kpi-alias-editor button {
  height: 30px;
  padding: 3px 8px;
  border: 1px solid #0f766e;
  border-radius: 7px;
  background: #0f766e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.ipc-kpi-table .ipc-kpi-rank { color: var(--muted); font-weight: 700; }
.ipc-kpi-table .ipc-kpi-total-points { color: #0f766e; font-size: 14px; font-weight: 800; }
.ipc-kpi-table .ipc-kpi-unknown { background: #fff7ed; }
.ipc-kpi-table tfoot th,
.ipc-kpi-table tfoot td { position: sticky; bottom: 0; z-index: 1; background: #e6fffb; font-weight: 800; }
.ipc-kpi-rank-col { width: 54px; }
.ipc-kpi-points-col { min-width: 90px; }

.ipc-kpi-data-note {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.report-content {
  padding: 12px;
  overflow: auto;
}
.report-group { margin-bottom: 16px; }
.report-group:last-child { margin-bottom: 0; }
.report-group-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.report-box-row .summary-box { flex: 1 1 130px; }

.report-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 10px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #0f766e 0%, #0284c7 50%, #1a2332 100%);
  color: #fff;
}
.report-banner-icon { font-size: 30px; line-height: 1; }
.report-banner-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.report-banner-period {
  margin-top: 4px;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  font-size: 12px;
  font-weight: 700;
}

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.report-tab-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .1s, background .1s, color .1s;
}
.report-tab-btn:hover { border-color: #b9c7d8; color: var(--ink); }
.report-tab-btn.active { border-color: var(--blue); background: var(--blue); color: #fff; }

.report-donut-row {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 260px;
}
.donut-chart {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.donut-hole {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.donut-center-value { font-size: 18px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.donut-center-label { font-size: 10px; color: var(--muted); margin-top: 2px; }

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-label { flex: 1; }
.legend-value { font-weight: 700; }
.legend-pct { color: var(--muted); min-width: 42px; text-align: right; }

.report-compare { margin-top: 4px; }
.report-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.report-compare-table th, .report-compare-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.report-compare-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
}
.report-compare-table th:not(:first-child),
.report-compare-table td:not(:first-child) { text-align: right; }
.report-compare-table .delta-up   { color: var(--green); font-weight: 700; }
.report-compare-table .delta-down { color: var(--red); font-weight: 700; }
.report-compare-table .delta-flat { color: var(--muted); font-weight: 700; }

.aging-chart { flex: 1 1 260px; min-width: 240px; }
.aging-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.aging-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.aging-label { width: 86px; font-size: 12px; color: var(--ink); flex-shrink: 0; }
.aging-track {
  flex: 1;
  height: 14px;
  background: #eef2f7;
  border-radius: 4px;
  overflow: hidden;
}
.aging-bar {
  height: 100%;
  border-radius: 0 4px 4px 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.aging-value { width: 30px; text-align: right; font-size: 12px; font-weight: 700; color: var(--ink); }

.report-matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.report-matrix-table th, .report-matrix-table td {
  padding: 6px 10px;
  border: 1px solid var(--line);
  text-align: center;
}
.report-matrix-table th:first-child, .report-matrix-table td:first-child {
  text-align: left;
}
.report-matrix-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  background: #f4f7fb;
}
.report-matrix-table tr.report-matrix-total-row { font-weight: 700; background: #f4f7fb; }

.report-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 560px;
}
.report-detail-table th, .report-detail-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.report-detail-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  background: #f4f7fb;
}
.report-detail-table tbody tr:hover { background: #f8fafc; }

.report-ai-review {
  border: 1px solid #fecaca;
  border-left: 4px solid #b42318;
  border-radius: 10px;
  padding: 14px;
  background: #fffafa;
}
.report-ai-note,
.report-ai-disclaimer {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.report-ai-confirmation {
  display: inline-block;
  min-width: 86px;
  padding: 4px 7px;
  border-radius: 999px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
}
.report-ai-confirmation.is-confirmed { background: #dcfce7; color: #166534; }
.report-ai-row-review { display: grid; gap: 6px; min-width: 150px; }
.report-ai-row-review .btn-primary { min-height: 28px; padding: 4px 8px; font-size: 11px; }
.report-ai-approval {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: #fff7f7;
}
.report-ai-approval > div { display: grid; gap: 3px; }
.report-ai-approval span { color: var(--muted); font-size: 12px; }
.report-ai-approval-actions { display: flex !important; grid-auto-flow: column; gap: 8px !important; }
.report-ai-ready { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.report-ai-ready > span { margin: 0; }
.report-ai-approval-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.report-ai-approval-note.is-confirmed { color: #166534; font-weight: 700; }
.report-ai-disclaimer {
  margin: 10px 0 0;
  color: #991b1b;
  font-weight: 600;
}
.report-ai-serious-table td:nth-child(6),
.report-ai-serious-table td:nth-child(7) {
  min-width: 220px;
  white-space: normal;
}

.report-insights ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.report-insights li {
  padding: 8px 12px;
  border-radius: 8px;
  background: #f0fdfa;
  border-left: 3px solid var(--teal);
  font-size: 12.5px;
  line-height: 1.5;
}

.report-assessment-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.report-assessment-reset {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
}

.report-assessment-editor {
  display: block;
  width: 100%;
  min-height: 112px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 8px;
  background: #f0fdfa;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
}

.report-assessment-editor:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}

.report-assessment-hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.report-assessment-print {
  padding: 8px 12px;
  border-radius: 8px;
  background: #f0fdfa;
  border-left: 3px solid var(--teal);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: normal;
}

.report-preset-note {
  align-self: center;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.report-meeting-task-wrap { overflow-x: auto; }
.report-meeting-task-overdue td { background: #fff7ed; }
.report-meeting-task-overdue td:first-child { border-left: 3px solid var(--red); }
.report-meeting-task-empty {
  margin: 0;
  padding: 9px 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, var(--teal), var(--blue), transparent) 1;
  font-weight: 700;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* ── Đầu việc giao ban ───────────────────────────────────── */
#dau-viec-giao-ban { grid-template-rows: auto auto minmax(0, 1fr); }
.meeting-task-heading { align-items: center; }
.meeting-task-controlbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .78);
}
.meeting-task-stats {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
}
.meeting-task-stat-card {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 31px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eff6ff;
}
.meeting-task-stat-card span { color: var(--muted); font-size: 10px; font-weight: 700; white-space: nowrap; }
.meeting-task-stat-card strong { color: var(--ink); font-size: 14px; line-height: 1; }
.meeting-task-stat-card.is-danger { border-color: #fecaca; background: #fff1f2; }
.meeting-task-stat-card.is-danger strong { color: var(--red); }
.meeting-task-stat-card.is-success { border-color: #bbf7d0; background: #f0fdf4; }
.meeting-task-stat-card.is-success strong { color: var(--green); }

.meeting-task-toolbar {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.meeting-task-toolbar label { gap: 3px; font-size: 11px; }
.meeting-task-toolbar label:first-child { flex: 1 1 240px; max-width: 440px; }
.meeting-task-toolbar input,
.meeting-task-toolbar select { min-height: 31px; font-size: 12px; }
.meeting-task-toolbar input { width: 100%; }
.meeting-task-toolbar select { width: 190px; }

.meeting-task-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.meeting-task-table-wrap { min-height: 0; overflow: auto; }
.meeting-task-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  font-size: 12px;
}
.meeting-task-table th,
.meeting-task-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.meeting-task-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7fb;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}
.meeting-task-table tbody tr:hover { background: #f8fafc; }
.meeting-task-table tbody tr.is-done { color: var(--muted); background: #f8fafc; }
.meeting-task-table tbody tr.is-done .meeting-task-content-cell { text-decoration: line-through; }
.meeting-task-done-col,
.meeting-task-done-cell { width: 56px; text-align: center !important; }
.meeting-task-done-input { width: 17px; height: 17px; accent-color: var(--green); cursor: pointer; }
.meeting-task-done-input:disabled { cursor: default; }
.meeting-task-date-cell { white-space: nowrap; }
.meeting-task-content-cell { min-width: 250px; font-weight: 650; line-height: 1.45; }
.meeting-task-note-inline { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.4; }
.meeting-task-docs-cell { min-width: 170px; max-width: 270px; }
.meeting-task-doc-list { display: flex; flex-wrap: wrap; gap: 4px; }
.meeting-task-doc {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 10px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.meeting-task-doc:hover { background: #e0e7ff; color: #312e81; }
.meeting-task-due-overdue { color: var(--red); font-weight: 800; }
.meeting-task-due-today { color: #a35f00; font-weight: 800; }
.meeting-task-completed-date { color: var(--green); font-weight: 750; }
.meeting-task-edit { min-height: 28px; padding: 4px 9px; font-size: 11px; }
.appraisal-modal-card.meeting-task-modal-card { width: min(760px, 96vw); }
#meetingTaskForm { padding: 16px 18px 18px; }
.meeting-task-status-field { gap: 5px; }
.meeting-task-done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}
.meeting-task-done-toggle input { width: 17px; height: 17px; accent-color: var(--green); }
.meeting-task-field-hint { color: var(--muted); font-size: 10px; font-weight: 400; }

@media (max-width: 700px) {
  #dau-viec-giao-ban { overflow: auto; height: auto; }
  .meeting-task-heading .subtle { display: none; }
  .meeting-task-controlbar { display: grid; align-items: stretch; }
  .meeting-task-stats { width: 100%; overflow-x: auto; }
  .meeting-task-stat-card { flex: 1 0 auto; justify-content: center; }
  .meeting-task-toolbar { display: grid; grid-template-columns: 1fr; }
  .meeting-task-toolbar label:first-child { max-width: none; }
  .meeting-task-toolbar select { width: 100%; }
  .meeting-task-modal { padding: 8px; }
}

.map {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  min-height: 0;
  height: 100%;
  min-width: 0;
  overflow: auto;
}

.zone {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f9fbfc;
  display: grid;
  gap: 8px;
  align-content: start;
  min-width: 0;
}

.zone[data-zone="Khu cân"] { grid-column: 1 / 2; border-color: #8aa7d8; }
.zone[data-zone="Hoàn thiện"] { grid-column: 2 / 3; border-color: #d0a24d; }
.zone[data-zone="Xưởng 1"] { grid-column: 1 / 2; border-color: #68a87b; }
.zone[data-zone="Xưởng 2"] { grid-column: 2 / 3; border-color: #9a81d9; }

.zone-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
}

.zone-count {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.rooms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.room {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 7px;
  display: grid;
  gap: 5px;
  min-width: 0;
}

.room.has-work {
  border-color: #b9c7d8;
  background: #fbfdff;
}

.room-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.room-name {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-count {
  min-width: 22px;
  flex: 0 0 auto;
  text-align: center;
  color: #fff;
  background: var(--ink);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 800;
}

.room-orders {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-width: 0;
}

.room-item {
  display: grid;
  gap: 2px;
  min-width: 0;
  border: 1px solid #d9e0e7;
  border-radius: 6px;
  background: #fff;
  padding: 4px 5px;
}

.room-item[data-order] {
  cursor: pointer;
}

.room-item[data-order]:hover,
.room-item[data-order]:focus-visible {
  border-color: #7aa3d8;
  box-shadow: 0 0 0 2px rgba(36, 93, 150, .12);
  outline: none;
}

.room-item.is-selected {
  border-color: #245d96;
  box-shadow: 0 0 0 2px rgba(36, 93, 150, .2);
}

.room-item.has-alert {
  border-color: #f0a03b;
  background: #fff4df;
  box-shadow: inset 0 0 0 1px rgba(163, 95, 0, .18);
}

.room-order {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-person {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-age {
  color: #45515f;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-line {
  color: #6d28d9;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-window {
  color: #344253;
  font-size: 10px;
  line-height: 1.25;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.room-note {
  color: #92400e;
  background: #fef3c7;
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  line-height: 1.25;
  min-width: 0;
  overflow-wrap: anywhere;
}

.timeline-note {
  color: #92400e;
  background: #fef3c7;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  margin-top: 2px;
  display: inline-block;
  overflow-wrap: anywhere;
}

.room-error {
  color: var(--red);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.room.is-empty {
  opacity: .58;
  background: #f6f8fa;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 100%);
  color: var(--teal);
  z-index: 1;
  font-size: 12px;
  font-weight: 700;
}

tbody tr:nth-child(even) {
  background: #f8fafc;
}

tbody tr:hover {
  background: #f0fdfa;
}

.table-wrap {
  height: 100%;
  max-height: none;
  overflow: auto;
}

.alert {
  border: 1px solid #f0c36d;
  border-left: 4px solid var(--amber);
  border-radius: 7px;
  background: #fff8ea;
  padding: 9px 10px;
  font-size: 13px;
}

.alert strong {
  display: block;
  margin-bottom: 3px;
}

.issue-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: none;
  overflow: auto;
}

.issue-card {
  border: 1px solid var(--line);
  border-left: 4px solid #8995a3;
  border-radius: 7px;
  background: #fff;
  padding: 9px 10px;
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.issue-card.is-serious {
  border-color: #efb1ad;
  border-left-color: var(--red);
  background: #fff5f4;
}

.issue-panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#issueDepartmentAiBtn {
  min-height: 30px;
  padding: 5px 10px;
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 800;
}

#issueDepartmentAiBtn:hover { background: #dbeafe; }

.issue-department-panel {
  margin-top: 4px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  overflow: hidden;
}

.issue-department-panel[open] { background: #fff; }

.issue-department-panel > summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 34px;
  padding: 6px 9px;
  cursor: pointer;
  list-style: none;
  font-size: 11px;
  font-weight: 800;
}

.issue-department-panel > summary::-webkit-details-marker { display: none; }
.issue-department-panel > summary::after { content: '▾'; margin-left: auto; color: var(--muted); }
.issue-department-panel[open] > summary::after { content: '▴'; }

.issue-department-badge,
.issue-department-confidence {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
}

.issue-department-badge.is-confirmed { background: #dcfce7; color: #166534; }
.issue-department-badge.is-suggested { background: #dbeafe; color: #1d4ed8; }
.issue-department-badge.is-empty { background: #fff7ed; color: #9a3412; }
.issue-department-confidence.is-high { background: #dcfce7; color: #166534; }
.issue-department-confidence.is-medium { background: #fef3c7; color: #92400e; }
.issue-department-confidence.is-low { background: #fee2e2; color: #991b1b; }

.issue-department-editor {
  display: grid;
  gap: 8px;
  padding: 9px;
  border-top: 1px solid #e2e8f0;
}

.issue-department-ai-copy {
  display: grid;
  gap: 3px;
  padding: 8px;
  border-radius: 7px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 11px;
  line-height: 1.45;
}

.issue-department-ai-copy span { color: #475569; }

.issue-department-fields {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(220px, 1fr);
  gap: 8px;
}

.issue-department-fields label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.issue-department-fields select,
.issue-department-fields input { width: 100%; min-height: 32px; font-size: 12px; }

.issue-department-controls { display: flex; flex-wrap: wrap; gap: 7px; }
.issue-department-controls button { min-height: 29px; padding: 4px 9px; font-size: 11px; }
.issue-department-confirm { background: #166534; color: #fff; }

@media (max-width: 700px) {
  .issue-panel-actions { align-items: flex-end; flex-direction: column; gap: 5px; }
  .issue-department-fields { grid-template-columns: 1fr; }
}


.issue-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.issue-title {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.issue-key-badge {
  font-size: 10px;
  font-weight: 800;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
  vertical-align: middle;
  margin-left: 5px;
}

.issue-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}

.issue-serious-btn {
  min-height: 28px;
  padding: 4px 8px;
  border-color: #ef4444;
  background: #fff;
  color: #b91c1c;
  font-size: 12px;
  white-space: nowrap;
}

.issue-serious-btn:hover { background: #fff1f2; }

.issue-serious-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  background: #dcfce7;
  color: #166534;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.issue-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 7px;
  background: #eef3f7;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.issue-pill.serious {
  background: #ffe1de;
  color: var(--red);
}

.issue-meta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.issue-text {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.issue-thread {
  display: grid;
  gap: 6px;
  margin-top: 4px;
  padding: 8px;
  border: 1px solid #d9e2ec;
  border-radius: 7px;
  background: #f8fafc;
}

.issue-thread-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.issue-reply {
  display: grid;
  gap: 2px;
  padding-top: 6px;
  border-top: 1px solid #e5edf4;
}

.issue-reply:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.issue-reply-head {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.thread-toggle {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
  background: none;
  border: none;
  padding: 3px 0 5px;
  cursor: pointer;
  min-height: auto;
  text-align: left;
}

.thread-toggle:hover { text-decoration: underline; }

.issue-reply-body {
  color: #334155;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.order-flags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.error-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 6px;
  background: #ffe1de;
  color: var(--red);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.timeline {
  display: grid;
  gap: 0;
  padding: 6px 12px 12px;
  height: 100%;
  overflow: auto;
}

.timeline-item {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.timeline-time {
  color: var(--muted);
  font-size: 12px;
}

.timeline-main {
  display: grid;
  gap: 3px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #f7fbff;
}

tr.eff-high {
  background: #effaf2;
}

tr.eff-mid {
  background: #fff8e6;
}

tr.eff-low {
  background: #fff0ee;
}

.eff-pill {
  display: inline-block;
  min-width: 54px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  background: #eef2f5;
  color: var(--ink);
}

.eff-pill.high {
  background: #dff4e5;
  color: #176235;
}

.eff-pill.mid {
  background: #fff1c7;
  color: #8a5a00;
}

.eff-pill.low {
  background: #ffe1de;
  color: var(--red);
}

.dim {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: #eef3f7;
}

.b-can { color: #174a8b; background: #e6eefb; }
.b-pha { color: #11663a; background: #e4f4ea; }
.b-chay { color: #6f4300; background: #fff0d6; }
.b-ht { color: #5724a3; background: #eee8fb; }

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  header {
    position: static;
    width: auto;
  }

  .app-main {
    margin-left: 0;
  }

  main, .stats {
    grid-template-columns: 1fr;
  }

  .map {
    grid-template-columns: 1fr;
  }

  .zone[data-zone] {
    grid-column: auto;
    grid-row: auto;
  }

  .rooms {
    grid-template-columns: 1fr;
  }

  .room-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .room-list {
    grid-template-columns: 1fr;
  }
}
/* ── Chat Panel ───────────────────────────────── */
.chat-toggle {
  position: fixed;
  bottom: 22px;
  right: 22px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(37,99,235,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, background .15s;
  padding: 0;
  min-height: auto;
}

.chat-toggle:hover { transform: scale(1.09); background: #1d4ed8; }
.chat-toggle.is-open { background: #374151; }

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 28px rgba(23,32,42,.12);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  z-index: 199;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}

.chat-panel.is-open { transform: translateX(0); }

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #0f766e, #134e4a);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title { font-size: 14px; font-weight: 700; display: block; }
.chat-header-sub   { font-size: 11px; color: rgba(255,255,255,.5); display: block; }

.chat-close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  min-height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-messages {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg { display: flex; flex-direction: column; gap: 3px; max-width: 88%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai   { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg.user .chat-bubble {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.ai .chat-bubble {
  background: #f1f5f9;
  color: var(--ink);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--line);
}

.chat-msg-time {
  font-size: 10px;
  color: var(--muted);
  padding: 0 4px;
}

.chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatBounce .9s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .30s; }

@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}

.chat-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 12px;
  line-height: 1.6;
}

.chat-input-row {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 7px;
  background: var(--panel);
}

.chat-input {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--ink);
  resize: none;
}

.chat-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 148, 136, .12); }

.chat-send {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 8px;
  white-space: nowrap;
}

.chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* ── Deviation ──────────────────────────────────────────── */
#deviation {
  grid-template-rows: auto minmax(0, 1fr);
}

#deviation > .panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#devListView {
  min-height: 0;
  overflow-y: auto;
}

#devFormView {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.dev-form-body {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

.record-disabled-notice {
  margin: 0 16px 8px;
  padding: 10px 12px;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 12px;
  line-height: 1.5;
}

.record-disabled-notice strong,
.record-disabled-notice span { display: block; }

.record-disabled-row { background: #fff7f7; color: #7f1d1d; }
.record-disabled-row td { opacity: .78; }
.record-disabled-row td:first-child { text-decoration: line-through; }
.record-disabled-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border: 1px solid #fca5a5;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 10px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.btn-record-disable { background: #b91c1c; color: #fff; }
.btn-record-disable.is-restore { background: #166534; }

.dev-section-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 16px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}

.dev-section-title:first-child { margin-top: 0; }

.dev-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}

.dev-grid.two  { grid-template-columns: 1fr 1fr; }
.dev-grid.full { grid-template-columns: 1fr; }

.dev-field { display: grid; gap: 4px; }

.dev-field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.dev-field input,
.dev-field select,
.dev-field textarea {
  min-height: 32px;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}

.dev-field textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.4;
}

.dev-field input[readonly] {
  background: #f4f6f8;
  color: var(--muted);
}

.ai-fill-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
  font-size: 13px;
  color: #1d4ed8;
}

.ai-fill-banner.done {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.ai-fill-banner.error {
  background: #fff5f4;
  border-color: #fca5a5;
  color: var(--red);
}

.ai-spinner {
  width: 16px; height: 16px;
  border: 2px solid #bfdbfe;
  border-top-color: #1d4ed8;
  border-radius: 50%;
  animation: spinAi .7s linear infinite;
  flex: 0 0 auto;
}

@keyframes spinAi { to { transform: rotate(360deg); } }

.ai-banner-text { flex: 1; }

.dev-form-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fafc, #f0f4f8);
  flex-wrap: wrap;
  align-items: center;
}

.btn-ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 600;
}

.btn-ghost:hover { border-color: #94a3b8; transform: none; box-shadow: none; }

.linked-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  white-space: nowrap;
  cursor: default;
}

.btn-create-dev {
  border-color: #7c3aed;
  background: #7c3aed;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 5px;
  line-height: 1.4;
}

.btn-create-dev:hover { background: #6d28d9; border-color: #6d28d9; }

/* ── CAPA ───────────────────────────────────────────────── */
#capa {
  grid-template-rows: auto minmax(0, 1fr);
}

#capa > .panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#capaListView {
  min-height: 0;
  overflow-y: auto;
}

#capaFormView {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.capa-actions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 6px;
}

.capa-action-plan-wrap {
  overflow-x: auto;
  margin-bottom: 6px;
  max-width: 100%;
  overscroll-behavior-inline: contain;
}

.capa-action-plan-table {
  table-layout: fixed;
  min-width: 760px;
}

.capa-action-plan-table .capa-action-col { width: auto; }
.capa-action-plan-table .capa-responsible-col { width: 180px; }
.capa-action-plan-table .capa-deadline-col { width: 126px; }
.capa-action-plan-table .capa-actual-col { width: 140px; }
.capa-action-plan-table .capa-remove-col { width: 38px; }

.capa-actions-table th {
  background: #eef3f7;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 8px;
  text-align: left;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.capa-actions-table td {
  padding: 3px 4px;
  border: 1px solid var(--line);
  vertical-align: middle;
}

.capa-actions-table input,
.capa-actions-table textarea {
  min-height: 28px;
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  color: var(--ink);
  resize: vertical;
}

.capa-actions-table input:focus,
.capa-actions-table textarea:focus {
  border-color: var(--blue);
  background: #fff;
  outline: none;
}

.capa-action-plan-table .ca-action {
  display: block;
  min-height: 40px;
  line-height: 1.4;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  resize: none;
}

.ca-remove {
  min-height: 24px;
  padding: 2px 5px;
  font-size: 16px;
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
  border-radius: 4px;
  width: 28px;
  line-height: 1;
}

.ca-remove:hover { border-color: var(--red); color: var(--red); background: #fff5f4; }

/* ── Investigation STT button & 5-Why panel ─────────────── */
.invest-stt-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  background: #f4f6f8;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #374151;
  cursor: pointer;
  line-height: 28px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.invest-stt-btn:hover { background: #e0e7f0; border-color: var(--blue); color: var(--blue); }
.invest-stt-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.invest-stt-btn:disabled { cursor: default; opacity: 0.6; }

.invest-detail-row > td { padding: 0 !important; }
.invest-detail-wrap {
  background: #f0f5ff;
  border-top: 2px solid var(--blue);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 12px;
}
.invest-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.invest-detail-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.invest-detail-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.invest-detail-close:hover { color: var(--red); }

.five-why-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid var(--line);
}
.five-why-table th {
  background: #e8eef6;
  padding: 6px 8px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  color: #374151;
}
.five-why-table td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.five-why-table tr:last-child td { border-bottom: none; }
.five-why-table textarea,
.five-why-table input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 5px;
  resize: none;
  overflow: hidden;
  min-height: 34px;
}
#devInvestBody textarea {
  overflow: hidden;
  resize: none;
  min-height: 34px;
}
.five-why-table textarea:focus,
.five-why-table input[type="text"]:focus { outline: none; border-color: var(--blue); }

.add-why-btn {
  font-size: 12px;
  padding: 4px 10px;
  background: #fff;
  border: 1px dashed var(--blue);
  color: var(--blue);
  border-radius: 4px;
  cursor: pointer;
}
.add-why-btn:hover { background: #eff5ff; }

.btn-create-capa {
  border-color: #0891b2;
  background: #0891b2;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 5px;
  line-height: 1.4;
}

.btn-create-capa:hover { background: #0e7490; border-color: #0e7490; }

.btn-create-ra {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-height: 26px;
  padding: 2px 8px;
  border-radius: 5px;
  line-height: 1.4;
}

.btn-create-ra:hover { background: #155e2d; border-color: #155e2d; }

.linked-badge.dev-link {
  border-color: #c4b5fd;
  background: #f5f3ff;
  color: #5b21b6;
}

.linked-badge.capa-link {
  border-color: #a5f3fc;
  background: #ecfeff;
  color: #0e7490;
}

.linked-badge[data-open-dev],
.linked-badge[data-open-capa] {
  cursor: pointer;
}

.linked-badge[data-open-dev]:hover { background: #ede9fe; border-color: #a78bfa; }
.linked-badge[data-open-capa]:hover { background: #cffafe; border-color: #67e8f9; }

.issue-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

/* ── Login overlay ──────────────────────────── */
#loginOverlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f766e 0%, #134e4a 35%, #1a2332 100%);
}
.login-card {
  background: rgba(255, 255, 255, .95); border: 1px solid rgba(226, 232, 240, .5);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25), 0 0 80px rgba(15, 118, 110, .15);
  backdrop-filter: blur(20px);
  padding: 40px 36px; width: 380px; max-width: calc(100vw - 32px);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-icon { font-size: 36px; margin-bottom: 8px; }
.login-logo h2 { margin: 0 0 4px; font-size: 18px; color: #1a2332; }
.login-logo .login-sub { color: var(--muted); font-size: 13px; }
.login-card label { margin-bottom: 14px; }
.login-card input[type="text"],
.login-card input[type="password"] { width: 100%; min-height: 40px; font-size: 14px; padding: 8px 12px; border-radius: 8px; transition: border-color .15s, box-shadow .15s; }
.login-card input[type="text"]:focus,
.login-card input[type="password"]:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 148, 136, .15); }
.login-btn { width: 100%; min-height: 42px; font-size: 15px; font-weight: 700; margin-top: 4px; border-radius: 10px; }
.login-btn:disabled { opacity: .6; cursor: not-allowed; }
#loginError { margin-top: 10px; color: var(--red); font-size: 13px; text-align: center; min-height: 18px; }

/* ── Sidebar user / logout ──────────────────── */
body.show-login > header,
body.show-login > .app-main,
body.show-login > #chatToggle,
body.show-login > #chatPanel { display: none !important; }

.sidebar-user {
  border-top: 1px solid rgba(94, 234, 212, .15);
  padding-top: 10px; display: flex; flex-direction: column; gap: 5px;
}
.sidebar-user-name { color: #fff; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { color: rgba(94, 234, 212, .6); font-size: 11px; }
.logout-btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.14); color: #d8e1ea; font-size: 12px; min-height: 30px; padding: 4px 10px; }
.logout-btn:hover { background: rgba(255,255,255,.15); transform: none; box-shadow: none; }
body.sidebar-collapsed .sidebar-user { display: none; }

/* ── Role-based visibility ──────────────────── */
body.role-viewer .role-editor-only { display: none !important; }
body:not(.role-admin) .role-admin-only { display: none !important; }
/* role-manager-only: chỉ trưởng phòng thấy, không mở cho admin */
body:not(.role-manager) .role-manager-only { display: none !important; }
/* manager-nav: chỉ admin + manager thấy */
body:not(.role-admin):not(.role-manager) .manager-nav { display: none !important; }
/* qa-nav: tất cả trừ viewer */
body.role-viewer .qa-nav { display: none !important; }

/* ── User management section ────────────────── */
.user-role-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.user-role-badge.role-admin { background: #fef3c7; color: #92400e; }
.user-role-badge.role-manager { background: #d1fae5; color: #065f46; }
.user-role-badge.role-qa-specialist { background: #dbeafe; color: #1e40af; }
.user-role-badge.role-viewer { background: #f1f5f9; color: #475569; }

/* ── Manager-only field groups ───────────────── */
/* Hiển thị note khóa cho non-manager */
.manager-input-wrap .manager-lock-note { display: none; }
body:not(.role-admin):not(.role-manager) .manager-input-wrap .manager-lock-note {
  display: block; font-size: 11px; color: var(--muted); font-style: italic;
  margin-bottom: 4px;
}
/* Làm xám và chặn tương tác */
body:not(.role-admin):not(.role-manager) .manager-input-wrap input,
body:not(.role-admin):not(.role-manager) .manager-input-wrap select,
body:not(.role-admin):not(.role-manager) .manager-input-wrap textarea {
  background: #f0f2f5 !important; color: var(--muted) !important;
  pointer-events: none; cursor: not-allowed;
}

/* ── Notification badge ──────────────────────── */
.notif-count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: #fff; border-radius: 10px;
  font-size: 10px; font-weight: 700; padding: 0 5px; min-width: 18px; height: 18px;
  margin-left: 4px; vertical-align: middle; line-height: 1;
}

/* ── Change password modal ───────────────────── */
#changePwModal {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(23,32,42,.5);
  display: flex; align-items: center; justify-content: center;
}
#changePwModal .modal-card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  padding: 32px; width: 360px; max-width: calc(100vw - 32px);
}
#changePwModal h3 { margin: 0 0 20px; font-size: 16px; }
#changePwModal label { margin-bottom: 12px; }
#changePwModal input { width: 100%; min-height: 38px; font-size: 14px; }
#cpError { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }

.user-form-panel {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 20px 24px; max-width: 480px; margin-top: 12px;
}
.user-form-panel h3 { margin: 0 0 16px; font-size: 15px; }
.user-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.user-form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ── Tổng kết: LSX search ───────────────────────────────── */
.tk-search-wrap { padding: 0 0 14px; }
.tk-search-inner { position: relative; display: inline-block; width: 100%; max-width: 340px; }
.tk-search-input {
  width: 100%; padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); box-sizing: border-box;
}
.tk-search-input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px #3b82f620; }
.tk-search-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 200;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
  max-height: 220px; overflow-y: auto; padding: 4px 0; margin: 0;
  list-style: none; box-shadow: 0 6px 18px rgba(0,0,0,.12);
}
.tk-search-item {
  padding: 7px 14px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tk-search-item:hover, .tk-search-item.tk-active { background: var(--blue); color: #fff; }

/* ── Date Range Filter + Summary row ───── */
.filter-summary-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 24px;
  padding-bottom: 4px;
}
.filter-summary-row .date-range-filter { flex: 0 0 auto; }
.summary-mini-table {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
}
.summary-box {
  flex: 1 1 110px;
  min-width: 90px;
  border-radius: 12px;
  padding: 7px 12px;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-left: 5px solid var(--muted);
  transition: transform .15s ease, box-shadow .15s ease;
}

.summary-box:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 118, 110, .08);
}
.summary-box .summary-box-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--ink);
}
.summary-box .summary-box-label {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
}
.summary-box.c-blue   { background: #eaf1fd; border-left-color: var(--blue); }
.summary-box.c-blue   .summary-box-value { color: var(--blue); }
.summary-box.c-green  { background: #eaf8ee; border-left-color: var(--green); }
.summary-box.c-green  .summary-box-value { color: var(--green); }
.summary-box.c-amber  { background: #fff8e8; border-left-color: var(--amber); }
.summary-box.c-amber  .summary-box-value { color: var(--amber); }
.summary-box.c-violet { background: #f3edfc; border-left-color: var(--violet); }
.summary-box.c-violet .summary-box-value { color: var(--violet); }
.summary-box.c-red    { background: #fcebe9; border-left-color: var(--red); }
.summary-box.c-red    .summary-box-value { color: var(--red); }

.date-range-filter {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 0 12px;
}
.date-preset-group { display: flex; gap: 4px; }
.date-preset-btn {
  padding: 4px 14px; border-radius: 16px;
  border: 1px solid var(--line, #d1d5db);
  background: transparent; color: var(--muted);
  font-size: 0.82rem; cursor: pointer; line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.date-preset-btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.date-preset-btn:hover:not(.active) { background: var(--bg-alt, #f3f4f6); }
.date-custom-group {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.date-custom-group label {
  font-size: 0.82rem; color: var(--muted);
  display: flex; align-items: center; gap: 4px;
}
.date-custom-group input[type="date"] {
  padding: 3px 7px; border: 1px solid var(--line, #d1d5db);
  border-radius: 6px; font-size: 0.82rem; color: var(--text);
  background: var(--card);
}

/* ── Record Comments (Discussion box in DEV / CAPA) ─────── */
.record-comments-wrap {
  border-top: 1px solid var(--line);
  padding: 10px 16px 12px;
  background: #f9fbfc;
  flex-shrink: 0;
}
.record-comments-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}
.comments-list {
  max-height: 190px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.comment-empty {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  padding: 2px 0;
}
.comment-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
}
.comment-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.comment-author { font-weight: 700; color: var(--blue); }
.comment-body { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.comment-input-row { display: flex; gap: 8px; align-items: flex-end; }
.comment-input {
  flex: 1;
  min-width: 0;
  resize: none;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: inherit;
  min-height: 34px;
  background: #fff;
  color: var(--ink);
}
.comment-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13, 148, 136, .1); }
.btn-comment-send {
  white-space: nowrap;
  min-height: 34px;
  padding: 4px 14px;
  font-size: 13px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 600;
}
.btn-comment-send:hover { background: #1d4ed8; }
.btn-comment-send:disabled { opacity: .55; cursor: not-allowed; }

/* ── Risk Assessment ────────────────────────────────────────── */
#danh-gia-rui-ro {
  grid-template-rows: auto minmax(0, 1fr);
}

#danh-gia-rui-ro > .panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#raListView {
  min-height: 0;
  overflow-y: auto;
}

#raFormView {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.ra-risk-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  background: #eef2f5;
  color: var(--muted);
}

.ra-risk-badge.risk-low      { background: #dcfce7; color: #15803d; }
.ra-risk-badge.risk-mid      { background: #fef9c3; color: #854d0e; }
.ra-risk-badge.risk-high     { background: #ffedd5; color: #c2410c; }
.ra-risk-badge.risk-critical { background: #fee2e2; color: #b91c1c; }

.filter-row td { padding: 3px 4px; background: #f7fafb; }


/* ── Tổng kết: hồ sơ DEV/CAPA/RA liên quan LSX ─────────── */
#tkRelated.has-content {
  margin: 8px 0 12px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tk-related-group { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.tk-related-label { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }

/* ── Badge "Chờ duyệt" (DEV/CAPA gửi duyệt) ─────────────── */
.review-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid #fcd34d;
  background: #fef9c3;
  color: #92400e;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Việc của tôi ────────────────────────────────────────── */
.mytask-group { margin-bottom: 20px; }
.mytask-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.mytask-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e2e8f0;
  color: #334155;
  font-size: 11px;
  line-height: 1;
  vertical-align: middle;
}
.mytask-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  border-radius: 6px;
}
.mytask-row:hover { background: #f1f5f9; }
.mytask-icon { flex: 0 0 auto; font-size: 15px; }
.mytask-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.mytask-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mytask-meta { font-size: 11.5px; color: var(--muted); }
.mytask-tag {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.mytask-tag.mytask-overdue { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.mytask-tag.mytask-soon    { background: #fef9c3; color: #854d0e; border: 1px solid #fcd34d; }

/* Nút Duyệt nhanh trong "Việc của tôi" (chỉ hiện ở nhóm Chờ tôi duyệt) */
.mytask-approve {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #15803d;
  background: #16a34a;
  color: #fff;
  cursor: pointer;
}
.mytask-approve:hover { background: #15803d; transform: none; box-shadow: none; }
.mytask-approve:disabled { opacity: .6; cursor: default; }

/* ── Small utility buttons: no hover lift ────────────── */
.section-filters button:hover,
.date-preset-btn:hover,
.sidebar-filters button:hover,
.ca-remove:hover,
.add-why-btn:hover,
.invest-stt-btn:hover,
.thread-toggle:hover,
.invest-detail-close:hover,
.chat-close:hover,
.report-tab-btn:hover,
.chip:hover,
#asOfNowBtn:hover,
#reloadButton:hover,
#cpSaveBtn:hover,
#cpCancelBtn:hover,
#actFilterBtn:hover,
#notifRefreshBtn:hover { transform: none; box-shadow: none; }

/* ── Theo dõi sản xuất (Gantt chart) ────────────────── */
#theo-doi-sx {
  grid-template-rows: auto auto minmax(0, 1fr);
}

#theo-doi-sx > .panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

/* ─ Filters ─ */
.gantt-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0;
}

.gantt-filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gantt-filter-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.gantt-filters input,
.gantt-filters select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}

.gantt-filters input:focus,
.gantt-filters select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}

.gantt-filters input[type="date"] { min-width: 140px; }
.gantt-filters input[type="text"],
.gantt-filters input[type="search"] { min-width: 230px; }
.gantt-filters select { min-width: 140px; }

/* ─ Container ─ */
.gantt-container {
  overflow: auto;
  min-height: 0;
  flex: 1;
}

/* ─ Time axis ─ */
.gantt-time-axis {
  display: flex;
  align-items: stretch;
  padding: 0 0 0 220px;
  background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 100%);
  border-bottom: 2px solid var(--line);
  min-height: 32px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.gantt-time-track {
  flex: 1;
  position: relative;
  min-height: 32px;
}

.gantt-time-label {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  color: var(--teal);
  text-align: center;
  padding: 6px 2px;
  white-space: nowrap;
  transform: translateX(-50%);
}

.gantt-time-label::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 6px;
  background: rgba(15, 118, 110, .3);
}

/* ─ Body ─ */
.gantt-body {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

/* ─ Rows ─ */
.gantt-row {
  display: flex;
  align-items: stretch;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}

.gantt-row:nth-child(even) { background: #f8fafc; }
.gantt-row:hover { background: #f0fdfa; }

/* ─ Label column ─ */
.gantt-label {
  flex: 0 0 220px;
  width: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4px 12px;
  border-right: 1px solid var(--line);
  min-width: 0;
}

.gantt-order {
  font-size: 12px;
  font-weight: 800;
  color: var(--blue);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .12s;
}

.gantt-order:hover { color: var(--teal); text-decoration: underline; }

.gantt-product {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt-product.is-missing {
  font-weight: 400;
  font-style: italic;
  color: #94a3b8;
}

/* ─ Bars area ─ */
.gantt-bars {
  flex: 1;
  position: relative;
  min-height: 36px;
  padding: 6px 0;
}

.gantt-bar {
  position: absolute;
  top: 8px;
  height: 24px;
  border-radius: 4px;
  min-width: 3px;
  cursor: default;
  transition: opacity .12s, filter .12s;
  opacity: .85;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.gantt-bar:hover { opacity: 1; filter: brightness(1.08); }

.gantt-bar-label {
  font-size: 9px;
  font-weight: 700;
  color: rgba(255, 255, 255, .9);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt-bar-can  { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.gantt-bar-pha  { background: linear-gradient(135deg, #10b981, #34d399); }
.gantt-bar-chay { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.gantt-bar-ht   { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }

.gantt-issue-marker {
  position: absolute;
  top: 13px;
  z-index: 4;
  width: 12px;
  height: 12px;
  min-width: 12px;
  min-height: 12px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #dc2626;
  box-shadow: 0 0 0 1px rgba(153, 27, 27, .35), 0 2px 6px rgba(127, 29, 29, .35);
  color: #fff;
  cursor: help;
  transform: translateX(-50%);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.gantt-issue-marker:hover,
.gantt-issue-marker:focus-visible {
  z-index: 5;
  outline: none;
  background: #b91c1c;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, .28), 0 3px 8px rgba(127, 29, 29, .4);
  transform: translateX(-50%) scale(1.25);
}

.gantt-issue-marker.is-group {
  top: 11px;
  width: 17px;
  height: 17px;
  min-width: 17px;
  min-height: 17px;
}

.gantt-issue-marker.is-group span {
  display: block;
  font-size: 8px;
  font-weight: 800;
  line-height: 13px;
  text-align: center;
}

/* ─ Tooltip ─ */
.gantt-tooltip {
  position: absolute;
  z-index: 9000;
  background: rgba(26, 35, 50, .95);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  max-width: 260px;
  backdrop-filter: blur(8px);
  display: none;
}

.gantt-tooltip.is-issue {
  width: max-content;
  max-width: min(360px, calc(100vw - 24px));
  max-height: min(440px, calc(100vh - 24px));
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, .45);
  background: rgba(46, 20, 24, .97);
}

.gantt-tooltip-issue-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-weight: 800;
}

.gantt-tooltip-error-dot { background: #ef4444; }

.gantt-tooltip-issue {
  padding: 7px 0;
  border-top: 1px solid rgba(255, 255, 255, .14);
}

.gantt-tooltip-issue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.gantt-tooltip-issue-meta {
  margin-top: 2px;
  color: #fecaca;
  font-size: 10px;
  font-weight: 700;
}

.gantt-tooltip-issue-text {
  margin-top: 5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.gantt-tooltip-issue-detail {
  margin-top: 3px;
  color: rgba(255, 255, 255, .86);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.gantt-tooltip-issue-detail span { color: rgba(255, 255, 255, .58); }

.gantt-tooltip-more {
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, .14);
  color: #fecaca;
  font-size: 10px;
  font-weight: 700;
}

.gantt-tooltip-stage {
  font-weight: 700;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gantt-tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gantt-tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.gantt-tooltip-label { color: rgba(255, 255, 255, .6); }

/* ─ Legend ─ */
.gantt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 0 0 12px 12px;
}

.gantt-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink);
  font-weight: 600;
}

.gantt-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.gantt-legend-issue-marker {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #dc2626;
  box-shadow: 0 0 0 1px rgba(153, 27, 27, .35);
}

/* ─ Empty + count ─ */
.gantt-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.gantt-count {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ─ Responsive ─ */
@media (max-width: 768px) {
  .gantt-filters { flex-direction: column; }
  .gantt-label { flex: 0 0 150px; width: 150px; padding-inline: 8px; }
  .gantt-time-axis { padding-left: 150px; }
  .gantt-order { font-size: 11px; }
}

/* ── Print overrides ─────────────────────────────────── */
@media print {
  .gantt-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .gantt-legend-dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .gantt-issue-marker,
  .gantt-legend-issue-marker { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Kế hoạch thẩm định ───────────────────────────── */
#ke-hoach-tham-dinh {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.appraisal-heading > div {
  display: grid;
  gap: 3px;
}

.appraisal-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.appraisal-stat-card {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.appraisal-stat-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 9px;
  background: #ecfeff;
  font-size: 17px;
}

.appraisal-stat-card.is-warning .appraisal-stat-icon { background: #fffbeb; }
.appraisal-stat-card.is-danger .appraisal-stat-icon { background: #fef2f2; }
.appraisal-stat-card.is-success .appraisal-stat-icon { background: #ecfdf5; }
.appraisal-stat-body { min-width: 0; }
.appraisal-stat-value { font-size: 20px; font-weight: 800; line-height: 1; }
.appraisal-stat-label { margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }

.appraisal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .7);
}

.appraisal-toolbar label { gap: 3px; font-size: 11px; }
.appraisal-toolbar input,
.appraisal-toolbar select {
  min-height: 31px;
  width: 170px;
  font-size: 12px;
}
.appraisal-toolbar label:first-child { flex: 1 1 240px; }
.appraisal-toolbar label:first-child input { width: 100%; }

.appraisal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.appraisal-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}
.appraisal-status.is-scheduled { background: #e0f2fe; color: #0369a1; }
.appraisal-status.is-in_progress { background: #fef3c7; color: #92400e; }
.appraisal-status.is-completed { background: #d1fae5; color: #065f46; }
.appraisal-status.is-overdue { background: #fee2e2; color: #b91c1c; }

.appraisal-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .62);
  backdrop-filter: blur(3px);
}

.appraisal-modal-card {
  width: min(900px, 96vw);
  max-height: 92vh;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}

.appraisal-modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
}

.appraisal-modal-head h3 { margin: 0 0 3px; font-size: 18px; }
.appraisal-close {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.appraisal-close:hover { color: var(--ink); box-shadow: none; transform: none; }

#appraisalForm { padding: 16px 18px 18px; }
.appraisal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px 14px;
}
.appraisal-form-grid input,
.appraisal-form-grid select,
.appraisal-form-grid textarea { width: 100%; }
.appraisal-form-grid textarea { resize: vertical; }
.appraisal-span-2 { grid-column: 1 / -1; }

.appraisal-form-section {
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}
.appraisal-form-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.appraisal-form-section-head h4 { margin: 0 0 2px; font-size: 14px; }
.appraisal-form-section-head button { min-height: 29px; padding: 4px 9px; font-size: 11px; }

.appraisal-assignment-table-wrap { overflow-x: auto; }
.appraisal-assignment-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.appraisal-assignment-table th {
  padding: 6px 7px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  text-align: left;
  text-transform: uppercase;
}
.appraisal-assignment-table td { padding: 5px 3px; }
.appraisal-assignment-table input { width: 100%; min-width: 135px; min-height: 31px; font-size: 12px; }
.appraisal-assignment-table .appraisal-task-input { min-width: 230px; }
.appraisal-remove-row {
  min-height: 29px;
  padding: 3px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--red);
  font-size: 15px;
}
.appraisal-remove-row:hover { border-color: #fecaca; background: #fff1f2; box-shadow: none; transform: none; }

.appraisal-form-actions {
  position: sticky;
  bottom: -18px;
  display: flex;
  gap: 8px;
  margin: 18px -18px -18px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
}
.appraisal-action-spacer { flex: 1; }
.btn-danger {
  border-color: #fecaca;
  background: #fff;
  color: var(--red);
}
.btn-danger:hover { background: #fff1f2; box-shadow: none; }

.appraisal-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 7000;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: 9px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .25);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .appraisal-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  #ke-hoach-tham-dinh { overflow: auto; height: auto; }
  .appraisal-heading { align-items: flex-start; }
  .appraisal-heading .subtle { display: none; }
  .appraisal-stats { grid-template-columns: 1fr 1fr; }
  .appraisal-toolbar { display: grid; grid-template-columns: 1fr 1fr; }
  .appraisal-toolbar label,
  .appraisal-toolbar label:first-child { width: auto; }
  .appraisal-toolbar input,
  .appraisal-toolbar select { width: 100%; }
  .appraisal-form-grid { grid-template-columns: 1fr; }
  .appraisal-span-2 { grid-column: 1; }
  .appraisal-modal { padding: 0; place-items: stretch; }
  .appraisal-modal-card { width: 100%; max-height: 100vh; border-radius: 0; }
}

/* ── Bảng kế hoạch thẩm định tổng thể ───────────────── */
#ke-hoach-tham-dinh {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.appraisal-panel {
  min-width: 0;
}

.appraisal-master-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #fff;
}

.appraisal-master-table {
  width: 100%;
  min-width: 1680px;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ink);
  font-size: 11px;
}

.appraisal-master-table th,
.appraisal-master-table td {
  padding: 8px 9px;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  vertical-align: middle;
}

.appraisal-master-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #d9ead3;
  color: #172033;
  font-size: 10px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .025em;
  white-space: nowrap;
}

.appraisal-master-table thead tr:first-child th {
  top: 0;
  height: 36px;
}

.appraisal-master-table thead tr:nth-child(2) th {
  top: 36px;
  height: 31px;
}

.appraisal-master-table th:first-child,
.appraisal-master-table td:first-child {
  border-left: 1px solid #cbd5e1;
}

.appraisal-master-table .empty {
  height: 150px;
  text-align: center;
}

.appraisal-plan-row {
  background: #fff;
}

.appraisal-plan-row:hover > td {
  background-color: #f0fdfa;
}

.appraisal-plan-row.is-overdue > td:not(.appraisal-group-cell):not(.appraisal-content-cell) {
  background-color: #fff8f8;
}

.appraisal-stt {
  width: 46px;
  text-align: center;
  font-weight: 800;
}

.appraisal-group-cell {
  width: 150px;
  max-width: 190px;
  background: #ede9fe;
  color: #4c1d95;
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

.appraisal-content-cell {
  width: 180px;
  max-width: 230px;
  background: #f5f3ff;
  line-height: 1.45;
}

.appraisal-content-cell strong {
  display: block;
  font-size: 12px;
}

.appraisal-content-cell span {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-size: 9px;
  font-weight: 800;
}

.appraisal-col-stt { width: 46px; }
.appraisal-col-stage { width: 70px; }

.appraisal-stage {
  display: inline-grid;
  min-width: 34px;
  min-height: 27px;
  place-items: center;
  border-radius: 6px;
  background: #e2e8f0;
  color: #334155;
  font-weight: 900;
}

.appraisal-stage.is-dq { background: #fce7f3; color: #9d174d; }
.appraisal-stage.is-iq { background: #dbeafe; color: #1d4ed8; }
.appraisal-stage.is-oq { background: #fef3c7; color: #92400e; }
.appraisal-stage.is-pq { background: #d1fae5; color: #047857; }

.appraisal-work-cell {
  width: 260px;
  min-width: 240px;
  line-height: 1.45;
}

.appraisal-owner-cell {
  width: 100px;
  font-weight: 800;
  text-align: center;
}

.appraisal-frequency-head,
.appraisal-frequency-values th,
.appraisal-frequency-cell,
.appraisal-change-frequency {
  background: #ffedd5;
}

.appraisal-frequency-values th,
.appraisal-frequency-cell {
  width: 42px;
  min-width: 42px;
  text-align: center;
}

.appraisal-frequency-cell strong {
  color: #c2410c;
  font-size: 19px;
  line-height: 1;
}

.appraisal-change-frequency {
  color: #9a3412;
  font-weight: 800;
  text-align: center;
}

.appraisal-date-cell {
  width: 96px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.appraisal-notes-cell {
  width: 155px;
  max-width: 210px;
  color: #475569;
  line-height: 1.4;
}

.appraisal-row-actions {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.appraisal-row-actions button {
  min-height: 29px;
  padding: 4px 7px;
  font-size: 10px;
  white-space: nowrap;
}

.appraisal-modal-card {
  width: min(1040px, 96vw);
}

.appraisal-criteria-section {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
}

.appraisal-criteria-table-wrap {
  overflow-x: auto;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.appraisal-criteria-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 11px;
}

.appraisal-criteria-table th {
  padding: 8px;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  background: #ede9fe;
  color: #4c1d95;
  font-size: 10px;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.appraisal-criteria-table th:first-child { width: 90px; }
.appraisal-criteria-table th:nth-child(2) { width: 42%; }
.appraisal-criteria-table th:nth-child(3) { width: 160px; }
.appraisal-criteria-table th:nth-child(4) { width: 170px; }
.appraisal-criteria-table th:last-child { width: 42px; border-right: 0; }

.appraisal-criteria-table td {
  padding: 6px;
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.appraisal-criteria-table tr:last-child td { border-bottom: 0; }
.appraisal-criteria-table td:last-child { border-right: 0; text-align: center; }

.appraisal-criteria-table input,
.appraisal-criteria-table select {
  width: 100%;
  min-height: 33px;
  font-size: 11px;
}

.appraisal-criterion-stage {
  color: #4c1d95;
  font-weight: 900;
  text-align: center;
}

.appraisal-criterion-work {
  min-width: 280px;
}

.appraisal-remove-criterion {
  min-height: 29px;
  padding: 3px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--red);
  font-size: 16px;
}

.appraisal-remove-criterion:hover {
  border-color: #fecaca;
  background: #fff1f2;
  box-shadow: none;
  transform: none;
}

@media (max-width: 700px) {
  .appraisal-panel {
    min-height: 540px;
  }

  .appraisal-master-wrap {
    overflow: auto;
  }

}

/* ── Chi tiết kế hoạch: thời gian chỉ tiêu và phân công mở rộng ── */
.appraisal-date-cell {
  width: 145px;
  min-width: 135px;
  line-height: 1.4;
  white-space: normal;
}

.appraisal-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 34px;
  min-height: 31px;
  padding: 3px 7px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
}

.appraisal-expand-btn small {
  color: var(--teal);
  font-size: 12px;
  transition: transform .16s ease;
}

.appraisal-expand-btn:hover,
.appraisal-expand-btn.is-open {
  border-color: #99f6e4;
  background: #ecfdf5;
  box-shadow: none;
  transform: none;
}

.appraisal-expand-btn.is-open small {
  transform: rotate(180deg);
}

.appraisal-expanded-row > td {
  padding: 0;
  border-bottom: 2px solid #99f6e4;
  background: #f0fdfa;
}

.appraisal-expanded-card {
  padding: 12px 16px 15px 74px;
  border-left: 4px solid var(--teal);
}

.appraisal-expanded-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.appraisal-expanded-head > div {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.appraisal-expanded-head strong {
  color: #0f766e;
  font-size: 12px;
}

.appraisal-expanded-head span {
  color: var(--muted);
  font-size: 10px;
}

.appraisal-expanded-head button {
  min-height: 29px;
  padding: 4px 8px;
  font-size: 10px;
}

.appraisal-expanded-table-wrap {
  overflow-x: auto;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #fff;
}

.appraisal-expanded-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 10px;
}

.appraisal-expanded-table th {
  padding: 7px 9px;
  border-right: 1px solid #ccfbf1;
  border-bottom: 1px solid #99f6e4;
  background: #ccfbf1;
  color: #115e59;
  font-size: 9px;
  text-align: left;
  text-transform: uppercase;
}

.appraisal-expanded-table td {
  padding: 8px 9px;
  border-right: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
}

.appraisal-expanded-table tr:last-child td { border-bottom: 0; }
.appraisal-expanded-table th:first-child,
.appraisal-expanded-table td:first-child { width: 42px; text-align: center; }
.appraisal-expanded-table th:nth-child(2) { width: 160px; }
.appraisal-expanded-table th:nth-child(4) { width: 110px; }
.appraisal-expanded-table th:nth-child(5) { width: 32%; }

.appraisal-expanded-docs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.appraisal-doc-chip {
  max-width: 210px;
  min-height: 25px;
  overflow: hidden;
  padding: 3px 7px;
  border-color: #bae6fd;
  border-radius: 999px;
  background: #f0f9ff;
  color: #0369a1;
  font-size: 9px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appraisal-doc-chip:hover {
  background: #e0f2fe;
  box-shadow: none;
  transform: none;
}

.appraisal-criteria-table {
  min-width: 1080px;
}

.appraisal-criteria-table th:first-child { width: 82px; }
.appraisal-criteria-table th:nth-child(2) { width: 32%; }
.appraisal-criteria-table th:nth-child(3) { width: 145px; }
.appraisal-criteria-table th:nth-child(4) { width: 160px; }
.appraisal-criteria-table th:nth-child(5),
.appraisal-criteria-table th:nth-child(6) { width: 140px; }
.appraisal-criteria-table th:last-child { width: 42px; }

.appraisal-assignment-table {
  min-width: 900px;
}

.appraisal-assignment-table th:nth-child(1) { width: 170px; }
.appraisal-assignment-table th:nth-child(2) { width: 30%; }
.appraisal-assignment-table th:nth-child(3) { width: 145px; }
.appraisal-assignment-table th:nth-child(4) { width: 35%; }
.appraisal-assignment-table th:last-child { width: 42px; }

.appraisal-assignment-doc-cell {
  min-width: 260px;
}

.appraisal-assignment-upload {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px dashed #0d9488;
  border-radius: 6px;
  background: #f0fdfa;
  color: #0f766e;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.appraisal-assignment-upload:hover {
  background: #ccfbf1;
}

.appraisal-assignment-upload input {
  display: none;
}

.appraisal-assignment-docs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.appraisal-assignment-doc {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 230px;
  padding: 3px 4px 3px 7px;
  border: 1px solid #bae6fd;
  border-radius: 999px;
  background: #f0f9ff;
  color: #0369a1;
  font-size: 9px;
  font-weight: 700;
}

.appraisal-assignment-doc > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appraisal-assignment-doc button {
  min-height: 20px;
  padding: 0 3px;
  border-color: transparent;
  background: transparent;
  color: #0369a1;
  font-size: 10px;
}

.appraisal-assignment-doc button:last-child {
  color: var(--red);
}

.appraisal-assignment-doc button:hover {
  background: rgba(255, 255, 255, .8);
  box-shadow: none;
  transform: none;
}

@media (max-width: 700px) {
  .appraisal-expanded-card {
    padding-left: 12px;
  }

  .appraisal-expanded-head {
    align-items: flex-start;
  }

  .appraisal-expanded-head > div {
    display: grid;
    gap: 2px;
  }
}

/* ── Mobile application shell ─────────────────────────────── */
.mobile-topbar,
.mobile-nav-backdrop {
  display: none;
}

@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  header,
  body.sidebar-collapsed header {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    height: 100dvh;
    padding: 14px 12px;
    gap: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 32;
  }

  body.mobile-nav-open header {
    transform: translateX(0);
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 31;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, .55);
    box-shadow: none;
  }

  body.mobile-nav-open .mobile-nav-backdrop {
    display: block;
  }

  .mobile-topbar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 24;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 7px max(10px, env(safe-area-inset-right)) 7px max(10px, env(safe-area-inset-left));
    border-bottom: 1px solid rgba(255, 255, 255, .16);
    background: linear-gradient(110deg, #0f766e, #134e4a);
    color: #fff;
    box-shadow: 0 3px 14px rgba(15, 23, 42, .18);
  }

  .mobile-topbar-button {
    display: grid;
    place-items: center;
    width: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 9px;
    background: rgba(255, 255, 255, .1);
    color: #fff;
    box-shadow: none;
    font-size: 21px;
    line-height: 1;
  }

  .mobile-topbar-button:hover {
    background: rgba(255, 255, 255, .18);
    box-shadow: none;
    transform: none;
  }

  .mobile-topbar-title {
    display: grid;
    min-width: 0;
    line-height: 1.15;
  }

  .mobile-topbar-title strong,
  .mobile-topbar-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-topbar-title strong { font-size: 14px; }
  .mobile-topbar-title span { margin-top: 2px; color: rgba(255, 255, 255, .72); font-size: 10px; }

  .section-nav { gap: 4px; }
  .section-nav button { min-height: 44px; }
  .sidebar-user { margin-top: auto; }

  .app-main,
  body.sidebar-collapsed .app-main {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    margin-left: 0;
    padding-top: 56px;
  }

  main {
    display: block;
    min-height: calc(100dvh - 56px);
    padding: 8px;
    overflow: visible;
  }

  .dashboard-section {
    width: 100%;
    min-height: calc(100dvh - 72px);
    height: auto;
    overflow: visible;
  }

  .section-heading {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 4px 2px 2px;
  }

  .section-heading .subtle {
    flex: 1 1 100%;
    line-height: 1.35;
  }

  .panel {
    width: 100%;
    min-width: 0;
  }

  .panel-title {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 10px;
  }

  .panel-title > button,
  .section-heading > button {
    min-height: 40px;
  }

  .section-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 0;
  }

  .section-filters > label,
  .section-filters input,
  .section-filters select,
  .section-filters input[type="search"],
  .section-filters input[type="datetime-local"] {
    width: 100%;
    min-width: 0;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map,
  .issue-list,
  .report-content {
    height: auto;
    overflow: visible;
  }

  .table-wrap,
  .appraisal-master-wrap,
  .appraisal-criteria-table-wrap,
  .appraisal-assignment-table-wrap,
  .appraisal-expanded-table-wrap {
    height: auto;
    max-width: 100%;
    overflow: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  #devList table { min-width: 900px; }
  #capaList table { min-width: 720px; }
  #raList table { min-width: 760px; }
  #userList table,
  #activityList table { min-width: 720px; }

  #deviation > .panel,
  #capa > .panel,
  #danh-gia-rui-ro > .panel,
  #bao-cao > .panel,
  #ipc-kpi > .panel,
  #chat-luong > .panel,
  #bao-cao-loi-web > .panel,
  #theo-doi-sx > .panel,
  .appraisal-panel {
    display: block;
    overflow: visible;
  }

  .ipc-kpi-score-guide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 10px;
  }

  .ipc-kpi-month-filter { align-items: flex-start; flex-direction: column; padding: 8px 10px; }
  .ipc-kpi-month-blocks { width: 100%; }
  .ipc-kpi-summary { grid-template-columns: 1fr; padding: 4px 10px 10px; }
  .ipc-kpi-table-wrap { max-width: 100%; overflow: auto; overscroll-behavior-inline: contain; }

  #bao-cao-loi-web { gap: 8px; }
  .web-issues-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .web-issues-toolbar label,
  .web-issues-toolbar input,
  .web-issues-toolbar select { width: 100%; min-width: 0; }
  .web-issues-toolbar .web-issues-search-label { grid-column: 1 / -1; }
  .web-issues-stats { display: flex; overflow-x: auto; padding-bottom: 2px; }
  .web-issues-stat { flex: 0 0 135px; }
  .web-issues-table-wrap { max-width: 100%; overflow: auto; overscroll-behavior-inline: contain; }

  #devListView,
  #capaListView,
  #raListView,
  #devFormView,
  #capaFormView,
  #raFormView {
    overflow: visible;
  }

  .dev-form-body {
    flex: none;
    overflow: visible;
    padding: 12px;
  }

  .dev-grid,
  .dev-grid.two {
    grid-template-columns: 1fr;
  }

  .dev-field input,
  .dev-field select,
  .dev-field textarea,
  .record-filter-control {
    min-height: 42px;
    font-size: 16px;
  }

  .dev-form-actions {
    position: sticky;
    bottom: 0;
    z-index: 6;
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
    box-shadow: 0 -5px 18px rgba(15, 23, 42, .08);
  }

  .dev-form-actions > button {
    flex: 1 1 138px;
    min-height: 42px;
  }

  .record-comments-wrap { padding: 10px; }
  .comment-input-row { align-items: stretch; }
  .comment-input { min-height: 42px; }
  .btn-comment-send { min-height: 42px; }

  .record-pager {
    position: sticky;
    left: 0;
    justify-content: center;
    flex-wrap: wrap;
  }

  .record-pager button,
  .record-pager select { min-height: 40px; }

  .filter-summary-row,
  .date-range-filter,
  .date-custom-group {
    width: 100%;
  }

  .date-range-filter {
    display: grid;
    gap: 8px;
    padding: 8px 10px 12px;
  }

  .date-preset-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .date-preset-btn { min-height: 38px; padding-inline: 7px; }
  .date-custom-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .date-custom-group label { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .date-custom-group input[type="date"] { width: 100%; min-width: 0; min-height: 40px; }
  .report-preset-note { white-space: normal; }

  .report-banner { align-items: flex-start; padding: 12px; }
  .report-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .report-tab-btn { flex: 0 0 auto; min-height: 38px; }
  .report-donut-row { gap: 16px; }
  .donut-wrap { min-width: 0; }

  .timeline { height: auto; overflow: visible; padding-inline: 10px; }
  .timeline-item { grid-template-columns: 1fr; gap: 4px; }
  .issue-top { flex-wrap: wrap; }

  .mytask-row {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 10px 8px;
  }

  .mytask-title {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .mytask-approve { min-height: 38px; }

  .user-form-panel {
    width: 100%;
    max-width: none;
    padding: 16px;
  }

  .user-form-grid { grid-template-columns: 1fr; }
  .user-form-grid > label { grid-column: auto !important; }
  .user-form-actions button { flex: 1; min-height: 42px; }

  #activity > .section-heading + div {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px !important;
    padding: 8px 0 !important;
  }

  #actFilterUser,
  #actFilterFrom,
  #actFilterTo,
  #actFilterAction,
  #actFilterBtn {
    width: 100% !important;
    min-width: 0;
  }

  .gantt-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .gantt-filter-item,
  .gantt-filters input,
  .gantt-filters select,
  .gantt-filters input[type="date"],
  .gantt-filters input[type="text"] {
    width: 100%;
    min-width: 0;
  }

  .gantt-container { min-height: 420px; }
  .gantt-legend { gap: 8px 12px; }

  .appraisal-form-section-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .appraisal-form-actions {
    flex-wrap: wrap;
  }

  .appraisal-form-actions button { min-height: 42px; }

  .appraisal-toast {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }

  .chat-toggle {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 46px;
    height: 46px;
  }

  .chat-panel {
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    max-height: calc(100dvh - 72px);
  }

  .login-card { padding: 28px 24px; }

  body.show-login > .mobile-topbar,
  body.show-login > .mobile-nav-backdrop {
    display: none !important;
  }
}

@media (max-width: 640px) {
  main { padding: 6px; }
  .dashboard-section { gap: 8px; }
  .section-heading h2 { font-size: 16px; }
  .section-heading .subtle { font-size: 11px; }
  .panel { border-radius: 9px; }
  .panel-title { font-size: 14px; }

  .ipc-kpi-score-guide { grid-template-columns: 1fr; }

  .section-filters,
  .gantt-filters,
  #activity > .section-heading + div {
    grid-template-columns: 1fr;
  }

  .record-filter-toolbar,
  .record-filter-toolbar-compact {
    padding: 10px;
    gap: 8px;
  }

  .stats,
  .appraisal-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .stat,
  .appraisal-stat-card { padding: 9px; }
  .stat-value,
  .appraisal-stat-value { font-size: 18px; }

  .report-banner { display: grid; gap: 8px; }
  .donut-wrap { display: grid; justify-items: center; }
  .donut-legend { width: 100%; }
  .aging-chart { min-width: 0; }

  .appraisal-toolbar { grid-template-columns: 1fr; }
  .appraisal-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .appraisal-modal-head { padding: 12px; }
  #appraisalForm { padding: 12px; }
  .appraisal-form-actions { margin: 16px -12px -12px; padding: 10px 12px; }

  #changePwModal .modal-card { padding: 22px 18px; }
  .modal-actions button { flex: 1; }
}

@media (max-width: 380px) {
  .mobile-topbar { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 7px; }
  .mobile-topbar-button { width: 40px; min-height: 40px; }
  .mobile-topbar-title strong { font-size: 13px; }

  .record-filter-toolbar,
  .record-filter-toolbar-compact {
    grid-template-columns: 1fr;
  }

  .record-filter-search,
  .record-filter-period,
  .record-filter-toolbar-compact .record-filter-period {
    grid-column: auto;
  }

  .record-filter-dates,
  .date-custom-group {
    grid-template-columns: 1fr;
  }

  .stats,
  .appraisal-stats { grid-template-columns: 1fr; }
  .date-preset-group { grid-template-columns: 1fr; }
  .comment-input-row { display: grid; }
  .btn-comment-send { width: 100%; }
}
