:root {
  --ink: #172026;
  --muted: #62717c;
  --line: #d8e0e6;
  --surface: #ffffff;
  --soft: #f3f6f8;
  --deep: #113c4a;
  --teal: #127a78;
  --gold: #d59f2a;
  --red: #b8463c;
  --green: #28724f;
  --shadow: 0 18px 36px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--soft);
  font-family:
    Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}

body.login-mode {
  display: block;
}

body.login-mode .sidebar,
body.login-mode .topbar {
  display: none;
}

body.login-mode main {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

body.login-mode .workspace {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
}

.login-panel {
  padding: 28px;
}

.google-login-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: white;
  box-shadow: 0 1px 2px rgba(23, 32, 38, 0.08);
  font-weight: 600;
  text-decoration: none;
}

.google-login-button:hover {
  border-color: #aebbc4;
  background: #f8fafb;
}

.google-mark {
  color: #4285f4;
  font-size: 20px;
  font-weight: 700;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  color: var(--muted);
  font-size: 13px;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 45, 54, 0.38);
}

.modal-panel {
  width: min(440px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.wide-modal {
  width: min(760px, 100%);
}

.employee-check-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

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

.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  background: #102d36;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: contain;
  flex: 0 0 48px;
}

.brand strong,
.brand span,
.user-switch span {
  display: block;
}

.brand span,
.user-switch span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  margin-top: 3px;
}

.user-switch {
  display: grid;
  gap: 8px;
}

.user-switch strong {
  font-size: 14px;
}

.user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.user-actions button {
  font-size: 13px;
}

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

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

