:root {
  --paper: #fff9fc;
  --surface: #ffffff;
  --surface-soft: #fff1f7;
  --rose: #ec6f9f;
  --rose-strong: #c93c76;
  --berry: #7b2457;
  --plum: #2d1836;
  --sage: #4d8274;
  --mint: #e5f5ee;
  --gold: #b8832f;
  --line: #ead7e1;
  --muted: #806f7d;
  --danger: #b4233c;
  --shadow: 0 18px 48px rgba(74, 24, 58, 0.13);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(236, 111, 159, 0.14), rgba(77, 130, 116, 0.1)),
    var(--paper);
  color: var(--plum);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

.login-body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(123, 36, 87, 0.82), rgba(236, 111, 159, 0.64)),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.28), transparent 34%),
    var(--berry);
}

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

.login-hero {
  width: min(100%, 520px);
  color: #ffffff;
}

.login-hero h1 {
  margin: 8px 0 24px;
  font-size: clamp(44px, 8vw, 76px);
  line-height: 0.95;
  letter-spacing: 0;
}

.login-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--plum);
  display: grid;
  gap: 14px;
  padding: 22px;
}

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

.sidebar {
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--rose), var(--berry));
  border-radius: 8px;
  color: #ffffff;
  display: inline-flex;
  font-size: 24px;
  font-weight: 800;
  height: 48px;
  justify-content: center;
  width: 48px;
  flex: 0 0 48px;
}

