:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --line: #dfe5ec;
  --text: #1d2733;
  --muted: #657386;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --warn: #b45309;
  --tag-bg: #e8f1ff;
  --tag-text: #174ea6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 58px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  color: var(--text);
  font-weight: 800;
}

.nav {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 12px;
}

.nav a {
  color: var(--muted);
  font-weight: 650;
}

.logout-form {
  margin-left: auto;
}

.inline-form {
  margin: 0;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.page-head,
.section-head,
.actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-head {
  justify-content: space-between;
  margin-bottom: 20px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 28px;
}

h2 {
  margin-bottom: 12px;
  font-size: 18px;
}

p {
  margin: 6px 0 0;
}

.page-head p,
.empty,
.muted {
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat,
.panel,
.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(20, 33, 48, 0.05);
}

.stat {
  padding: 18px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.stat.warn strong {
  color: var(--warn);
}

.section {
  margin-top: 26px;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

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

th {
  background: var(--surface-soft);
  color: #405064;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.needs-check td:first-child {
  border-left: 4px solid var(--warn);
}

.memo-cell {
  max-width: 300px;
  color: var(--muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 12px;
  font-weight: 750;
}

.toolbar {
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.toolbar input[type="search"] {
  flex: 1 1 280px;
}

.toolbar input[type="text"],
.toolbar select {
  flex: 0 1 180px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cfd8e3;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

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

.check input {
  width: auto;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 750;
}

button:hover,
.button:hover {
  text-decoration: none;
  background: #f8fafc;
}

.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.compact-button {
  min-height: 32px;
  padding: 5px 10px;
  white-space: nowrap;
  font-size: 13px;
}

.danger {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--danger);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr) minmax(300px, 0.8fr);
  gap: 16px;
}

.panel,
.auth-panel {
  padding: 18px;
}

.narrow,
.auth-panel {
  max-width: 680px;
}

.auth-panel {
  margin: 80px auto 0;
}

.form p,
.form label {
  display: block;
  margin: 0 0 14px;
  font-weight: 700;
}

.form .helptext {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.form-note {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
}

.form ul.errorlist {
  margin: 0 0 6px;
  padding-left: 18px;
  color: var(--danger);
}

.meta {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  margin: 0 0 20px;
}

.meta dt {
  color: var(--muted);
  font-weight: 800;
}

.meta dd {
  margin: 0;
}

.note {
  white-space: normal;
}

.month-label {
  margin: -4px 0 14px;
  color: var(--muted);
  font-weight: 800;
}

.benefit-form input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.done {
  background: #e7f7ee;
  color: #137047;
}

.status.pending {
  background: #fff7ed;
  color: #b45309;
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.timeline time {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.messages {
  margin-bottom: 16px;
}

.message {
  padding: 10px 12px;
  border-radius: 8px;
  background: #e8f1ff;
}

.message.warning {
  background: #fff7ed;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }

  .logout-form {
    margin-left: 0;
  }

  .page-head,
  .detail-grid {
    display: block;
  }

  .page-head .button,
  .page-head .actions {
    margin-top: 12px;
  }

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

  .panel + .panel {
    margin-top: 14px;
  }

  .toolbar > * {
    flex: 1 1 100%;
  }
}
