:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-strong: #eef3ef;
  --ink: #1d2420;
  --muted: #637069;
  --line: #dbe3de;
  --accent: #16756b;
  --accent-dark: #0f554d;
  --warning: #9b5a00;
  --danger: #b3261e;
  --shadow: 0 18px 50px rgba(30, 45, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: #b8c7bf;
  background: var(--surface-strong);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.button-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-btn:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #10231f;
  color: #fff;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-heading h2,
.section-heading p,
.panel h2 {
  margin: 0;
}

.brand h1 {
  font-size: 24px;
}

.brand p,
.section-heading p,
.topbar p,
.panel dd {
  color: var(--muted);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.payroll-settings,
.fx-panel,
.controls,
.month-panel,
.audit-panel,
.formulas-panel {
  padding: 16px;
}

.payroll-settings,
.fx-panel {
  display: grid;
  gap: 12px;
}

.payroll-settings h2,
.fx-panel h2,
.month-panel h2,
.audit-panel h2,
.formulas-panel h2 {
  font-size: 15px;
}

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

.fx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(22, 117, 107, 0.18);
  outline-offset: 1px;
  border-color: var(--accent);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.controls .primary-btn {
  grid-column: 1 / -1;
}

.hidden-file {
  display: none;
}

.validation-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.validation-list li {
  padding: 10px;
  border-radius: 6px;
  background: #fff7e8;
  color: var(--warning);
}

.validation-list li.ok {
  background: #eaf6ef;
  color: var(--accent-dark);
}

.month-details {
  display: grid;
  gap: 9px;
  margin: 12px 0;
}

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

.month-details div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.month-details dt,
.month-details dd {
  margin: 0;
  font-size: 13px;
}

.month-details dt {
  color: var(--muted);
  font-weight: 700;
}

.month-details dd {
  color: var(--ink);
  font-weight: 800;
  text-align: right;
}

.save-status {
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: #eaf6ef;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.save-status.unsaved {
  background: #fff7e8;
  color: var(--warning);
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.topbar-right {
  display: grid;
  justify-items: end;
  gap: 12px;
}

.account-menu {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.account-menu div {
  display: grid;
  text-align: right;
}

.account-menu span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.account-menu a {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 34px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  min-width: min(100%, 460px);
}

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

.summary-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-grid strong {
  font-size: 20px;
}

.table-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading.compact {
  padding: 16px;
}

.section-heading h2 {
  font-size: 18px;
}

.section-heading p {
  margin-top: 4px;
  font-size: 13px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(160px, 0.8fr) minmax(130px, 0.6fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.filter-bar button {
  min-width: 108px;
}

.employee-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.view-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-width: 190px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.view-switch button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.view-switch button.active {
  background: var(--accent);
  color: #fff;
}

.save-month-btn {
  min-width: 116px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: min(64vh, 680px);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8faf8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

.sort-btn:hover {
  background: transparent;
  color: var(--accent-dark);
}

.sort-btn::after {
  content: "";
  color: var(--accent);
}

.sort-btn.active[data-direction="asc"]::after {
  content: "up";
}

.sort-btn.active[data-direction="desc"]::after {
  content: "down";
}

td input {
  min-width: 88px;
}

td:first-child input {
  min-width: 115px;
}

td:nth-child(2) input,
td:nth-child(3) input {
  min-width: 150px;
}

td select {
  min-width: 92px;
}

td:nth-child(4) select {
  min-width: 140px;
}

tbody tr {
  cursor: pointer;
}

tbody tr.selected {
  background: #edf7f4;
}

tbody tr.has-warning {
  box-shadow: inset 4px 0 0 var(--warning);
}

.archived-row {
  color: var(--muted);
}

.empty-row td {
  height: 86px;
  color: var(--muted);
  text-align: center;
}

.icon-btn {
  min-width: 74px;
  min-height: 36px;
  border-radius: 8px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.archived-row .icon-btn {
  color: var(--accent-dark);
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 16px;
  margin-top: 16px;
}

.payslip {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.empty-state {
  min-height: 180px;
  place-items: center;
  color: var(--muted);
}

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

.payslip-header h3,
.payslip-header p {
  margin: 0;
}

.archive-note {
  color: var(--warning);
  font-weight: 700;
}

.payslip-lines {
  display: grid;
  gap: 8px;
}

.payslip-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.payslip-line.total {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 20px;
  font-weight: 800;
}

.formulas-panel dl {
  display: grid;
  gap: 12px;
  margin: 14px 0 0;
}

.formulas-panel div {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.formulas-panel div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.formulas-panel dt {
  font-weight: 800;
}

.formulas-panel dd {
  margin: 3px 0 0;
  font-size: 13px;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  display: grid;
  width: min(880px, 100%);
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 40px;
  background: #10231f;
  color: #fff;
}

.auth-brand h1,
.auth-brand p,
.auth-form h2,
.auth-form p {
  margin: 0;
}

.auth-brand p {
  margin-top: 4px;
  color: #c8d7d1;
}

.auth-form {
  display: grid;
  gap: 18px;
  padding: 40px;
}

.auth-form > div > p:last-child {
  margin-top: 5px;
  color: var(--muted);
}

.auth-form label,
.admin-create-form label,
.user-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.auth-form input,
.admin-create-form input,
.admin-create-form select,
.user-row input,
.user-row select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.form-message {
  margin: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.form-message.error {
  border-color: #edc2be;
  background: #fff4f3;
  color: var(--danger);
}

.form-message.success {
  border-color: #bcded1;
  background: #effaf5;
  color: var(--accent-dark);
}

.admin-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 60px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.admin-header h1,
.admin-header p,
.admin-create h2,
.admin-users h2 {
  margin: 0;
}

.admin-header > div > p:last-child {
  margin-top: 5px;
  color: var(--muted);
}

.admin-create {
  margin-top: 18px;
}

.admin-create-form {
  display: grid;
  grid-template-columns: 1fr 1fr 150px 1fr auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.admin-users {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) 1fr 130px 1fr 80px auto;
  gap: 12px;
  align-items: end;
}

.user-identity {
  display: grid;
  align-self: center;
}

.user-identity span {
  color: var(--muted);
  font-size: 11px;
}

.check-label {
  display: flex !important;
  min-height: 42px;
  align-items: center;
  gap: 8px !important;
}

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

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-right {
    justify-items: stretch;
  }

  .account-menu {
    justify-content: flex-start;
  }

  .account-menu div {
    margin-right: auto;
    text-align: left;
  }

  .admin-create-form,
  .user-row {
    grid-template-columns: 1fr 1fr;
  }

  .section-heading {
    display: grid;
  }

  .employee-actions,
  .view-switch {
    width: 100%;
  }

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

  .employee-actions .view-switch {
    flex: 1 1 190px;
  }

  .save-month-btn {
    flex: 1 1 116px;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar,
  .workspace {
    padding: 16px;
  }

  .topbar h2 {
    font-size: 28px;
  }

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

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

  .auth-page {
    padding: 12px;
  }

  .auth-shell {
    grid-template-columns: 1fr;
  }

  .auth-brand,
  .auth-form {
    padding: 24px;
  }

  .admin-header,
  .account-menu {
    align-items: flex-start;
  }

  .admin-header {
    display: grid;
  }

  .admin-create-form,
  .user-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .table-section,
  .formulas-panel {
    display: none;
  }

  .app-shell,
  .workspace,
  .details-grid {
    display: block;
    padding: 0;
  }

  .payslip-panel {
    border: 0;
    box-shadow: none;
  }
}
