:root {
  --bg: #eef3f1;
  --surface: #fff;
  --ink: #1a2b28;
  --muted: #5f736e;
  --border: #d3e0dc;
  --primary: #0d6e63;
  --primary-soft: #e3f3f0;
  --accent: #c47a2a;
  --ok: #2a6b45;
  --warn: #8a5a12;
  --danger: #b54a52;
  --shadow: 0 10px 28px rgba(20, 42, 40, 0.08);
  --font: "IBM Plex Sans JP", "DM Sans", sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgba(13, 110, 99, 0.1), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(196, 122, 42, 0.08), transparent 38%),
    linear-gradient(180deg, #f5f8f7, var(--bg));
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); font-size: 0.88rem; }

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: grid;
  gap: 14px;
}

.app-header {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
}
.brand {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kicker {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary);
}
.brand h1 {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 1.2rem + 1vw, 1.9rem);
  line-height: 1.2;
}
.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}
.header-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
}
.meta-card span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
}
.meta-card strong { font-size: 1rem; }
.meta-card.company-pick select {
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  width: 100%;
}

.note-banner {
  background: #fff8e8;
  border: 1px solid #ecd9a8;
  color: #6a4e16;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.schema-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.schema-chip {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(13, 110, 99, 0.18);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}
.schema-chip.soft {
  background: #fff;
  color: var(--muted);
  border-color: var(--border);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.35fr);
  gap: 14px;
  align-items: start;
}
.list-pane,
.detail-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 420px;
}
.list-pane[hidden],
.detail-pane[hidden] {
  display: none !important;
}
.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 520px;
}
.pane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 16px 0;
}
.pane-head h2 { margin: 0 0 4px; font-size: 1.1rem; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  background: #e8efed;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: #f8e8ea; color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
}

.list-tools {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 8px;
  padding: 12px 16px;
}
.list-tools.search-grid {
  grid-template-columns: 1fr;
}
@media (min-width: 901px) {
  .list-tools.search-grid {
    grid-template-columns: 1.6fr 1fr 1fr auto;
  }
  .list-tools.search-grid input[type="search"] {
    grid-column: 1 / -1;
  }
}
.page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.page-size select { min-width: 88px; }