.sidebar select {
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.sidebar option {
  color: var(--ink);
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

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

main {
  min-width: 0;
}

.topbar {
  min-height: 92px;
  padding: 22px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: white;
  border-bottom: 1px solid var(--line);
}

.topbar p {
  color: var(--muted);
  margin: 0 0 5px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  margin-bottom: 14px;
}

h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.workspace {
  padding: 28px 30px 42px;
  display: grid;
  gap: 22px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.span-4 {
  grid-column: 1 / -1;
}

.span-5 {
  grid-column: 1 / -1;
}

.span-6 {
  grid-column: 1 / -1;
}

.span-7 {
  grid-column: 1 / -1;
}

.span-8 {
  grid-column: 1 / -1;
}

.span-12 {
  grid-column: 1 / -1;
}

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

.panel {
  padding: 18px;
}

.metric {
  min-height: 128px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
}

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

.metric small {
  color: var(--muted);
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

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

.readonly-field {
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  display: grid;
  gap: 4px;
}

.readonly-field span {
  color: var(--muted);
  font-size: 13px;
}

.readonly-field strong {
  font-size: 15px;
}

.datetime-field {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 7px;
}

.datetime-parts {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 76px 76px;
  gap: 8px;
}

.datetime-parts input,
.datetime-parts select {
  min-width: 0;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--deep);
  color: white;
  cursor: pointer;
}

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

button.warn {
  background: var(--red);
}

button.ok {
  background: var(--green);
}

button.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.icon-button {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafb;
}

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

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: 6px;
}

.table-scroll table {
  width: max-content;
}

.management-table {
  min-width: 1760px;
}

.management-table th,
.management-table td {
  white-space: normal;
}

.management-table select,
.management-table input,
.management-table textarea {
  min-width: 100%;
}

.management-table textarea {
  min-height: 96px;
}

.leave-management-table th:nth-child(1),
.leave-management-table td:nth-child(1),
.leave-management-table th:nth-child(2),
.leave-management-table td:nth-child(2),
.leave-management-table th:nth-child(6),
.leave-management-table td:nth-child(6) {
  min-width: 190px;
}

.leave-management-table th:nth-child(3),
.leave-management-table td:nth-child(3),
.leave-management-table th:nth-child(4),
.leave-management-table td:nth-child(4) {
  min-width: 370px;
}

.leave-management-table th:nth-child(5),
.leave-management-table td:nth-child(5) {
  min-width: 96px;
}

.leave-management-table th:nth-child(7),
.leave-management-table td:nth-child(7),
.leave-management-table th:nth-child(8),
.leave-management-table td:nth-child(8) {
  min-width: 150px;
}

.leave-management-table th:nth-child(9),
.leave-management-table td:nth-child(9),
.leave-management-table th:nth-child(10),
.leave-management-table td:nth-child(10) {
  min-width: 260px;
}

.leave-management-table th:nth-child(11),
.leave-management-table td:nth-child(11) {
  min-width: 150px;
}

.overtime-management-table {
  min-width: 1280px;
}

.overtime-management-table th:nth-child(1),
.overtime-management-table td:nth-child(1),
.overtime-management-table th:nth-child(3),
.overtime-management-table td:nth-child(3) {
  min-width: 190px;
}

.overtime-management-table th:nth-child(2),
.overtime-management-table td:nth-child(2),
.overtime-management-table th:nth-child(5),
.overtime-management-table td:nth-child(5) {
  min-width: 150px;
}

.overtime-management-table th:nth-child(4),
.overtime-management-table td:nth-child(4) {
  min-width: 110px;
}

.overtime-management-table th:nth-child(6),
.overtime-management-table td:nth-child(6),
.overtime-management-table th:nth-child(7),
.overtime-management-table td:nth-child(7) {
  min-width: 280px;
}

.overtime-management-table th:nth-child(8),
.overtime-management-table td:nth-child(8) {
  min-width: 150px;
}

.payroll-table {
  min-width: 1720px;
}

.payroll-table th:nth-child(1),
.payroll-table td:nth-child(1) {
  min-width: 170px;
}

.payroll-table th:nth-child(2),
.payroll-table td:nth-child(2),
.payroll-table th:nth-child(6),
.payroll-table td:nth-child(6),
.payroll-table th:nth-child(7),
.payroll-table td:nth-child(7) {
  min-width: 120px;
}

.payroll-table th:nth-child(3),
.payroll-table td:nth-child(3),
.payroll-table th:nth-child(4),
.payroll-table td:nth-child(4),
.payroll-table th:nth-child(5),
.payroll-table td:nth-child(5) {
  min-width: 420px;
}

.payroll-lines {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.payroll-line {
  display: grid;
  grid-template-columns: minmax(150px, 1.4fr) minmax(72px, 0.5fr) minmax(92px, 0.7fr) auto;
  gap: 8px;
  align-items: center;
}

.payroll-line.insurance-line {
  grid-template-columns: minmax(210px, 1fr) minmax(92px, 0.5fr);
}

.payroll-line span,
.muted {
  color: var(--muted);
}

.payroll-line input[readonly] {
  background: #f8fafb;
}

.settings-table {
  min-width: 1120px;
}

.settings-table th,
.settings-table td {
  white-space: normal;
}

.settings-table input,
.settings-table select {
  min-width: 100%;
}

.employee-create-form {
  margin-bottom: 18px;
}

.employee-settings-table {
  min-width: 2300px;
}

.employee-settings-table th:nth-child(1),
.employee-settings-table td:nth-child(1),
.employee-settings-table th:nth-child(2),
.employee-settings-table td:nth-child(2),
.employee-settings-table th:nth-child(8),
.employee-settings-table td:nth-child(8),
.employee-settings-table th:nth-child(9),
.employee-settings-table td:nth-child(9) {
  min-width: 150px;
}

.employee-settings-table th:nth-child(3),
.employee-settings-table td:nth-child(3) {
  min-width: 230px;
}

.employee-settings-table th:nth-child(4),
.employee-settings-table td:nth-child(4),
.employee-settings-table th:nth-child(10),
.employee-settings-table td:nth-child(10),
.employee-settings-table th:nth-child(11),
.employee-settings-table td:nth-child(11),
.employee-settings-table th:nth-child(12),
.employee-settings-table td:nth-child(12),
.employee-settings-table th:nth-child(14),
.employee-settings-table td:nth-child(14) {
  min-width: 130px;
}

.employee-settings-table th:nth-child(13),
.employee-settings-table td:nth-child(13) {
  min-width: 210px;
}

.employee-settings-table th:nth-child(5),
.employee-settings-table td:nth-child(5),
.employee-settings-table th:nth-child(6),
.employee-settings-table td:nth-child(6),
.employee-settings-table th:nth-child(7),
.employee-settings-table td:nth-child(7) {
  min-width: 170px;
}

.leave-type-settings-table th:nth-child(1),
.leave-type-settings-table td:nth-child(1) {
  min-width: 130px;
}

.leave-type-settings-table th:nth-child(2),
.leave-type-settings-table td:nth-child(2) {
  min-width: 160px;
}

.leave-type-settings-table th:nth-child(3),
.leave-type-settings-table td:nth-child(3),
.leave-type-settings-table th:nth-child(4),
.leave-type-settings-table td:nth-child(4),
.leave-type-settings-table th:nth-child(8),
.leave-type-settings-table td:nth-child(8),
.leave-type-settings-table th:nth-child(9),
.leave-type-settings-table td:nth-child(9) {
  min-width: 120px;
}

.leave-type-settings-table th:nth-child(5),
.leave-type-settings-table td:nth-child(5) {
  min-width: 180px;
}

.leave-type-settings-table th:nth-child(6),
.leave-type-settings-table td:nth-child(6),
.leave-type-settings-table th:nth-child(7),
.leave-type-settings-table td:nth-child(7),
.balance-settings-table th:nth-child(5),
.balance-settings-table td:nth-child(5),
.balance-settings-table th:nth-child(6),
.balance-settings-table td:nth-child(6) {
  min-width: 150px;
}

.balance-management {
  display: grid;
  gap: 14px;
}

.balance-settings-table th:nth-child(1),
.balance-settings-table td:nth-child(1) {
  min-width: 170px;
}

.balance-settings-table th:nth-child(2),
.balance-settings-table td:nth-child(2),
.balance-settings-table th:nth-child(3),
.balance-settings-table td:nth-child(3),
.balance-settings-table th:nth-child(4),
.balance-settings-table td:nth-child(4),
.balance-settings-table th:nth-child(7),
.balance-settings-table td:nth-child(7) {
  min-width: 120px;
}

.balance-settings-table small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #edf2f4;
  color: var(--muted);
  white-space: nowrap;
}

.status.approved,
.status.manager_pending {
  background: #e8f3ed;
  color: var(--green);
}

.status.rejected,
.status.delegate_rejected {
  background: #f8e9e7;
  color: var(--red);
}

.status.delegate_pending {
  background: #fff5d8;
  color: #8a6200;
}

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

.toolbar p {
  color: var(--muted);
  margin-bottom: 0;
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 16px;
}

.subtabs button.active {
  background: var(--deep);
  color: white;
}

.data-table {
  min-width: 960px;
}

.data-table th,
.data-table td {
  white-space: nowrap;
  vertical-align: middle;
}

.resizable-record-cell {
  display: block;
  overflow: hidden;
  resize: horizontal;
  white-space: nowrap;
  min-width: 6em;
  max-width: 80vw;
}

.reason-cell {
  width: var(--reason-cell-width, 20em);
}

.rejection-cell {
  width: var(--rejection-cell-width, 10em);
}

.data-table input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.compact-actions {
  flex-wrap: nowrap;
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
}

.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--muted);
}

