:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2a6fd4;
  --danger: #f87171;
  --radius: 10px;
  --sidebar-w: 240px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse 80% 60% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.login-sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-form label {
  display: block;
  margin-bottom: 1rem;
}

.login-form label span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.login-form input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 139, 253, 0.25);
}

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-block {
  width: 100%;
  margin-top: 0.25rem;
}

/* App shell */
.app-body {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--surface2);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar-brand {
  padding: 0 1.1rem 1.25rem;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--surface2);
  margin-bottom: 0.75rem;
}

.sidebar-brand span {
  color: var(--accent);
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.5rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.sidebar-link:hover {
  background: var(--surface2);
  color: var(--text);
}

.sidebar-link.is-active {
  background: rgba(61, 139, 253, 0.15);
  color: var(--text);
}

.sidebar-icon {
  width: 1.5rem;
  text-align: center;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 1rem 1.1rem 0;
  border-top: 1px solid var(--surface2);
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.sidebar-user {
  display: block;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.sidebar-logout {
  color: var(--accent);
  text-decoration: none;
}

.sidebar-logout:hover {
  text-decoration: underline;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--surface2);
  background: rgba(26, 35, 50, 0.6);
  backdrop-filter: blur(8px);
}

.topbar-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.content {
  padding: 1.5rem;
  flex: 1;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: 52rem;
}

.lead {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 1rem;
}

.dash-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text);
}

.dash-list li {
  margin-bottom: 0.5rem;
}

.placeholder-panel p {
  margin: 0;
  color: var(--muted);
}

.spec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.spec-btn {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.spec-btn:hover {
  filter: brightness(1.08);
}

.spec-btn-secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.spec-panel code {
  font-size: 0.85em;
  color: var(--muted);
}

/* Flash */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.flash-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.flash-warning {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fde68a;
}

.flash-info {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
}

/* Toolbar & tables */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-left: auto;
}

.filters input[type="search"],
.filters select {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
}

.inline-import {
  display: inline-flex;
  align-items: center;
}

.file-label span {
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 0.35rem;
}

.file-label input[type="file"] {
  max-width: 200px;
  font-size: 0.8rem;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--surface2);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface2);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-ghost:hover {
  color: var(--text);
}

.table-panel {
  max-width: none;
}

.form-panel {
  max-width: 56rem;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem 1rem;
}

.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.grid-form label span:first-child {
  font-weight: 500;
}

.grid-form input,
.grid-form select {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}

.input-readonly {
  opacity: 0.75;
}