.table-wrap {
  padding: 0 16px 8px;
  overflow: auto;
  max-height: min(68vh, 720px);
}
.empty-list { padding: 16px 0; }
.party-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.party-table th,
.party-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.party-table th {
  position: sticky;
  top: 0;
  background: #f4f8f7;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  z-index: 1;
}
.party-table .num { text-align: right; font-variant-numeric: tabular-nums; width: 4.5rem; }
.party-table .col-name { font-weight: 600; min-width: 8rem; }
.party-table .col-address {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.84rem;
  color: var(--muted);
}
.party-table .col-karte {
  min-width: 9rem;
  display: grid;
  gap: 2px;
  font-size: 0.82rem;
}
.party-table td.col-karte.has-karte {
  background: #fff9c4;
}
.karte-status {
  font-weight: 700;
  color: var(--muted);
}
.karte-status.is-on {
  color: var(--primary);
}
.visit-at {
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.tag-editor { display: grid; gap: 10px; }
.tag-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-toggle {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.tag-toggle.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.tag-custom-row {
  display: flex;
  gap: 8px;
}
.tag-custom-row input { flex: 1; }
.tiny-note { font-size: 0.78rem; margin: 0; }

.karte-callout {
  margin: 0 18px 14px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 2px solid rgba(13, 110, 99, 0.35);
  background: linear-gradient(135deg, #e7f6f3, #fff8ee);
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.karte-callout-kicker {
  margin: 0 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.karte-callout strong {
  display: block;
  font-size: 1.08rem;
  margin-bottom: 4px;
}
.karte-callout p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.karte-callout-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.karte-inline-hint {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff4e5;
  border: 1px solid #ecd9a8;
  color: #6a4e16;
  font-size: 0.88rem;
  font-weight: 600;
}
.field-actions { margin: 12px 0 18px; }
.mini-card.karte-card {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-color: rgba(13, 110, 99, 0.28);
  background: linear-gradient(90deg, #f4fbf9, #fff);
}
.mini-card-main { display: grid; gap: 6px; text-align: left; }
.mini-card-cta {
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.party-photo-overview {
  padding-top: 0;
}
.party-photo-overview .photo-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.photo-visit-link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.78rem;
  color: var(--primary);
  cursor: pointer;
  text-align: left;
  line-height: 1.35;
}
.photo-visit-link:hover { text-decoration: underline; }

.photo-hero-wrap {
  padding-top: 4px;
  padding-bottom: 4px;
}
.photo-block.is-hero {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f4f8f7;
  border: 1px solid var(--border);
}
.photo-block.is-hero .photo-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.photo-block.is-hero .photo-thumb img {
  height: 140px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-card {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fbfcfc;
}
.photo-thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: #e8efed;
  cursor: pointer;
}
.photo-thumb img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
}
.photo-card figcaption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 8px;
  font-size: 0.75rem;
}
.photo-card figcaption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.photo-preview img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px;
  background: #eef2f1;
}
.party-row {
  cursor: pointer;
  transition: background 0.12s ease;
}
.party-row:hover,
.party-row:focus {
  background: var(--primary-soft);
  outline: none;
}
.party-row:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(13, 110, 99, 0.35);
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px 16px;
  border-top: 1px solid var(--border);
}
.pager-info {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.pager-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-weight: 600;
  font-size: 0.85rem;
}
.page-btn.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.detail-topbar {
  padding: 14px 18px 0;
}
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2f1;
  color: var(--muted);
}
.detail-kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--primary);
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.section-head h3,
.detail-section > h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}
.section-head h3 { margin: 0; }
.mini-list {
  display: grid;
  gap: 8px;
}
.mini-card {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fbfcfc;
  display: grid;
  gap: 6px;
}
.mini-card:hover { border-color: rgba(13, 110, 99, 0.35); }
.breadcrumb { padding: 0 18px 4px; }
.btn.tiny {
  padding: 4px 10px;
  font-size: 0.8rem;
}
.party-profile { padding: 0 18px 8px; }
.list-tools input,
.list-tools select,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}
.field textarea { min-height: 88px; resize: vertical; }

.record-list {
  display: grid;
  gap: 8px;
  padding: 0 16px 16px;
  max-height: 640px;
  overflow: auto;
}
.record-card {
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fbfcfc;
  display: grid;
  gap: 6px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.record-card:hover { border-color: rgba(13, 110, 99, 0.35); }
.record-card.is-on {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}
.record-card strong { font-size: 0.98rem; }
.record-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2f1;
}
.badge.active { background: #e3f5ea; color: var(--ok); }
.badge.paused { background: #fff3df; color: var(--warn); }
.badge.closed { background: #f1e8e8; color: var(--danger); }

.detail-pane { padding: 0 0 16px; }
.empty-detail {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}
.detail-head {
  padding: 16px 18px 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.detail-head h2 { margin: 0 0 6px; font-size: 1.25rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 18px 12px;
}
.tab-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.85rem;
}
.tab-btn.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.detail-section { padding: 0 18px 8px; }
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field.full { grid-column: 1 / -1; }
.field label {
  display: grid;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.field .value {
  color: var(--ink);
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.party-box {
  margin: 0 18px 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f4f8f7;
  border: 1px solid var(--border);
  display: grid;
  gap: 4px;
}
.party-box strong { font-size: 1rem; }

.timeline {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}
.timeline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.timeline li {
  border-left: 3px solid rgba(13, 110, 99, 0.35);
  padding: 8px 0 8px 14px;
  display: grid;
  gap: 4px;
}
.timeline .when {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}
.timeline .etype {
  display: inline-block;
  margin-right: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}
.timeline p { margin: 0; line-height: 1.5; font-size: 0.92rem; }

.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 22, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  max-height: min(90vh, 760px);
  overflow: auto;
}
.modal-head, .modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}
.modal-head { border-bottom: 1px solid var(--border); }
.modal-foot { border-top: 1px solid var(--border); }
.modal-body { padding: 16px; display: grid; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }

@media (max-width: 900px) {
  .app-header, .workspace, .field-grid, .list-tools {
    grid-template-columns: 1fr;
  }
  .pane, .list-pane, .detail-pane { min-height: 0; }
  .party-table .col-address { max-width: 8rem; }
}
