:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #657184;
  --line: #d9e0e8;
  --panel: #ffffff;
  --soft: #f5f7fa;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #b45309;
  --danger: #b42318;
  --blue: #2563eb;
  --shadow: 0 16px 40px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef2f6;
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  background: #111827;
  color: #f8fafc;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand p,
.login-panel label,
.eyebrow,
.section-head p,
.notice {
  color: var(--muted);
}

.brand p {
  margin: 4px 0 0;
  color: #a7b0bf;
  font-size: 12px;
}

.login-panel {
  display: grid;
  gap: 9px;
}

.login-panel label {
  color: #cbd5e1;
  font-size: 12px;
}

.fixed-employee-label {
  display: none;
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  font-weight: 700;
}

.employee-fixed #currentUser {
  display: none;
}

.employee-fixed .fixed-employee-label {
  display: block;
}

.admin-login-screen {
  display: none;
}

.admin-locked .app-shell {
  display: none;
}

.admin-locked .admin-login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.admin-login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.admin-login-card .brand-mark {
  margin-bottom: 4px;
}

.admin-login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.admin-login-card label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

select,
input,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}

textarea {
  min-height: 130px;
  resize: vertical;
}

.role-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.segmented {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cbd5e1;
}

.segmented.active {
  background: white;
  color: #111827;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: #dbe4ef;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
}