.inline-check input {
  width: auto;
}

.list-limit-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty strong {
  color: var(--ink);
}

.notice {
  border-left: 4px solid var(--gold);
  padding: 12px 14px;
  background: #fff8e4;
  color: #725318;
  border-radius: 6px;
}

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

.comp-time-section {
  margin-top: 18px;
}

.comp-time-section h3 {
  margin-bottom: 10px;
}

.comp-time-scroll.scrollable {
  max-height: 470px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.comp-time-scroll.scrollable table {
  margin: 0;
}

.mini-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mini-row p {
  margin: 2px 0 0;
  color: var(--muted);
}

.approval-row {
  align-items: start;
}

.approval-detail {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.reject-note {
  max-width: 520px;
}

.reject-note textarea {
  min-height: 72px;
}

@media (max-width: 960px) {
  body {
    grid-template-columns: 1fr;
  }

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

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

  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8 {
    grid-column: span 12;
  }
}

@media (max-width: 640px) {
  .topbar,
  .workspace {
    padding-left: 16px;
    padding-right: 16px;
  }

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

  .datetime-parts {
    grid-template-columns: minmax(150px, 1fr) 72px 72px;
  }

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

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

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

  .filter-actions {
    justify-content: stretch;
  }

  .approval-row {
    grid-template-columns: 1fr;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