.brand strong,
.brand small {
  display: block;
  overflow-wrap: anywhere;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

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

.nav-list a,
.logout-link {
  border-radius: var(--radius);
  color: var(--berry);
  font-weight: 700;
  padding: 11px 12px;
}

.nav-list a:hover,
.logout-link:hover {
  background: var(--surface-soft);
}

.nav-list a.active {
  background: var(--plum);
  color: #ffffff;
}

.logout-link {
  margin-top: auto;
}

.main-content {
  display: grid;
  gap: 22px;
  padding: 28px;
  min-width: 0;
}

.topbar,
.section-head,
.section-actions,
.row-actions {
  align-items: center;
  display: flex;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(30px, 4vw, 44px);
}

.period-range {
  color: var(--muted);
  display: block;
  font-weight: 800;
  margin-top: 4px;
}

.section-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h2 {
  font-size: 22px;
}

.section-actions,
.topbar-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.eyebrow {
  color: var(--rose-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.panel,
.metric {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(74, 24, 58, 0.08);
}

.panel {
  padding: 20px;
  min-width: 0;
}

.accent-panel {
  background: linear-gradient(135deg, rgba(255, 241, 247, 0.98), rgba(229, 245, 238, 0.96));
}

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

.metric {
  display: grid;
  gap: 6px;
  min-height: 116px;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  color: var(--berry);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.metric-primary {
  background: linear-gradient(135deg, var(--berry), var(--rose-strong));
  color: #ffffff;
}

.metric-primary span,
.metric-primary strong {
  color: #ffffff;
}

.content-grid {
  display: grid;
  gap: 18px;
}

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

.employee-layout,
.loans-layout {
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

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

.mini-stats span {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 14px;
}

.mini-stats strong {
  color: var(--berry);
  display: block;
  font-size: 24px;
}

label {
  color: var(--berry);
  display: grid;
  font-size: 13px;
  font-weight: 800;
  gap: 7px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid #d9bfcc;
  border-radius: var(--radius);
  color: var(--plum);
  min-height: 42px;
  outline: none;
  padding: 9px 11px;
  width: 100%;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--rose);
  box-shadow: 0 0 0 3px rgba(236, 111, 159, 0.18);
}

.stacked-form,
.inline-form {
  display: grid;
  gap: 14px;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-actions {
  margin-top: 18px;
}

.button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  text-align: center;
  white-space: nowrap;
}

.button-primary {
  background: var(--berry);
  color: #ffffff;
}

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

.button-ghost {
  background: #ffffff;
  border-color: var(--line);
  color: var(--berry);
}

.button-danger {
  background: #fff0f2;
  border-color: #f4c5ce;
  color: var(--danger);
}

.button-small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}

.flash {
  border-radius: var(--radius);
  font-weight: 800;
  margin: 0;
  padding: 12px 14px;
}

.flash-success {
  background: var(--mint);
  color: #276253;
}

.flash-error {
  background: #fff0f2;
  color: var(--danger);
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  width: 100%;
}

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

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

th {
  color: var(--berry);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

td strong,
td small {
  display: block;
}

td small,
.muted {
  color: var(--muted);
  font-size: 12px;
}

tfoot th {
  background: var(--surface-soft);
  font-size: 13px;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
  white-space: nowrap;
}

.badge-good {
  background: var(--mint);
  color: #276253;
}

.badge-warn {
  background: #fff4d8;
  color: #8a5b11;
}

.badge-muted {
  background: #f2edf1;
  color: var(--muted);
}

.search-input {
  max-width: 240px;
}

.week-form {
  align-items: end;
  display: grid;
  grid-template-columns: 150px 190px auto;
  gap: 10px;
}

.attendance-guide {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: -4px 0 18px;
}

.attendance-guide span {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  padding: 10px 12px;
}

.attendance-guide strong {
  color: var(--berry);
  display: block;
}

.attendance-wrap table {
  min-width: 1280px;
}

.attendance-table th:not(:first-child),
.attendance-table td:not(:first-child) {
  text-align: center;
  width: 142px;
}

.attendance-table th strong,
.attendance-table th span,
.attendance-table th em {
  display: block;
}

.attendance-table th strong {
  color: var(--rose-strong);
  font-size: 16px;
}

.attendance-table th span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  margin-top: 2px;
  text-transform: none;
}

.attendance-table th em {
  color: var(--plum);
  font-size: 13px;
  font-style: normal;
  margin-top: 4px;
}

.attendance-table td:first-child {
  background: #ffffff;
  min-width: 260px;
  position: sticky;
  left: 0;
  z-index: 1;
}

.attendance-table th:first-child {
  background: #ffffff;
  position: sticky;
  left: 0;
  z-index: 2;
}

.attendance-day {
  border-left: 1px solid rgba(234, 215, 225, 0.72);
}

.attendance-day.status-worked {
  background: rgba(229, 245, 238, 0.72);
}

.attendance-day.status-missed {
  background: rgba(255, 240, 242, 0.9);
}

.attendance-day.status-rest {
  background: rgba(242, 237, 241, 0.92);
}

.attendance-day.status-pending {
  background: rgba(255, 255, 255, 0.72);
}

.attendance-table select,
.attendance-table input {
  border-color: #e0bfce;
}

.attendance-table select {
  background: #ffffff;
  font-weight: 800;
  min-height: 38px;
  padding: 6px 8px;
}

.attendance-table input {
  min-height: 34px;
  padding: 6px;
  text-align: center;
}

.extra-field {
  color: var(--muted);
  font-size: 11px;
  gap: 5px;
  margin-top: 8px;
  text-transform: uppercase;
}

.extra-field span {
  display: block;
}

.payment-form {
  display: grid;
  gap: 8px;
  min-width: 190px;
}

.payment-form input {
  min-height: 34px;
}

.loan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.letter-stage {
  background: #f7edf2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow-x: auto;
  padding: 18px;
}

.payroll-sheet {
  background: #ffffff;
  border: 1px solid #ead7e1;
  border-radius: 6px;
  box-shadow: 0 14px 32px rgba(74, 24, 58, 0.12);
  color: var(--plum);
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 1056px;
  padding: 42px;
  width: 816px;
}

.sheet-header,
.sheet-kpis,
.sheet-footer {
  display: grid;
  gap: 12px;
}

.sheet-header {
  align-items: start;
  border-bottom: 2px solid var(--berry);
  grid-template-columns: minmax(0, 1fr) 240px;
  padding-bottom: 18px;
}

.sheet-header p,
.sheet-header h2,
.sheet-header span,
.sheet-header small {
  display: block;
  margin: 0;
}

.sheet-header p {
  color: var(--rose-strong);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sheet-header h2 {
  font-size: 32px;
  letter-spacing: 0;
  line-height: 1.05;
  margin-top: 8px;
}

.sheet-header span {
  color: var(--berry);
  font-weight: 900;
  margin-top: 10px;
}

.sheet-header small {
  color: var(--muted);
  font-weight: 700;
  margin-top: 4px;
}

.sheet-total {
  background: linear-gradient(135deg, var(--berry), var(--rose-strong));
  border-radius: 8px;
  color: #ffffff;
  padding: 18px;
  text-align: right;
}

.sheet-total span {
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-total strong {
  display: block;
  font-size: 30px;
  line-height: 1.05;
  margin-top: 8px;
}

.sheet-kpis {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.sheet-kpis div {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px;
}

.sheet-kpis span {
  color: var(--muted);
  display: block;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.sheet-kpis strong {
  color: var(--berry);
  display: block;
  font-size: 17px;
  margin-top: 5px;
}

.sheet-table {
  border-collapse: collapse;
  min-width: 0;
  width: 100%;
}

.sheet-table th,
.sheet-table td {
  border-bottom: 1px solid #ead7e1;
  padding: 9px 8px;
}

.sheet-table th {
  color: var(--berry);
  font-size: 10px;
}

.sheet-table td {
  font-size: 12px;
}

.sheet-table th:not(:first-child),
.sheet-table td:not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

.sheet-table td:first-child {
  font-weight: 800;
}

.sheet-table td:last-child,
.sheet-table th:last-child {
  font-weight: 900;
}

.sheet-table tfoot th {
  background: var(--plum);
  color: #ffffff;
}

.sheet-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  grid-template-columns: 1fr 1fr;
  margin-top: auto;
  padding-top: 12px;
}

.sheet-footer span:last-child {
  text-align: right;
}

.export-preview {
  align-items: center;
  background: rgba(45, 24, 54, 0.56);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 22px;
  position: fixed;
  z-index: 50;
}

.export-preview-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-height: 92vh;
  max-width: min(920px, 96vw);
  overflow: auto;
  padding: 18px;
  width: 100%;
}

.export-preview-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.export-preview img {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  height: auto;
  max-height: 68vh;
  max-width: 100%;
  object-fit: contain;
  width: 100%;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.history-item summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.history-item summary small {
  color: var(--muted);
  display: block;
}

.empty-state {
  color: var(--muted);
  font-weight: 700;
  margin: 0;
  padding: 18px;
  text-align: center;
}

.settings-panel {
  max-width: 720px;
}

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

  .sidebar {
    height: auto;
    position: static;
  }

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

  .logout-link {
    margin-top: 0;
  }

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

  .two-columns,
  .employee-layout,
  .loans-layout {
    grid-template-columns: 1fr;
  }
}

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

  .main-content,
  .sidebar {
    padding: 16px;
  }

  .app-shell {
    min-height: 100svh;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    border-right: 0;
    gap: 12px;
    padding: 12px;
    position: sticky;
    top: 0;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    overflow: hidden;
    z-index: 20;
  }

  .brand-mark {
    flex-basis: 40px;
    font-size: 20px;
    height: 40px;
    width: 40px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand small {
    font-size: 12px;
  }

  .topbar,
  .section-head,
  .inline-form {
    align-items: stretch;
    display: grid;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
  }

  .topbar-actions,
  .section-actions {
    display: grid;
    justify-self: stretch;
    width: 100%;
  }

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

  .period-range {
    font-size: 12px;
  }

  .nav-list,
  .metric-grid,
  .mini-stats,
  .form-row,
  .attendance-guide,
  .week-form {
    grid-template-columns: 1fr;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin: 0 -12px;
    max-width: 100vw;
    min-width: 0;
    overflow-x: auto;
    padding: 0 12px 4px;
    scroll-snap-type: x proximity;
    width: calc(100vw - 0px);
  }

  .nav-list a {
    flex: 0 0 auto;
    min-width: max-content;
    padding: 9px 12px;
    scroll-snap-align: start;
  }

  .logout-link {
    align-self: start;
    font-size: 13px;
    margin-top: 0;
    padding: 7px 10px;
  }

  .main-content {
    gap: 16px;
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .panel {
    max-width: 100%;
    min-width: 0;
    padding: 14px;
  }

  .content-grid {
    min-width: 0;
  }

  .metric {
    min-height: 92px;
    padding: 14px;
  }

  .metric strong {
    font-size: 26px;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .attendance-wrap table {
    min-width: 1110px;
  }

  .attendance-table th:not(:first-child),
  .attendance-table td:not(:first-child) {
    width: 126px;
  }

  .attendance-table td:first-child {
    min-width: 210px;
  }

  .attendance-table select {
    min-height: 36px;
  }

  .payment-form {
    min-width: 0;
  }

  .export-preview {
    padding: 10px;
  }

  .export-preview-panel {
    max-height: 94vh;
    padding: 12px;
  }

  .button {
    width: 100%;
  }

  .search-input {
    max-width: none;
  }

  .letter-stage {
    overflow-x: hidden;
    padding: 10px;
  }

  .payroll-sheet {
    gap: 14px;
    min-height: auto;
    padding: 18px;
    width: 100%;
  }

  .sheet-header {
    grid-template-columns: 1fr;
  }

  .sheet-header h2 {
    font-size: 27px;
  }

  .sheet-total {
    text-align: left;
  }

  .sheet-total strong {
    font-size: 26px;
  }

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

  .sheet-table {
    table-layout: fixed;
  }

  .sheet-table th,
  .sheet-table td {
    font-size: 10px;
    padding: 7px 4px;
    white-space: normal;
  }

  .sheet-table th:first-child,
  .sheet-table td:first-child {
    width: 54%;
  }

  .sheet-table th:nth-child(2),
  .sheet-table td:nth-child(2),
  .sheet-table th:nth-child(3),
  .sheet-table td:nth-child(3),
  .sheet-table th:nth-child(4),
  .sheet-table td:nth-child(4) {
    display: none;
  }

  .sheet-table th:nth-child(5),
  .sheet-table td:nth-child(5),
  .sheet-table th:nth-child(6),
  .sheet-table td:nth-child(6) {
    width: 23%;
  }

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

  .login-hero h1 {
    font-size: 48px;
  }
}

@media print {
  @page {
    margin: 0.35in;
    size: letter;
  }

  body {
    background: #ffffff;
  }

  .sidebar,
  .topbar-actions,
  .section-actions,
  .button,
  .search-input,
  form[data-confirm] {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main-content {
    padding: 0;
  }

  .panel,
  .metric {
    box-shadow: none;
  }

  .letter-stage {
    background: #ffffff;
    border: 0;
    margin: 0;
    overflow: visible;
    padding: 0;
  }

  .payroll-sheet {
    border: 0;
    box-shadow: none;
    min-height: auto;
    padding: 0;
    width: 100%;
  }

  .table-wrap {
    display: none;
  }
}
