:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #1d252b;
  --muted: #64717b;
  --line: #d9e0e4;
  --line-strong: #b7c3ca;
  --primary: #176c72;
  --primary-dark: #0e5257;
  --soft: #edf2f4;
  --warn: #875118;
  --danger: #b23b3b;
  --ok: #23744d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }

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

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

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

input[readonly] { background: #f8fafb; color: var(--muted); }

.amount-input {
  text-align: right;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  background: #172329;
  color: #e7eef0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.brand span {
  display: block;
  color: #a9b8bf;
  font-size: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.nav {
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav a {
  min-height: 38px;
  display: flex;
  align-items: center;
  border-radius: 7px;
  padding: 8px 10px;
  color: #d9e4e8;
}

.nav a:hover { background: #223139; }

.logout-form {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.login-user { color: #b5c2c8; font-size: 12px; margin-bottom: 10px; }

.main { padding: 24px; min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1 { margin: 0 0 5px; font-size: 24px; }
h2 { margin: 0 0 14px; font-size: 16px; }
p { margin: 0; }

.lead, .hint { color: var(--muted); }
.hint { font-size: 12px; }

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

.section-head h2 { margin: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 4px; font-size: 26px; }

.backup-summary {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.backup-summary > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
  padding: 12px;
}

.backup-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.backup-summary strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.backup-note {
  margin-bottom: 12px;
}

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

.field { display: grid; gap: 6px; }
.field.full, .actions.full { grid-column: 1 / -1; }

.section-split {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 16px;
}

.section-split h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

label { font-weight: 700; }

.aligned-form {
  gap: 12px 18px;
  align-items: start;
}

.aligned-form .field:not(.full) {
  grid-template-rows: 22px 40px;
  gap: 6px;
}

.aligned-form .field:not(.full) > label:first-child {
  min-height: 22px;
  display: flex;
  align-items: end;
}

.aligned-form .field:not(.full) > input:not([type="checkbox"]),
.aligned-form .field:not(.full) > select {
  height: 40px;
  min-height: 40px;
}

.label-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-size: 11px;
  font-weight: 800;
  cursor: help;
}

.tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 280px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #1d252b;
  color: #fff;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 20;
}

.tip:hover::after,
.tip:focus::after {
  opacity: 1;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.check-row input, .check-field input {
  width: auto;
  min-height: auto;
  height: 16px;
}

.contract-app-unlock {
  margin-bottom: 10px;
}

.contract-app-checks {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}

.contract-app-checks.is-locked {
  pointer-events: none;
  border-color: var(--line);
  background: #f8fafb;
  opacity: .72;
}

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

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

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

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

.btn.danger {
  border-color: #e5b9b9;
  background: #fff;
  color: var(--danger);
}

.btn.danger:hover {
  background: #fff0f0;
}

.btn.compact {
  min-height: 32px;
  padding: 5px 10px;
}

.text-link {
  color: var(--primary);
  font-weight: 700;
}

.text-link:hover { text-decoration: underline; }

.strong { font-weight: 800; }

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

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  background: #f9fbfc;
  color: #42505a;
  font-size: 12px;
}

.list-table tbody tr:hover td { background: #f9fcfd; }

.table-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.editable-member-table th,
.editable-member-table td {
  vertical-align: middle;
}

.editable-member-table input {
  height: 38px;
  min-height: 38px;
  min-width: 180px;
}

.editable-member-table td:nth-child(3) input {
  min-width: 160px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  padding: 26px 12px;
}

.badge-row, .api-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seat-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--soft);
  color: #3a464e;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  border-color: #b8dcc9;
  background: #eaf7ef;
  color: var(--ok);
}

.badge.warn {
  border-color: #ead2ad;
  background: #fff6e8;
  color: var(--warn);
}

.badge.danger {
  border-color: #e5b9b9;
  background: #fff0f0;
  color: var(--danger);
}

.inline-check {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  padding: 6px 10px;
}

.inline-check input {
  width: 16px;
  height: 16px;
  min-height: auto;
}

.aligned-form .inline-check {
  min-height: 40px;
  height: 40px;
  margin: 0;
}

.note,
.payment-rule,
.limit-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfc;
  color: #40505a;
  padding: 12px;
  margin-bottom: 14px;
}

.limit-note {
  border-color: #e5b9b9;
  border-left: 4px solid var(--danger);
  background: #fff0f0;
  color: #743131;
}

.payment-rule {
  display: grid;
  gap: 4px;
  border-left: 4px solid var(--primary);
}

.payment-add-form {
  margin-bottom: 18px;
}

.payment-calendar-panel {
  overflow: visible;
}

.year-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
}

.payment-calendar-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.calendar-lock-row {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr);
  align-items: center;
  gap: 12px;
}

.calendar-reason:disabled {
  background: #f2f5f6;
}

.payment-month-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(78px, 1fr));
  gap: 8px;
}

.payment-month {
  min-height: 92px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.payment-month.paid {
  border-color: #9bc6b4;
  background: #eef8f3;
  color: var(--ok);
}

.payment-month input {
  width: 18px;
  height: 18px;
  min-height: auto;
  padding: 0;
}

.payment-month input:disabled {
  opacity: .65;
}

.payment-month small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.payment-history-details {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.payment-history-details summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 800;
}

.payment-history-details[open] summary {
  margin-bottom: 14px;
}

.mono, code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

code {
  display: inline-block;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfc;
}

.flash {
  border-left: 4px solid var(--primary);
  background: #eef7f8;
  color: #294b4f;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.security-warning {
  border: 1px solid #ead2ad;
  border-left: 4px solid var(--warn);
  background: #fff8ec;
  color: #4f3820;
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.security-warning strong {
  display: block;
  margin-bottom: 4px;
}

.security-warning p + p {
  margin-top: 4px;
}

.timeline { display: grid; gap: 0; }

.timeline-item {
  display: grid;
  grid-template-columns: 210px 170px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

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

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.login-brand {
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: block; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .backup-summary { grid-template-columns: 1fr; }
  .payment-month-grid { grid-template-columns: repeat(3, minmax(80px, 1fr)); }
  .calendar-lock-row { grid-template-columns: 1fr; }
  .page-head { display: grid; }
  .timeline-item { grid-template-columns: 1fr; }
}
