:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --ink: #172026;
  --muted: #6a7680;
  --line: #dce3e8;
  --teal: #d71920;
  --teal-dark: #a90f17;
  --amber: #d99019;
  --red: #c94c3b;
  --green: #2d9b63;
  --blue: #3b6fb6;
  --shadow: 0 18px 40px rgba(25, 35, 45, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  background: #11191e;
  color: #f7fbfc;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: block;
  object-fit: contain;
}

.sidebar-logo {
  width: 78px;
  height: 30px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.user strong,
.sidebar-footer strong {
  display: block;
  font-size: 14px;
}

.brand span,
.user span,
.sidebar-footer span,
.mini-label {
  display: block;
  color: #8fa0a9;
  font-size: 12px;
  line-height: 1.4;
}

.nav {
  display: grid;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.nav::-webkit-scrollbar {
  width: 6px;
}

.nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 10px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #b9c7ce;
  text-align: left;
  font-size: 14px;
}

.nav-button:hover,
.nav-button.active {
  background: #203038;
  color: #ffffff;
}

.nav-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  color: #9fd7d2;
  font-size: 12px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.main {
  position: relative;
  min-width: 0;
  padding: 18px 22px 32px;
}

.topbar,
.workspace-header,
.panel,
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.topbar {
  display: grid;
  grid-template-columns: 260px minmax(220px, 1fr) 40px minmax(330px, auto);
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 12px;
}

.project-switcher,
.search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.project-switcher span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.project-switcher select,
.search input,
.dialog-card input,
.dialog-card select,
.dialog-card textarea,
.panel select {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}

.search .icon {
  color: var(--muted);
}

.icon-button {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
}

.notification-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.notification-panel {
  position: absolute;
  z-index: 20;
  top: 88px;
  right: 22px;
  width: min(430px, calc(100vw - 44px));
  max-height: min(620px, calc(100vh - 110px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(20, 31, 36, 0.2);
}

.notification-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

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

.notification-heading span {
  color: var(--muted);
  font-size: 12px;
}

.notification-list {
  max-height: 510px;
  overflow-y: auto;
}

.notification-item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.notification-item.unread {
  background: #f3f8f7;
}

.notification-dot {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--blue);
}

.notification-item.critical .notification-dot {
  background: var(--red);
}

.notification-item.warning .notification-dot {
  background: var(--amber);
}

.notification-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.notification-copy strong,
.notification-copy span {
  overflow-wrap: anywhere;
}

.notification-copy span,
.notification-copy time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.notification-empty {
  padding: 28px 16px;
  text-align: center;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #dfe9e8;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.18;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.header-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--teal-dark);
}

.compact {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.kpi-card {
  padding: 15px;
}

.kpi-top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  margin-top: 10px;
  font-size: 26px;
  font-weight: 800;
}

.kpi-note {
  margin-top: 6px;
  font-size: 12px;
}

.module-tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

.tab-button.active {
  border-color: rgba(15, 143, 136, 0.35);
  background: #e7f4f3;
  color: var(--teal-dark);
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(330px, 1fr) minmax(280px, 0.85fr);
  gap: 14px;
  margin-top: 14px;
}

.bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.8fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  padding: 16px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.user-admin-panel {
  margin-top: 14px;
}

.project-admin-panel,
.project-members-box,
.audit-box {
  margin-top: 14px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-heading select {
  max-width: 150px;
  min-height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.count-pill,
.status,
.priority {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.count-pill {
  background: #eef3f5;
  color: var(--muted);
}

.schedule-list,
.action-list,
.rfi-list,
.safety-stack {
  display: grid;
  gap: 10px;
}

.schedule-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.schedule-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.schedule-meta,
.action-meta,
.rfi-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.schedule-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 130px;
}

.danger-link {
  color: var(--red);
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9ed;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #4bb8a9);
}

.action-card,
.rfi-card,
.safety-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.action-card h3,
.rfi-card h3,
.safety-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.rfi-response {
  padding: 10px;
  border-left: 3px solid var(--teal);
  background: #f3faf8;
  color: var(--ink);
}

.rfi-response p {
  margin: 4px 0 0;
  color: var(--muted);
}

.rfi-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.priority.high,
.status.overdue {
  background: #fae8e5;
  color: var(--red);
}

.priority.medium,
.status.pending {
  background: #fff3dc;
  color: #9b640f;
}

.priority.low,
.status.approved {
  background: #e7f4ec;
  color: var(--green);
}

.status.open {
  background: #e6eef9;
  color: var(--blue);
}

.risk-matrix {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.risk-cell {
  min-height: 54px;
  padding: 8px;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
}

.risk-cell strong {
  display: block;
  font-size: 20px;
}

.risk-low {
  background: var(--green);
}

.risk-med {
  background: var(--amber);
}

.risk-high {
  background: var(--red);
}

.table-wrap {
  overflow-x: auto;
}

.table-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dialog {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(12, 20, 24, 0.48);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
}

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

.dialog-card input,
.dialog-card select,
.dialog-card textarea {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.dialog-card textarea {
  padding: 10px;
  resize: vertical;
}

.checkbox-label {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox-label input {
  width: auto;
}

.dialog-actions {
  justify-content: flex-end;
}

#reportDialog {
  width: min(600px, calc(100vw - 28px));
}

.report-dialog-card {
  min-width: 0;
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.report-summary-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 13px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.report-summary-item:nth-child(3n) {
  border-right: 0;
}

.report-summary-item span {
  color: var(--muted);
  font-size: 11px;
}

.report-summary-item strong {
  font-size: 21px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(16px);
  opacity: 0;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 6px;
  background: #11191e;
  color: #fff;
  font-size: 13px;
  transition: 180ms ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .brand div:last-child,
  .nav-label,
  .sidebar-footer {
    display: none;
  }

  .sidebar {
    padding: 18px 14px;
  }

  .nav-button {
    justify-content: center;
  }

  .topbar {
    grid-template-columns: minmax(210px, 260px) minmax(180px, 1fr) 40px;
  }

  .user {
    display: none;
  }

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

  .dashboard-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav {
    display: flex;
  }

  .brand {
    flex: 0 0 auto;
  }

  .main {
    padding: 12px;
  }

  .notification-panel {
    position: fixed;
    top: 82px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100vh - 100px);
  }

  .topbar,
  .workspace-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .header-actions {
    flex-wrap: wrap;
  }

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

  h1 {
    font-size: 23px;
  }

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

  .report-summary-item:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .report-summary-item:nth-child(2n) {
    border-right: 0;
  }
}

@media (max-width: 470px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Cost & Tendering (Chi phí) */
#costContent .num { text-align: right; white-space: nowrap; }
#costContent table tfoot td { border-top: 2px solid var(--border, #d7dce5); font-weight: 600; }
#costContent .positive { color: #1c7c43; }
#costContent .negative { color: #c0392b; }
#costContent .dashboard-grid { margin-bottom: 16px; }
.dialog-card .form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.dialog-card .form-row label { margin: 0; }

/* Cost dynamic line rows */
.lines-block { margin: 8px 0 4px; }
.lines-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.line-rows .line-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.line-row input, .line-row select { padding: 8px; min-width: 0; }
.line-row .line-remove { flex: 0 0 auto; width: 34px; height: 34px; line-height: 1; }
.inline-list { margin: 0; padding-left: 16px; font-size: 13px; }
.inline-list li { margin: 2px 0; }

/* HR manpower dashboard */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi-row .kpi-card { display: flex; flex-direction: column; gap: 6px; }
.kpi-row .kpi-label { color: var(--muted); font-size: 12px; }
.kpi-row .kpi-num { font-size: 26px; font-weight: 800; }
.histogram { display: flex; align-items: flex-end; gap: 6px; min-height: 160px; padding: 10px 4px 0; overflow-x: auto; }
.hist-col { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 0 0 auto; min-width: 34px; }
.hist-bar { display: flex; flex-direction: column-reverse; width: 26px; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--surface-2); }
.hist-seg.seg-ts { background: var(--blue); }
.hist-seg.seg-dr { background: var(--amber); }
.hist-val { font-size: 12px; font-weight: 700; }
.hist-date { font-size: 11px; color: var(--muted); white-space: nowrap; }
.legend { display: inline-block; padding: 0 6px; border-radius: 4px; color: #fff; font-size: 11px; }
.legend.seg-ts { background: var(--blue); }
.legend.seg-dr { background: var(--amber); }

/* Gantt / CPM schedule */
.gantt-wrap { overflow-x: auto; }
.gantt-table th.g-track-head, .gantt-table td.g-track { min-width: 360px; width: 42%; }
.g-track { position: relative; height: 22px; }
.g-bar { position: absolute; top: 4px; height: 14px; background: var(--blue); border-radius: 3px; min-width: 2px; overflow: hidden; }
.g-bar.g-critical { background: var(--teal); }
.g-summary { position: absolute; top: 8px; height: 6px; background: var(--ink); border-radius: 2px; min-width: 2px; }
.g-milestone { position: absolute; top: 3px; width: 13px; height: 13px; background: var(--amber); transform: translateX(-6px) rotate(45deg); border-radius: 2px; }
.g-prog { position: absolute; left: 0; top: 0; height: 100%; background: rgba(0, 0, 0, 0.28); }
.g-row-crit td { background: rgba(215, 25, 32, 0.045); }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.checkbox-label input { width: auto; }

/* S-curve */
.scurve { width: 100%; height: auto; max-height: 280px; }
.sc-grid { stroke: var(--line); stroke-width: 1; }
.sc-axis { fill: var(--muted); font-size: 10px; }
.sc-planned { stroke: var(--blue); stroke-width: 2; stroke-dasharray: 5 4; }
.sc-actual { stroke: var(--teal); stroke-width: 2.5; }
.sc-actual-dot { fill: var(--teal); }
.legend.sc-leg-plan { background: var(--blue); }
.legend.sc-leg-act { background: var(--teal); }
.evm-pv { stroke: var(--blue); stroke-width: 2; stroke-dasharray: 5 4; }
.evm-ev { stroke: var(--green); stroke-width: 2.5; }
.evm-ac { stroke: var(--teal); stroke-width: 2.5; }
.evm-pv-dot { fill: var(--blue); }
.evm-ev-dot { fill: var(--green); }
.evm-ac-dot { fill: var(--teal); }
.legend.evm-leg-pv { background: var(--blue); }
.legend.evm-leg-ev { background: var(--green); }
.legend.evm-leg-ac { background: var(--teal); }
