:root {
  --accent: #168fa8;
  --accent-dark: #0f7085;
  --accent-soft: #dff3f6;
  --background: #eef8fa;
  --surface: #fff;
  --text: #18333c;
  --muted: #58747c;
  --border: #d5e8eb;
  --border-strong: #b9d8de;
  --danger: #a83e4a;
  --danger-soft: #fff0f1;
  --success: #267860;
  --success-soft: #e8f6f1;
  --warning: #8a6112;
  --warning-soft: #fff7df;
  --shadow: 0 14px 40px rgba(24, 78, 90, 0.09);
  --radius-large: 18px;
  --radius-medium: 12px;
  color: var(--text);
  background: var(--background);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  font-synthesis: none;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 88% 2%, rgba(22, 143, 168, 0.08), transparent 28rem),
    var(--background);
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
[tabindex] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
dialog:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #0b6678;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.65rem, 3vw, 2.15rem);
  line-height: 1.25;
  letter-spacing: -0.025em;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.14rem;
  line-height: 1.35;
}

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

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1.3;
}

.login-view {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  overflow: hidden;
  padding: 24px;
}

.login-view::before,
.login-view::after {
  position: fixed;
  z-index: -1;
  width: 360px;
  height: 360px;
  border: 1px solid rgba(22, 143, 168, 0.14);
  border-radius: 50%;
  content: "";
}

.login-view::before {
  top: -190px;
  right: -80px;
  box-shadow: 0 0 0 56px rgba(255, 255, 255, 0.34), 0 0 0 112px rgba(22, 143, 168, 0.025);
}

.login-view::after {
  bottom: -240px;
  left: -110px;
  box-shadow: 0 0 0 48px rgba(255, 255, 255, 0.32);
}

.login-card {
  width: min(430px, 100%);
  padding: clamp(28px, 6vw, 42px);
}

.login-card h1 {
  font-size: clamp(2rem, 7vw, 2.75rem);
}