.check-row {
  grid-column: 1 / -1;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.id-card-uploads {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.id-card-uploads .label-text {
  font-weight: 500;
}

.id-card-pair {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.id-card-side {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.id-card-side strong {
  font-size: 0.85rem;
  color: var(--text);
}

.id-card-existing {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--surface);
}

.id-card-thumb {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--surface2);
}

.id-card-uploads input[type="file"] {
  font-size: 0.82rem;
}

.check-inline {
  grid-column: auto !important;
}

.muted {
  color: var(--muted);
}

.muted-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.input-year {
  width: 5rem;
}

.sales-lead {
  margin: 0.75rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.45;
}

.sales-toolbar {
  margin-top: 1rem;
}

.sales-table-wrap {
  margin-top: 0.5rem;
}

.sales-table .sales-stt {
  vertical-align: middle;
  min-width: 2.5rem;
}

.sales-table .sales-emp-total--ditto {
  background: rgba(0, 0, 0, 0.12);
  border-left: 1px solid var(--surface2, rgba(255, 255, 255, 0.06));
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--surface2);
  text-align: left;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table .mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

.row-inactive {
  opacity: 0.55;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-on {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.badge-off {
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
}

.badge-role {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.row-actions {
  white-space: nowrap;
}

.row-actions .inline-form {
  display: inline;
}

.link-sm {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
  margin-right: 0.5rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0;
}

.link-btn.danger {
  color: var(--danger);
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem !important;
}

.panel-wide {
  max-width: none;
}

.attendance-grid-wrap {
  max-height: 70vh;
  overflow: auto;
}

.attendance-grid th,
.attendance-grid td {
  white-space: nowrap;
}

.attendance-grid .cell-input {
  width: 4rem;
  min-width: 3.2rem;
  padding: 0.25rem 0.35rem;
  font-size: 0.78rem;
  border-radius: 6px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
}

.payroll-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
  padding-bottom: 0.25rem;
}

.payroll-grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}

.payroll-grid thead th {
  background: var(--surface);
  box-shadow: inset 0 -1px 0 var(--surface2);
  white-space: normal;
  line-height: 1.3;
  font-size: 0.72rem;
  vertical-align: bottom;
}

.payroll-grid th,
.payroll-grid td {
  padding: 0.7rem 0.95rem;
  vertical-align: middle;
}

.payroll-grid tbody td {
  white-space: nowrap;
}

/* Nhóm 3 cột đầu (NV) — tách khỏi khối số */
.payroll-grid th:nth-child(1),
.payroll-grid td:nth-child(1) {
  min-width: 4.5rem;
  padding-right: 1rem;
}

.payroll-grid th:nth-child(2),
.payroll-grid td:nth-child(2) {
  min-width: 10rem;
  max-width: 16rem;
  padding-left: 0.5rem;
  padding-right: 1rem;
}

.payroll-grid th:nth-child(3),
.payroll-grid td:nth-child(3) {
  min-width: 6.5rem;
  padding-right: 1.15rem;
  border-right: 1px solid var(--surface2);
}

/* Cột tiền: khoảng đệm ngang rộng + độ rộng tối thiểu */
.payroll-grid th:nth-child(n + 4):nth-child(-n + 13),
.payroll-grid td:nth-child(n + 4):nth-child(-n + 13) {
  padding-left: 1.05rem;
  padding-right: 1.05rem;
  min-width: 7.5rem;
}

.payroll-grid th:nth-child(13),
.payroll-grid td:nth-child(13) {
  min-width: 8.25rem;
  padding-left: 1.15rem;
  padding-right: 1.15rem;
}

.payroll-grid td:nth-child(13) strong {
  font-size: 1.02em;
}

/* ĐCC + loại + TK */
.payroll-grid th:nth-child(14),
.payroll-grid td:nth-child(14) {
  min-width: 3.75rem;
  padding-left: 1rem;
}

.payroll-grid th:nth-child(15),
.payroll-grid td:nth-child(15) {
  padding-left: 0.85rem;
  padding-right: 0.85rem;
}

.payroll-grid th:nth-child(16),
.payroll-grid td:nth-child(16) {
  min-width: 8rem;
  padding-right: 1.1rem;
}

.payroll-grid tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.payroll-grid tbody td.payroll-bank-cell {
  white-space: normal;
  vertical-align: top;
  min-width: 9.5rem;
  max-width: 11rem;
}

.payroll-sepay-qr {
  margin-top: 0.45rem;
}

.payroll-sepay-qr img {
  display: block;
  border-radius: 8px;
  background: #fff;
}

.payslip-sepay {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.15);
}

.payslip-sepay-cap {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.payslip-sepay-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.payslip-sepay-row img {
  border-radius: 10px;
  background: #fff;
}

.payslip-sepay-side .payslip-muted {
  margin: 0 0 0.5rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.payroll-sepay-thumb,
.payslip-sepay-thumb {
  display: block;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  border-radius: 8px;
  line-height: 0;
}

a.payroll-sepay-thumb,
a.payslip-sepay-thumb {
  text-decoration: none;
  color: inherit;
}

.payroll-sepay-thumb:focus-visible,
.payslip-sepay-thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a.payroll-sepay-link-btn {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

a.payroll-sepay-link-btn:hover {
  color: var(--accent-dim);
}

@media print {
  .payroll-sepay-thumb,
  .payslip-sepay-thumb {
    cursor: default;
    pointer-events: none;
  }
}

.lindo-sepay-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}

.lindo-sepay-modal.is-open {
  display: flex;
}

.lindo-sepay-modal-backdrop {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.lindo-sepay-modal-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 20rem;
  padding: 1.2rem 1.35rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.lindo-sepay-modal-x {
  position: absolute;
  top: 0.5rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.lindo-sepay-modal-x:hover {
  color: var(--text);
  background: var(--surface2);
}

.lindo-sepay-modal-title {
  margin: 0 2rem 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.lindo-sepay-modal-meta {
  margin: 0 0 0.75rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface2);
}

.lindo-sepay-modal-line {
  margin: 0.2rem 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text);
}

.lindo-sepay-modal-line:first-child {
  margin-top: 0;
}

.lindo-sepay-modal-line:last-child {
  margin-bottom: 0;
}

.lindo-sepay-modal-k {
  color: var(--muted);
  margin-right: 0.35rem;
}

.lindo-sepay-modal-v {
  font-weight: 600;
  word-break: break-word;
}

.lindo-sepay-modal-img-wrap {
  display: flex;
  justify-content: center;
  padding: 0.35rem 0 0.25rem;
}

.lindo-sepay-modal-img-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  background: #fff;
}

.lindo-sepay-modal-foot {
  margin: 0.85rem 0 0;
  text-align: center;
}

.activity-log-detail {
  max-width: 36rem;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

.payslip-wrap .payslip-doc {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--surface2);
}

.payslip-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.payslip-title {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
}

.payslip-sub {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.payslip-qr {
  text-align: center;
}

.payslip-qr img {
  display: block;
  border-radius: 8px;
  background: #fff;
}

.payslip-qr-cap {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.payslip-meta {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.payslip-meta th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  width: 8rem;
  padding: 0.35rem 0.5rem 0.35rem 0;
  vertical-align: top;
}

.payslip-meta td {
  padding: 0.35rem 0;
}

.payslip-lines {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.payslip-lines th,
.payslip-lines td {
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--surface2);
}

.payslip-lines .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.payslip-lines thead th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.payslip-total td {
  border-bottom: none;
  padding-top: 0.65rem;
  font-size: 1.05rem;
}

.payslip-bank {
  margin-top: 0.5rem;
}

@media print {
  .sidebar,
  .topbar,
  .no-print {
    display: none !important;
  }

  .app-body {
    display: block;
  }

  .app-main {
    display: block;
  }

  .content {
    padding: 0;
  }

  .payslip-wrap {
    border: none;
    box-shadow: none;
  }

  .payslip-wrap .payslip-doc {
    border: none;
    background: #fff;
    color: #111;
  }

  .payslip-wrap .payslip-doc .payslip-sub,
  .payslip-wrap .payslip-doc .payslip-meta th,
  .payslip-wrap .payslip-doc .payslip-qr-cap {
    color: #444;
  }

  .payslip-wrap .payslip-doc .payslip-lines th,
  .payslip-wrap .payslip-doc .payslip-lines td {
    border-color: #ddd;
  }

  body.app-body {
    background: #fff;
  }
}

@media (max-width: 768px) {
  .app-body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.75rem;
  }

  .sidebar-brand {
    border: none;
    margin: 0;
    padding: 0 0.5rem 0 0.5rem;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
    padding: 0;
  }

  .sidebar-link {
    font-size: 0.85rem;
  }

  .sidebar-footer {
    border: none;
    margin: 0;
    padding: 0.5rem;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
