:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #17201a;
  --muted: #66736a;
  --line: #dce3dd;
  --brand: #166534;
  --brand-dark: #124b29;
  --accent: #0f766e;
  --danger: #b42318;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--brand);
  color: white;
  font-weight: 650;
}

button:active {
  transform: translateY(1px);
}

.ghost {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.shell {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.auth-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  width: min(520px, 100%);
  margin-bottom: 18px;
}

.brand-logo {
  display: block;
  width: 112px;
  max-width: 34vw;
  height: auto;
  flex: 0 0 auto;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  font-size: 24px;
  font-weight: 800;
}

.brand h1,
.topbar h1 {
  margin: 0;
}

.brand p,
.eyebrow,
.detail-empty p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel,
.list-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
  font-size: 16px;
}

textarea {
  resize: vertical;
}

.message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
}

.app-view {
  padding: 18px;
}

.topbar,
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto 14px;
  max-width: 1180px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar .brand-logo,
.topbar .brand-mark {
  flex: 0 0 auto;
}

.topbar .brand-logo {
  width: 118px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.eyebrow {
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0;
  color: var(--accent);
}

.profile-badge {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.storage-warning {
  color: #a15c00;
  font-weight: 750;
}

.storage-danger {
  color: var(--danger);
  font-weight: 800;
}

.toolbar input {
  flex: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 14px;
  max-width: 1180px;
  margin: 0 auto;
}

.list-panel,
.detail-panel {
  min-height: 70vh;
  overflow: hidden;
}

.site-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.user-form {
  margin-bottom: 18px;
}

.user-list {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.user-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.user-row strong,
.user-row span {
  display: block;
}

.list-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

.list-head h2 {
  margin: 0;
  font-size: 18px;
}

.site-card {
  width: 100%;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
  color: var(--ink);
  text-align: left;
}

.site-card.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(22, 101, 52, 0.14);
}

.site-card strong {
  display: block;
  margin-bottom: 5px;
}

.site-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.site-card span b {
  display: inline-block;
  min-width: 58px;
  color: var(--ink);
  font-weight: 750;
}

.site-card-top {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 7px;
}

.site-card-top strong {
  margin-bottom: 0;
}

.site-code {
  display: inline-flex !important;
  flex: 0 0 auto;
  max-width: 46%;
  border: 1px solid #b8d8c2;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--brand-dark) !important;
  font-size: 12px !important;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.owner-card {
  min-height: 76px;
}

.owner-card .count {
  color: var(--accent);
  font-weight: 750;
}

.empty,
.detail-empty {
  padding: 24px;
}

.site-form,
.site-detail {
  padding: 18px;
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.form-head h2,
.site-detail h2 {
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.form-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 0;
  background: white;
}

.form-section summary {
  cursor: pointer;
  list-style: none;
  padding: 13px 14px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.form-section summary::-webkit-details-marker {
  display: none;
}

.form-section summary::after {
  content: "展開";
  float: right;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.form-section[open] summary {
  border-bottom: 1px solid var(--line);
}

.form-section[open] summary::after {
  content: "收合";
}

.form-section > .grid,
.form-section > .feature-grid,
.form-section > label,
.form-section > .attachment-section,
.form-section > .message {
  margin: 14px;
}

.form-section > .grid {
  margin-bottom: 14px;
}

.vehicle-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.vehicle-box legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
}

.check-row input {
  width: auto;
}

.vehicle-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.feature-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feature-pill {
  border: 1px solid #b8d8c2;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 750;
}

.span-2 {
  grid-column: span 2;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.info-item {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.info-item b {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.preline {
  white-space: pre-wrap;
}

.attachments {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.form-section.attachments {
  display: block;
}

.attachment-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.attachment-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.attachment-head h3 {
  margin: 0;
}

.file-input {
  max-width: 260px;
  font-size: 13px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.photo-grid a,
.file-list a {
  color: var(--brand-dark);
  font-weight: 650;
}

.photo-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.photo-item {
  display: grid;
  gap: 6px;
}

.file-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.icon-danger {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #fecaca;
  background: #fff5f5;
  color: var(--danger);
}

.subtle {
  color: var(--muted);
  font-size: 13px;
}

.mobile-action-bar {
  display: none;
}

@media (max-width: 820px) {
  .auth-view {
    align-content: start;
    padding: 32px 16px 18px;
  }

  .brand {
    gap: 10px;
    width: 100%;
    max-width: 420px;
  }

  .brand-logo {
    width: 88px;
    max-width: 28vw;
  }

  .brand h1 {
    font-size: 24px;
    line-height: 1.2;
  }

  .brand p {
    font-size: 13px;
    line-height: 1.4;
  }

  .panel {
    width: 100%;
    max-width: 420px;
    padding: 16px;
  }

  .app-view {
    padding: 12px 12px 92px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-brand {
    align-items: flex-start;
  }

  .topbar .brand-logo {
    width: 92px;
    max-width: 30vw;
  }

  .topbar h1 {
    font-size: 24px;
    line-height: 1.2;
  }

  .form-head {
    align-items: flex-start;
  }

  .form-head .form-actions {
    display: none;
  }

  .form-section {
    margin-bottom: 10px;
  }

  .form-section summary {
    padding: 12px;
  }

  .form-section > .grid,
  .form-section > .feature-grid,
  .form-section > label,
  .form-section > .attachment-section,
  .form-section > .message {
    margin: 12px;
  }

  .primary-submit {
    display: none;
  }

  .mobile-action-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(246, 247, 244, 0.96);
    box-shadow: 0 -8px 24px rgba(23, 32, 26, 0.12);
    overflow-x: auto;
  }

  .mobile-action-bar button {
    flex: 1 0 auto;
    min-width: 72px;
    min-height: 44px;
    padding: 0 12px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .site-list {
    gap: 10px;
    padding: 10px;
  }

  .site-card {
    min-height: 0;
    padding: 12px 13px;
  }

  .site-card-top {
    align-items: center;
  }

  .site-card-top strong {
    font-size: 16px;
  }

  .site-card span {
    font-size: 12px;
    line-height: 1.45;
  }

  .list-panel,
  .detail-panel {
    min-height: auto;
  }

  .grid,
  .info-grid,
  .vehicle-fields,
  .feature-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }
}