.month-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.month-control input {
  width: 150px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.view {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h3 {
  margin: 0;
  font-size: 20px;
}

.section-head p {
  margin: 5px 0 0;
  font-size: 13px;
}

.sticky-save-bar {
  position: sticky;
  right: 0;
  bottom: 12px;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  pointer-events: none;
}

.sticky-save-bar .primary {
  min-width: 140px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.24);
  pointer-events: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
}

.detail-field-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.span-2 {
  grid-column: span 2;
}

.hidden {
  display: none !important;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  min-height: 40px;
}

.check-row label {
  display: inline-flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.master-data-field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.inline-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.url-field {
  min-width: 420px;
  font-size: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button-row select {
  width: min(220px, 100%);
}

.approval-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.approval-tools select {
  width: min(240px, 100%);
}

.primary,
.secondary,
.danger,
.small {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary {
  background: var(--accent);
  color: white;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.danger {
  background: #fff5f5;
  color: var(--danger);
  border-color: #ffd5d2;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  background: var(--soft);
  color: var(--ink);
  border-color: var(--line);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

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

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

th {
  background: var(--soft);
  color: #475569;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.approval-row {
  background: var(--employee-bg);
  box-shadow: inset 4px 0 0 var(--employee-color);
}

.employee-color-chip {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--employee-color);
  vertical-align: middle;
}

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

.status.pending {
  background: #fff7ed;
  color: var(--warn);
}

.status.approved {
  background: #ecfdf5;
  color: #047857;
}

.status.rejected {
  background: #fef2f2;
  color: var(--danger);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.payroll-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.denomination-table {
  min-width: 1080px;
}

.denomination-table th:not(:first-child),
.denomination-table td:not(:first-child) {
  text-align: right;
}

.denomination-table .total-row td {
  background: #eef8f6;
  font-weight: 800;
}

.retirement-summary {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.retirement-summary h4 {
  margin: 0;
  font-size: 16px;
}

.retirement-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}

.retirement-summary-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.retirement-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.retirement-summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.payslip-paper {
  display: grid;
  gap: 14px;
  min-height: 240px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.print-only {
  display: none;
}

.payslip-print-page {
  display: grid;
  gap: 14px;
  page-break-after: always;
  break-after: page;
}

.payslip-print-page:last-child {
  page-break-after: auto;
  break-after: auto;
}

.payslip-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 12px;
}

.payslip-title h3 {
  margin: 0;
  font-size: 22px;
}

.payslip-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.payslip-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.payslip-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.payslip-box h4 {
  margin: 0;
  padding: 10px 12px;
  background: var(--soft);
  border-bottom: 1px solid var(--line);
}

.payslip-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.payslip-line:last-child {
  border-bottom: 0;
}

.payslip-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 8px;
  background: #eaf7f5;
}

.payslip-total span {
  color: #0f766e;
  font-weight: 700;
}

.payslip-total strong {
  font-size: 28px;
}

.notice {
  margin: 6px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  line-height: 1.6;
}

.origin-notice {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #f3d08a;
  border-radius: 8px;
  background: #fff8e6;
  color: #7c4a03;
  line-height: 1.6;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 84px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

.admin-disabled .admin-only {
  display: none;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
  }

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

  .workspace {
    padding: 14px;
  }

  .topbar,
  .section-head,
  .payslip-title {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .summary-grid,
  .retirement-summary-grid,
  .payslip-columns {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .sticky-save-bar {
    bottom: 10px;
  }

  .sticky-save-bar .primary {
    width: min(100%, 260px);
  }

  .approval-tools,
  .approval-tools select,
  .approval-tools button {
    width: 100%;
  }

  .toast {
    right: 14px;
    bottom: 86px;
    max-width: calc(100vw - 28px);
  }

  .payslip-title p {
    text-align: left;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 5mm;
  }

  @page all-payslips {
    size: A4 landscape;
    margin: 5mm;
  }

  body {
    background: white;
  }

  .sidebar,
  .topbar,
  .section-head,
  .sticky-save-bar,
  .toast,
  .summary-grid,
  .view:not(.print-target) {
    display: none !important;
  }

  .app-shell,
  .workspace {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .view {
    display: block !important;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .payslip-paper {
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  body.print-section-mode .view:not(.print-target) {
    display: block !important;
  }

  body.print-section-mode .view > :not(.print-target) {
    display: none !important;
  }

  body.print-section-mode .print-target {
    display: block !important;
  }

  body.print-section-mode #allPayslipsPrintArea.print-target {
    display: block !important;
  }

  body.print-section-mode .payslip-print-page {
    display: block !important;
    page-break-after: always;
    break-after: page;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.print-section-mode .payslip-print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  body.all-payslips-sheet-mode #allPayslipsPrintArea.print-target {
    display: block !important;
    page: all-payslips;
  }

  body.all-payslips-sheet-mode .payslip-print-sheet {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    min-height: 200mm;
    page-break-after: always;
    break-after: page;
  }

  body.all-payslips-sheet-mode .payslip-print-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  body.all-payslips-sheet-mode .payslip-print-page {
    position: relative;
    display: block !important;
    min-height: 200mm;
    padding: 1.5mm;
    border-right: 1px dashed #6b7280;
    page-break-after: auto;
    break-after: auto;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.all-payslips-sheet-mode .payslip-print-page:nth-child(3n) {
    border-right: 0;
  }

  body.all-payslips-sheet-mode .payslip-print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  body.all-payslips-sheet-mode .payslip-paper {
    display: grid;
    gap: 0.7mm;
    font-size: 6.4pt;
  }

  body.all-payslips-sheet-mode .payslip-title {
    gap: 1mm;
    padding-bottom: 0.7mm;
    border-bottom-width: 1px;
  }

  body.all-payslips-sheet-mode .payslip-title h3 {
    font-size: 9.5pt;
    white-space: nowrap;
  }

  body.all-payslips-sheet-mode .payslip-title p {
    font-size: 5.8pt;
  }

  body.all-payslips-sheet-mode .payslip-line span {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  body.all-payslips-sheet-mode .payslip-line strong {
    white-space: nowrap;
  }

  body.all-payslips-sheet-mode .payslip-columns {
    grid-template-columns: 1fr 1fr;
    gap: 1mm;
  }

  body.all-payslips-sheet-mode .payslip-box {
    border-radius: 0;
  }

  body.all-payslips-sheet-mode .payslip-box h4 {
    padding: 0.45mm 0.8mm;
    font-size: 6.6pt;
  }

  body.all-payslips-sheet-mode .payslip-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.8mm;
    padding: 0.35mm 0.8mm;
    line-height: 1.02;
  }

  body.all-payslips-sheet-mode .payslip-line small {
    display: block;
    margin-top: 0.1mm;
    font-size: 5pt;
  }

  body.all-payslips-sheet-mode .payslip-total {
    padding: 1mm;
    border-radius: 0;
  }

  body.all-payslips-sheet-mode .payslip-total strong {
    font-size: 10.5pt;
  }

  body.print-section-mode .payroll-panel,
  body.print-section-mode .payslip-paper {
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  body.print-section-mode .table-wrap {
    overflow: visible;
    border: 0;
  }

  body.print-section-mode table {
    min-width: 0;
  }
}
