:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --text: #15211f;
  --muted: #66736f;
  --line: #dfe7e4;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --primary-soft: #dff3ef;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --shadow: 0 14px 35px rgba(25, 54, 48, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  color: white;
  background: #102c29;
  transition: transform .25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: var(--primary-dark);
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 3px 0 0; color: #b7cfca; font-size: 12px; }

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

.nav-item {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  color: #c8dad6;
  background: transparent;
  transition: background .18s ease, color .18s ease;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.13); color: #fff; font-weight: 700; }

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 14px;
  background: rgba(255,255,255,.05);
}

.sidebar-note strong { display: block; margin-bottom: 5px; font-size: 13px; }
.sidebar-note span { color: #b7cfca; font-size: 11px; line-height: 1.5; }

.main-content {
  min-height: 100vh;
  margin-left: 260px;
  padding: 0 28px 48px;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 16px 0;
  background: rgba(244, 247, 246, .9);
  backdrop-filter: blur(10px);
}

.topbar h2 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; }
.menu-button {
  display: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 42px;
  height: 42px;
  background: #fff;
}

.view { display: none; }
.view.active { display: block; }

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

.summary-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-card.accent-card {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #0f766e, #14564f);
}

.summary-label { display: block; margin-bottom: 13px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.accent-card .summary-label { color: #c6e6df; }
.summary-card strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 25px; letter-spacing: -.04em; }
.summary-card small { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }
.accent-card small { color: #c6e6df; }

.content-grid { display: grid; gap: 18px; }
.dashboard-grid { grid-template-columns: minmax(0, 1.6fr) minmax(300px, .8fr); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.entry-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin: 18px 0; }

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 19px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.compact-header { padding-bottom: 15px; }
.form-panel { margin-bottom: 18px; }
.entry-columns .form-panel { margin-bottom: 0; }

.chart-wrap { position: relative; min-height: 330px; padding: 18px; }
#salaryChart { display: block; width: 100%; height: 290px; }
.empty-state { display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.chart-wrap .empty-state { position: absolute; inset: 0; }

.recent-list { padding: 10px 18px 18px; }
.recent-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 2px; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: 0; }
.recent-item strong { display: block; font-size: 13px; }
.recent-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.recent-amount { text-align: right; }
.recent-amount strong { color: var(--primary); }

.text-button { border: 0; padding: 6px 0; color: var(--primary); background: transparent; font-weight: 700; }

.button {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  transition: transform .12s ease, background .18s ease, border-color .18s ease;
}
.button:active { transform: translateY(1px); }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: var(--primary-dark); border-color: #bcd9d4; background: var(--primary-soft); }
.button.secondary:hover { background: #d1ebe6; }
.button.ghost { color: var(--text); border-color: var(--line); background: #fff; }
.button.ghost:hover { background: var(--panel-soft); }
.button.danger { color: var(--danger); border-color: #f0c4c0; background: var(--danger-soft); }
.button.small { padding: 8px 11px; font-size: 12px; }
.button.hidden, .hidden { display: none !important; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; }
.form-grid.one-column { grid-template-columns: 1fr; }
.overtime-grid { grid-template-columns: 1fr 1fr 1fr; }
.field { display: grid; gap: 7px; min-width: 0; }
.field > span, .calculated-field > span { color: #40514d; font-size: 12px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid #ccd8d5;
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
textarea { resize: vertical; min-height: 104px; }
.form-panel > .field { padding: 20px; }
.calculated-field { display: grid; align-content: center; gap: 8px; padding: 12px 14px; border: 1px dashed #b7cbc6; border-radius: 12px; background: var(--panel-soft); }
.calculated-field strong { color: var(--primary); font-size: 20px; }

.dynamic-rows { display: grid; gap: 10px; padding: 18px 20px 20px; }
.money-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 38px; gap: 9px; align-items: center; }
.remove-row { width: 38px; height: 38px; border: 1px solid #efc7c4; border-radius: 10px; color: var(--danger); background: #fff5f4; font-size: 20px; line-height: 1; }

.salary-total-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid #bcd9d4;
  border-radius: var(--radius);
  background: #edf8f5;
}
.salary-total-card > div { padding: 10px 14px; }
.salary-total-card span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.salary-total-card strong { display: block; margin-top: 8px; font-size: 21px; }
.salary-total-card .net-total { border-radius: 13px; color: #fff; background: var(--primary); }
.salary-total-card .net-total span { color: #d3eee8; }
.salary-total-card .net-total strong { font-size: 25px; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-actions.align-left { justify-content: flex-start; padding: 0 20px 20px; }

.history-header { align-items: flex-end; }
.history-tools { display: flex; align-items: center; gap: 9px; }
.history-tools input { min-width: 230px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; white-space: nowrap; }
th { color: #566762; background: #f7faf9; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
td strong { color: var(--primary); }
.actions-cell { display: flex; gap: 6px; }
.table-action { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; color: var(--text); background: #fff; font-size: 11px; }
.table-action:hover { background: var(--panel-soft); }
.table-action.delete { color: var(--danger); }
.table-empty { padding: 38px; }

.backup-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 20px; }
.file-button input { display: none; }
.info-box { margin: 0 20px 20px; padding: 14px 16px; border-radius: 12px; background: #f4f8f7; }
.info-box strong { display: block; margin-bottom: 5px; font-size: 12px; }
.info-box p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 16px;
  border-radius: 11px;
  color: #fff;
  background: #173b36;
  box-shadow: 0 14px 30px rgba(0,0,0,.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 22px; background: rgba(4, 21, 18, .58); }
.modal-card { width: min(760px, 100%); max-height: 90vh; overflow: auto; border-radius: 18px; background: #fff; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.modal-header, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-header h3 { margin: 0; }
.modal-actions { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.icon-button { border: 0; width: 34px; height: 34px; border-radius: 9px; background: #f2f5f4; font-size: 23px; }
.payslip-content { padding: 30px; }
.payslip-heading { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 20px; border-bottom: 2px solid var(--text); }
.payslip-heading h2 { margin: 0 0 5px; }
.payslip-heading p { margin: 0; color: var(--muted); }
.payslip-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.payslip-summary div { padding: 14px; border-radius: 11px; background: #f5f8f7; }
.payslip-summary span { display: block; color: var(--muted); font-size: 11px; }
.payslip-summary strong { display: block; margin-top: 7px; font-size: 17px; }
.payslip-section { margin-top: 22px; }
.payslip-section h4 { margin: 0 0 9px; font-size: 13px; }
.payslip-line { display: flex; justify-content: space-between; gap: 18px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.payslip-net { display: flex; justify-content: space-between; margin-top: 22px; padding: 16px; border-radius: 12px; color: #fff; background: var(--primary); }
.payslip-notes { margin-top: 18px; padding: 14px; border-radius: 10px; background: #f7faf9; color: var(--muted); font-size: 12px; white-space: pre-wrap; }

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0,0,0,.22); }
  .main-content { margin-left: 0; padding: 0 18px 36px; }
  .menu-button { display: block; }
  .entry-columns { grid-template-columns: 1fr; }
  .overtime-grid { grid-template-columns: 1fr 1fr; }
  .calculated-field { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .main-content { padding-inline: 12px; }
  .topbar { min-height: 74px; }
  .topbar h2 { font-size: 20px; }
  .topbar-actions .button { padding: 9px 11px; font-size: 12px; }
  .summary-grid { grid-template-columns: 1fr; }
  .form-grid, .overtime-grid, .salary-total-card { grid-template-columns: 1fr; }
  .money-row { grid-template-columns: minmax(0, 1fr) 105px 36px; }
  .panel-header, .history-header { align-items: flex-start; flex-direction: column; }
  .history-tools { width: 100%; flex-direction: column; align-items: stretch; }
  .history-tools input { min-width: 0; }
  .payslip-content { padding: 20px; }
  .payslip-heading { flex-direction: column; }
  .payslip-summary { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden !important; }
  #payslipModal, #payslipModal * { visibility: visible !important; }
  #payslipModal { position: absolute; inset: 0; display: block !important; padding: 0; background: #fff; }
  #payslipModal .modal-card { width: 100%; max-height: none; overflow: visible; border-radius: 0; box-shadow: none; }
  .no-print { display: none !important; }
  .payslip-content { padding: 18mm 16mm; }
}