.login-copy {
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field + .field {
  margin-top: 18px;
}

.field label {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.field label span,
.required-note {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  color: var(--text);
  background: #f9fcfd;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

input:hover {
  border-color: #8fc3cd;
}

input:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(22, 143, 168, 0.1);
}

input::placeholder {
  color: #81989e;
}

select {
  width: 100%;
  min-height: 48px;
  padding: 11px 38px 11px 13px;
  color: var(--text);
  background: #f9fcfd;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
}

.input-unit {
  position: relative;
}

.input-unit input {
  padding-right: 46px;
}

.input-unit > span {
  position: absolute;
  top: 50%;
  right: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  transform: translateY(-50%);
}

.button,
.icon-button,
.tab {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease, color 140ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  color: #fff;
  background: var(--accent-dark);
  box-shadow: 0 8px 20px rgba(15, 112, 133, 0.22);
}

.primary:hover:not(:disabled) {
  background: #0b5c6c;
  box-shadow: 0 10px 24px rgba(11, 92, 108, 0.26);
}

.secondary {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid #c4e5ea;
}

.ghost,
.text-button {
  color: var(--accent-dark);
  background: transparent;
}

.ghost:hover:not(:disabled),
.text-button:hover:not(:disabled) {
  background: var(--accent-soft);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #f1ccd0;
}

.compact {
  min-height: 44px;
  padding: 7px 11px;
  font-size: 0.78rem;
}

.full-width {
  width: 100%;
  margin-top: 22px;
}

.message {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 650;
}

.error {
  color: #8f2533;
  background: var(--danger-soft);
  border: 1px solid #f1c7cc;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px clamp(16px, 4vw, 42px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand {
  display: grid;
  line-height: 1.2;
}

.brand strong {
  font-size: 1.08rem;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.session,
.session-person {
  display: flex;
  align-items: center;
}

.session {
  gap: 12px;
}

.session-person {
  gap: 7px;
  font-size: 0.84rem;
}

.role-badge {
  padding: 3px 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 800;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 9px clamp(16px, 4vw, 42px);
  background: rgba(255, 255, 255, 0.84);
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  padding: 9px 15px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tab:hover {
  color: var(--accent-dark);
  background: #f0f9fa;
}

.tab.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px #c7e7ec;
}

.app-main {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: clamp(22px, 4vw, 42px);
}

.loading-status {
  position: fixed;
  z-index: 40;
  top: 82px;
  right: 18px;
  min-height: 0;
  margin: 0;
  padding: 7px 12px;
  color: var(--accent-dark);
  background: #e2f5f7;
  border: 1px solid #bee1e6;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(24, 78, 90, 0.1);
  font-size: 0.75rem;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.is-loading .loading-status:not(:empty) {
  opacity: 1;
  transform: translateY(0);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: panel-in 180ms ease both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-heading,
.section-heading,
.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.page-heading {
  align-items: flex-end;
  margin-bottom: 20px;
}

.page-heading p:not(.eyebrow),
.preview-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.business-date {
  flex: 0 0 auto;
  padding: 7px 11px;
  color: var(--accent-dark) !important;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 0 0 18px;
}

.metric {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 7px 24px rgba(24, 78, 90, 0.055);
}

.metric::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 42px;
  height: 3px;
  background: #bedfe5;
  border-radius: 0 0 0 4px;
  content: "";
}

.metric > span,
.metric > small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric > span {
  font-weight: 750;
}

.metric strong {
  display: block;
  margin: 4px 0 2px;
  overflow: hidden;
  font-size: clamp(1.18rem, 2vw, 1.55rem);
  letter-spacing: -0.02em;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accent-metric::after,
.status-metric.unpaid::after {
  background: var(--accent);
}

.overpaid-metric {
  background: var(--warning-soft);
  border-color: #eedda9;
}

.overpaid-metric::after,
.status-metric.overpaid::after {
  background: var(--warning);
}

.status-metric.paid::after {
  background: var(--success);
}

.entry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 16px;
  align-items: stretch;
}

.entry-form,
.preview-card {
  padding: clamp(20px, 3vw, 28px);
}

.entry-form .section-heading {
  margin-bottom: 20px;
}

.preview-card {
  background:
    linear-gradient(150deg, rgba(223, 243, 246, 0.35), transparent 65%),
    var(--surface);
}

.preview-card dl {
  margin: 4px 0 18px;
}

.preview-card dl > div {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}

.preview-card dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.preview-card dd {
  margin: 0;
  font-weight: 800;
}

.preview-note {
  padding: 10px 12px;
  background: #f3fafb;
  border-radius: 9px;
}

.recent-section,
.payroll-history-section,
.audit-section,
.admin-detail-section {
  margin-top: 30px;
}

.admin-summary-grid {
  display: grid;
  gap: 24px;
}

.admin-summary-grid h2,
.admin-detail-section h2,
.audit-section h2 {
  margin-bottom: 10px;
}

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

.admin-table-wrap {
  overflow-x: auto;
}

.audit-json {
  min-width: 280px;
  max-width: 440px;
  white-space: normal;
}

.audit-json details + details {
  margin-top: 6px;
}

.audit-json summary {
  min-height: 44px;
  padding: 11px 0;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 750;
}

.audit-json pre {
  max-height: 180px;
  margin: 0 0 8px;
  padding: 12px;
  overflow: auto;
  color: var(--text);
  background: #f3fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 0.72rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.recent-section .section-heading {
  align-items: end;
  margin-bottom: 10px;
}

.recent-section h2,
.payroll-history-section h2 {
  margin-bottom: 0;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(150px, 1fr) minmax(150px, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  padding: 16px;
  box-shadow: 0 7px 24px rgba(24, 78, 90, 0.055);
}

.history-filters .field + .field {
  margin-top: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}

th,
td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  background: #f7fbfc;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

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

tbody tr:hover td {
  background: #f9fcfd;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: flex;
  gap: 6px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
}

.status.unpaid {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: #eddda9;
}

.status.paid {
  color: var(--success);
  background: var(--success-soft);
  border-color: #cbe8dc;
}

.status.overpaid {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #efd1cc;
}

.pay-button {
  min-height: 44px;
  color: #fff;
  background: var(--accent-dark);
}

.pay-button:hover:not(:disabled) {
  background: #075b6b;
}

.employee-create-card,
.issued-key-box {
  padding: clamp(20px, 3vw, 28px);
}

.employee-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(150px, 0.6fr);
  gap: 12px;
}

.employee-form-grid .field + .field {
  margin-top: 0;
}

.issued-key-box {
  background: linear-gradient(145deg, #f8fcfd, #e8f7f9);
  border-color: #9eced7;
}

.issued-key-box pre {
  min-height: 72px;
  margin: 16px 0;
  padding: 14px;
  overflow-wrap: anywhere;
  color: #123842;
  background: #fff;
  border: 1px solid #9eced7;
  border-radius: 9px;
  font: 700 0.82rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  user-select: all;
  white-space: pre-wrap;
}

.masked-key {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
}

.muted-action {
  color: var(--muted);
  font-size: 0.76rem;
}

.empty-state {
  margin: 0;
  padding: 30px 20px;
  color: var(--muted);
  text-align: center;
}

.positive {
  color: var(--success);
  font-weight: 750;
}

.negative {
  color: var(--danger);
  font-weight: 750;
}

.edit-dialog,
.employee-dialog {
  width: min(520px, calc(100% - 28px));
  margin: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
  box-shadow: 0 28px 80px rgba(20, 61, 70, 0.24);
}

.edit-dialog::backdrop,
.employee-dialog::backdrop {
  background: rgba(14, 43, 50, 0.48);
  backdrop-filter: blur(3px);
}

.edit-dialog form,
.employee-dialog form {
  padding: 26px;
}

.checkbox-field {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
}

.checkbox-field input {
  width: 22px;
  min-height: 22px;
}

.checkbox-field label {
  margin: 0;
}

.dialog-heading {
  margin-bottom: 20px;
}

.dialog-heading h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  background: #eff7f8;
  font-size: 1.35rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.toast {
  position: fixed;
  z-index: 80;
  right: 20px;
  bottom: 20px;
  max-width: min(390px, calc(100% - 40px));
  padding: 13px 17px;
  color: #fff;
  background: #163b44;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  box-shadow: 0 18px 44px rgba(15, 54, 62, 0.24);
  font-size: 0.84rem;
  font-weight: 700;
  animation: toast-in 180ms ease both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .app-header {
    position: relative;
    min-height: 66px;
    padding: 9px 14px;
  }

  .brand span {
    display: none;
  }

  .session-person {
    display: grid;
    gap: 0;
    justify-items: end;
  }

  .session .ghost {
    padding-inline: 10px;
  }

  .tabs {
    position: sticky;
    z-index: 18;
    top: 0;
    padding: 7px 12px;
  }

  .app-main {
    padding: 20px 14px 34px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .business-date {
    font-size: 0.75rem !important;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 9px;
  }

  .metric {
    padding: 13px;
  }

  .metric strong {
    font-size: 1.08rem;
  }

  .metric > small {
    display: none;
  }

  .entry-grid,
  .history-filters,
  .admin-content-grid,
  .employee-form-grid {
    grid-template-columns: 1fr;
  }

  .history-filters .field + .field {
    margin-top: 0;
  }

  .recent-section .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .recent-section .text-button {
    padding-left: 0;
  }

  .loading-status {
    top: auto;
    right: 12px;
    bottom: 12px;
  }

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

@media (max-width: 430px) {
  .login-view {
    padding: 14px;
  }

  .login-card {
    padding: 27px 21px;
  }

  .brand strong {
    font-size: 0.94rem;
  }

  .session {
    gap: 5px;
  }

  .session-person {
    font-size: 0.74rem;
  }

  .role-badge {
    padding: 1px 6px;
  }

  .session .ghost {
    font-size: 0.72rem;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
