:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: #f6f7f9;
  color: #1f2937;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; }
button, input { font: inherit; }
textarea, select { font: inherit; }
[hidden] { display: none !important; }

.app-container {
  width: 100%;
  min-height: 100vh;
  margin-inline: auto;
  padding: 24px 16px;
  background: #fff;
}

.login-screen, .home-screen, .records-screen, .record-screen, .admin-screen {
  display: grid;
  gap: 16px;
}

.login-screen h1, .login-screen p, .home-screen h1, .records-screen h1,
.record-screen h1, .admin-screen h1, .admin-screen p { margin: 0; }
.login-screen h1, .home-screen h1, .records-screen h1,
.record-screen h1, .admin-screen h1 { font-size: 1.5rem; line-height: 1.4; }
.login-screen h1 span { display: block; }
.login-screen > p, .admin-screen p { line-height: 1.7; }

.login-form { display: grid; gap: 10px; margin-top: 8px; }
.login-form input[type=email] {
  width: 100%; min-height: 46px; border: 1px solid #9ca3af;
  border-radius: 8px; padding: 10px 12px;
}
.login-form input[type=email]:focus {
  border-color: #b91c1c; outline: 3px solid #fecaca;
}
.submit-button, .primary-link {
  display: inline-flex; min-height: 46px; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; padding: 10px 16px;
  color: #fff; background: #b91c1c; font-weight: 700;
  text-decoration: none; cursor: pointer;
}
.submit-button:disabled { cursor: not-allowed; opacity: .55; }
.field-error, .notice { color: #991b1b; }
.field-error { font-size: .875rem; }
.success { color: #166534; }

.screen-header {
  display: grid; grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center; gap: 8px; min-height: 48px;
}
.screen-header h1 { grid-column: 2; text-align: center; font-size: 1.25rem; }
.screen-header > :last-child { justify-self: end; }
.screen-header-end h1 { grid-column: 1 / 3; justify-self: start; text-align: left; }
.icon-button {
  display: grid; width: 44px; height: 44px; place-items: center;
  border: 1px solid #d1d5db; border-radius: 50%;
  color: #374151; background: #fff; cursor: pointer; list-style: none;
}
.icon-button::-webkit-details-marker { display: none; }
.icon-button:hover { background: #f3f4f6; }
.back-link {
  display: inline-flex; width: max-content; min-height: 44px;
  align-items: center; gap: 6px; color: #374151;
  font-weight: 700; text-decoration: none;
}

.user-navigation { position: relative; }
.user-menu {
  position: absolute; z-index: 5; top: calc(100% + 8px); right: 0;
  min-width: 170px; padding: 6px; border: 1px solid #d1d5db;
  border-radius: 10px; background: #fff; box-shadow: 0 10px 24px rgb(0 0 0 / 15%);
}
.user-menu a, .user-menu button {
  display: flex; width: 100%; min-height: 44px; align-items: center;
  border: 0; border-radius: 6px; padding: 9px 12px;
  color: #374151; background: #fff; text-align: left;
  text-decoration: none; cursor: pointer;
}
.user-menu a:hover, .user-menu button:hover { background: #f3f4f6; }
.confirmation-dialog {
  width: min(100% - 32px, 400px); max-width: none; border: 0;
  border-radius: 12px; padding: 24px; color: #1f2937;
  box-shadow: 0 20px 40px rgb(0 0 0 / 25%);
}
.confirmation-dialog::backdrop { background: rgb(17 24 39 / 55%); }
.confirmation-dialog h2 { margin: 0; font-size: 1.25rem; }
.confirmation-dialog p { margin: 12px 0 0; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.text-button, .danger-button {
  min-height: 44px; border-radius: 8px; padding: 9px 14px;
  font-weight: 700; cursor: pointer;
}
.text-button { border: 1px solid #9ca3af; color: #374151; background: #fff; }
.danger-button { border: 0; color: #fff; background: #b91c1c; }
.danger-button:disabled { cursor: not-allowed; opacity: .55; }

.screen-placeholder {
  display: grid; min-height: 280px; place-items: center;
  align-content: center; gap: 20px; padding: 32px 16px; text-align: center;
}
.record-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.record-form [data-rate] { min-width: 0; }
.record-rate-settings { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
.record-rate-settings [data-rate="amount_based"] { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.rate-equation { display: flex; flex-wrap: nowrap; align-items: center; gap: 5px; width: max-content; max-width: 100%; min-width: 0; }
.rate-equation-part { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; white-space: nowrap; }
.rate-equation-part input { box-sizing: border-box; width: 5.5em; min-width: 5.5em; min-height: 44px; border: 1px solid #9ca3af; border-radius: 8px; padding: 9px 8px; background: #fff; text-align: right; }
.rate-equation-part:nth-child(2) input { width: 4.5em; min-width: 4.5em; }
.rate-equation-part span { flex: 0 0 auto; }
.record-field { display: grid; gap: 7px; min-width: 0; font-weight: 700; }
.record-field-label { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.record-field-label > span { flex: 0 1 auto; min-width: 0; }
.record-checkbox { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; }
.record-checkbox input { width: 20px; height: 20px; }
.record-field b { flex: 0 0 auto; color: #b91c1c; font-size: .8rem; white-space: nowrap; }
.record-field input, .record-field select, .record-field textarea { width: 100%; max-width: 100%; min-width: 0; min-height: 44px; border: 1px solid #9ca3af; border-radius: 8px; padding: 9px 11px; background: #fff; }
.record-field input[type="date"] { display: block; width: 11em; min-width: 0; max-width: 100%; }
.record-field textarea { min-height: 96px; resize: vertical; }
.record-field-control { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.record-field-control input { flex: 1 1 0%; }
.record-unit { flex: 0 0 auto; white-space: nowrap; }
.planned-miles { display: flex; align-items: center; justify-content: space-between; border-radius: 8px; padding: 14px; background: #fef2f2; color: #7f1d1d; }
.home-summary { display: grid; justify-items: center; gap: 18px; padding: 28px 16px; text-align: center; }
.lsp-gauge { position: relative; display: grid; width: min(72vw, 300px); aspect-ratio: 1; place-items: center; color: #7f1d1d; text-decoration: none; }
.lsp-gauge svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.lsp-gauge circle { fill: none; stroke-width: 8; }
.gauge-track { stroke: #fee2e2; }
.gauge-progress { stroke: #b91c1c; stroke-linecap: round; transition: stroke-dashoffset .2s ease; }
.gauge-value { position: relative; display: grid; gap: 2px; font-weight: 700; }
.gauge-value .gauge-title { color: #7f1d1d; font-size: .95rem; font-weight: 700; }
.gauge-value strong { font-size: 3rem; line-height: 1; }
.gauge-value small { color: #4b5563; font-weight: 400; }
.pending-total { margin: 0; }
.record-summary { display: flex; justify-content: space-between; gap: 12px; border-radius: 10px; padding: 13px; background: #fef2f2; color: #7f1d1d; }
.record-summary span { display: grid; gap: 3px; font-size: .85rem; }
.record-summary strong { font-size: 1.05rem; }
.record-filters { border: 1px solid #d1d5db; border-radius: 10px; padding: 0 14px; }
.record-filters summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.record-filters form { display: grid; gap: 12px; padding: 2px 0 16px; }
.record-filters label { display: grid; gap: 6px; font-weight: 700; }
.record-filters input, .record-filters select { min-height: 42px; border: 1px solid #9ca3af; border-radius: 8px; padding: 8px; background: #fff; }
.filter-actions { display: flex; gap: 10px; }
.filter-actions .secondary-link { min-height: 46px; }
.record-list { display: grid; border-top: 1px solid #e5e7eb; }
.record-row { display: flex; align-items: center; gap: 12px; padding: 14px 2px; border-bottom: 1px solid #e5e7eb; color: #374151; }
.record-row-main { display: grid; flex: 1; grid-template-columns: 1fr auto; gap: 6px 12px; color: inherit; text-decoration: none; }
.record-check { display: grid; flex: 0 0 44px; height: 44px; place-items: center; border: 1px solid #9ca3af; border-radius: 8px; font-size: 1.5rem; text-decoration: none; color: #374151; }
.record-check.done { color: #166534; background: #dcfce7; }
.record-row strong { overflow-wrap: anywhere; }
.record-row-main > span:first-child { color: #6b7280; font-size: .85rem; }
.record-row-main > span:last-child { grid-column: 1 / -1; display: flex; gap: 6px; }
.status-badge, .combined-badge { width: max-content; border-radius: 999px; padding: 3px 8px; background: #fef3c7; font-size: .75rem; font-weight: 700; }
.status-badge.accrued { background: #dcfce7; color: #166534; }
.combined-badge { background: #e0e7ff; color: #3730a3; }
.load-more { justify-self: center; margin-top: 6px; }
.empty-records { padding: 28px 0; text-align: center; color: #6b7280; }
.record-detail { display: grid; grid-template-columns: minmax(110px, .8fr) 1.5fr; margin: 0; border-top: 1px solid #e5e7eb; }
.record-detail dt, .record-detail dd { margin: 0; padding: 12px 4px; border-bottom: 1px solid #e5e7eb; overflow-wrap: anywhere; }
.record-detail dt { color: #6b7280; font-weight: 700; }
@media (min-width: 640px) { .record-filters { padding: 14px; } .record-filters summary { display: none; } .record-filters form { padding: 0; grid-template-columns: 1fr 1fr; } .filter-actions { align-items: end; } }
@media (min-width: 390px) and (max-width: 639px) {
  .record-rate-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .record-rate-settings > [data-rate="amount_based"] { grid-column: 1 / -1; }
}
@media (max-width: 359px) {
  .screen-header { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 4px; }
  .screen-header h1 { font-size: 1.1rem; }
}
.secondary-link {
  display: inline-flex; min-height: 46px; align-items: center; justify-content: center;
  border: 1px solid #9ca3af; border-radius: 8px; padding: 10px 18px;
  color: #374151; background: #fff; font-weight: 700; text-decoration: none;
}
.add-record-button {
  position: fixed; right: max(20px, calc((100vw - 640px) / 2 + 24px)); bottom: 24px;
  display: grid; width: 56px; height: 56px; place-items: center;
  border-radius: 50%; color: #fff; background: #b91c1c;
  box-shadow: 0 6px 18px rgb(0 0 0 / 22%);
  font-size: 2rem; line-height: 1; text-decoration: none;
}

.admin-section { display: grid; gap: 12px; margin-top: 8px; }
.admin-section h2 { margin: 0; font-size: 1.15rem; }
.admin-section form { justify-self: start; }
.admin-users { list-style: none; margin: 0; padding: 0; }
.admin-users li {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid #e5e7eb; padding: 12px 0; overflow-wrap: anywhere;
}
.admin-badge { color: #991b1b; font-weight: 700; }

.icon-button:focus-visible, .add-record-button:focus-visible, .back-link:focus-visible,
.primary-link:focus-visible, .secondary-link:focus-visible, .text-button:focus-visible,
.danger-button:focus-visible, .submit-button:focus-visible, .user-menu a:focus-visible,
.user-menu button:focus-visible { outline: 3px solid #fecaca; outline-offset: 2px; }

@media (min-width: 640px) {
  .app-container { max-width: 640px; padding: 32px 24px; }
  .login-screen h1 span { display: inline; }
}
