:root {
  color-scheme: light dark;
  --bg: #f2f6ff;
  --card-bg: #ffffff;
  --text: #161a2c;
  --muted: #5b6479;
  --border: #d9e3f8;
  --accent: #2f6feb;
  --danger: #e0352b;
  --danger-bg: #fde9e8;
  --ok: #1f9d55;
  --ok-bg: #e4f7ec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --card-bg: #171e2e;
    --text: #eef2fc;
    --muted: #96a3bd;
    --border: #2c3652;
    --accent: #6d97ff;
    --danger: #ff6b60;
    --danger-bg: #3a1f1e;
    --ok: #4ade80;
    --ok-bg: #163526;
  }
}

* {
  box-sizing: border-box;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body {
  margin: 0;
  padding: 24px 16px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.card {
  max-width: 640px;
  margin: 0 auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

h1 { margin: 0 0 4px; font-size: 1.5rem; }
.subtitle { margin: 0 0 20px; color: var(--muted); font-size: 0.9rem; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.print-value {
  display: none;
  font-size: 1rem;
  color: var(--text);
}

.wfh-field {
  margin-top: 12px;
}

.wfh-field textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.94rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 44px;
}

.checkbox-row {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
  margin-bottom: 0;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.checkbox-row .state {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  flex: none;
}

.checkbox-row .state.on { color: var(--accent); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#costTable { margin-top: 16px; }
#costTable tr:first-child td { border-top: 1px solid var(--border); padding-top: 16px; }

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

th { color: var(--muted); font-weight: 600; }

td:last-child, th:last-child,
td:nth-child(2), th:nth-child(2),
td:nth-child(3), th:nth-child(3) {
  text-align: right;
}

tr.total td { font-weight: 700; border-top: 2px solid var(--border); }

.derived {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 6px 0 0;
}

#actualResult {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

#actualResult.ok {
  display: block;
  background: var(--ok-bg);
  color: var(--ok);
}

#actualResult.alert {
  display: block;
  background: var(--danger-bg);
  color: var(--danger);
}

@page {
  size: A4;
  margin: 10mm;
}

@media print {
  :root {
    --bg: #ffffff;
    --card-bg: #ffffff;
  }

  html, body { height: auto !important; min-height: 0 !important; }

  body { margin: 0; padding: 0; font-size: 1.05em; }
  .card { box-shadow: none; padding: 12px 18px; max-width: none; }
  h1 { font-size: 1.35rem; margin-bottom: 2px; }
  .subtitle { display: none; }
  h2 { margin: 12px 0 6px; font-size: 1.1rem; }
  label { font-size: 0.85rem; }
  input[type="number"] { display: none; }
  .print-value { display: block; margin-top: 4px; }
  #chargeRatePrintValue, #salaryPrintValue {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--accent);
  }
  section { margin-top: 10px; break-inside: avoid; }
  .checkbox-row { margin-top: 7px; }
  .checkbox-row input[type="checkbox"] { outline: 1px solid #8892a6; }
  .wfh-field { margin-top: 7px; }
  .wfh-field textarea { display: none; }
  .wfh-field .print-value {
    white-space: pre-wrap;
    border: 1px solid #8892a6;
    border-radius: 8px;
    padding: 6px 12px;
    min-height: 18px;
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--text);
  }
  #costTable { margin-top: 10px; }
  #costTable tr:first-child td { padding-top: 10px; }
  td, th { padding: 5px 4px; }
  .no-print { display: none !important; }
  #actualResult { padding: 8px 10px; margin-top: 8px; }
}
