/* =============================================
   長崎中小企業家同友会 島原支部 企業マップ
   style.css
   ============================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #1a6b3a;
  --color-primary-light: #e8f4ee;
  --color-primary-mid: #2e8b57;
  --color-accent: #e8622a;
  --color-accent-light: #fff0ea;
  --color-text: #1a1a1a;
  --color-text-sub: #555;
  --color-text-muted: #888;
  --color-border: #ddd;
  --color-bg: #f5f5f2;
  --color-white: #ffffff;
  --header-height: 56px;
  --sidebar-width: 320px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
}

html, body {
  height: 100%;
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Header ---- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--color-primary);
  z-index: 1000;
  box-shadow: var(--shadow);
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-title {
  display: flex;
  flex-direction: column;
}

.header-org {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
}

.header-sub {
  font-size: 10px;
  color: rgba(255,255,255,0.75);
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  padding: 6px 16px;
  border: 1.5px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  background: transparent;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.nav-link { text-decoration: none; }

button { touch-action: manipulation; }

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-color: rgba(255,255,255,0.7);
}

/* ---- Main ---- */
.main {
  padding-top: var(--header-height);
  height: 100vh;
  height: 100dvh; /* モバイルのアドレスバー対策 */
}

.view {
  display: none;
  height: 100%;
}

.view.active {
  display: flex;
}

/* ---- Map Layout ---- */
.map-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-bar {
  padding: 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-white);
}

.search-bar input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--color-primary);
}

.filter-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-tag {
  padding: 3px 10px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--color-white);
  color: var(--color-text-sub);
}

.filter-tag:hover,
.filter-tag.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.company-list {
  flex: 1;
  overflow-y: auto;
}

.company-list-item {
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.company-list-item:hover {
  background: var(--color-primary-light);
}

.company-list-item.selected {
  background: var(--color-primary-light);
  border-left: 3px solid var(--color-primary);
}

.company-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.company-list-info {
  flex: 1;
  min-width: 0;
}

.company-list-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-list-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.env-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.env-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  background: var(--color-accent-light);
  color: var(--color-accent);
  border: 1px solid rgba(232,98,42,0.2);
  white-space: nowrap;
}

.sidebar-count {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-white);
}

/* ---- Map Container ---- */
.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* ---- Company Detail Panel ---- */
.company-detail {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  max-height: 55%;
  overflow-y: auto;
  z-index: 500;
  transition: transform 0.3s ease;
  border-radius: var(--radius) var(--radius) 0 0;
}

.company-detail.hidden {
  transform: translateY(100%);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #f0f0f0;
  position: sticky;
  top: 0;
  background: var(--color-white);
  z-index: 1;
}

.detail-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
}

.detail-industry {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 3px;
}

.close-btn {
  background: #f0f0f0;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 12px;
  color: var(--color-text-sub);
}

.close-btn:hover {
  background: #e0e0e0;
}

.detail-body {
  padding: 16px 20px;
}

.detail-info-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  align-items: flex-start;
}

.detail-info-label {
  color: var(--color-text-muted);
  min-width: 52px;
  flex-shrink: 0;
}

.detail-info-value {
  color: var(--color-text);
}

.detail-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  margin: 16px 0 10px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--color-primary-light);
  display: flex;
  align-items: center;
  gap: 4px;
}

.env-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.env-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.env-card-label {
  flex: 1;
}

.env-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.env-card-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.apply-btn {
  padding: 8px 16px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background 0.2s;
}

.apply-btn:hover {
  background: #c9501f;
}

/* ---- List View ---- */
#view-list {
  flex-direction: column;
  background: var(--color-bg);
  overflow-y: auto;
}

.list-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
}

.list-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.list-header input {
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 220px;
}

.list-header input:focus {
  border-color: var(--color-primary);
}

.full-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.full-list-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.full-list-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--color-primary);
}

.full-list-card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.full-list-card-industry {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.full-list-card-address {
  font-size: 11px;
  color: var(--color-text-sub);
  margin-bottom: 8px;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-content {
  position: relative;
  background: var(--color-white);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #f0f0f0;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-sub);
}

.modal-close:hover {
  background: #e0e0e0;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.modal-subtitle strong {
  color: var(--color-primary);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
}

.required {
  color: var(--color-accent);
  margin-left: 2px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  color: var(--color-text);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,107,58,0.1);
}

.form-group input:user-invalid,
.form-group textarea:user-invalid {
  border-color: #d33a2c;
}

.form-group textarea {
  resize: vertical;
}

.form-actions {
  margin-top: 20px;
}

.submit-btn {
  width: 100%;
  padding: 12px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}

.submit-btn:hover {
  background: var(--color-primary-mid);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---- Success Screen ---- */
.form-success {
  text-align: center;
  padding: 20px 0;
}

.form-success.hidden {
  display: none;
}

.success-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.form-success h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text);
}

.form-success p {
  font-size: 13px;
  color: var(--color-text-sub);
  margin-bottom: 20px;
}

/* ---- Loading ---- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  font-size: 13px;
  gap: 8px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Leaflet Overrides ---- */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.map-marker-label {
  background: var(--color-primary);
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  font-family: 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ---- Responsive ---- */
@media (max-width: 640px) {

  /* ヘッダー: 組織名は省略表示し、ナビは潰さない */
  .header-inner { padding: 0 12px; gap: 8px; }
  .header-title { min-width: 0; }
  .header-org {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-sub { display: none; }
  .header-nav { flex-shrink: 0; }
  .nav-btn { padding: 7px 12px; font-size: 12px; }

  /* マップビュー: 検索＋リスト（上45%）／マップ（下55%）の縦並び */
  #view-map.active { display: block; }
  .map-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: 45%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .map-container { height: 55%; }

  /* 詳細パネル: マップ枠内だと狭すぎるため画面下部に固定 */
  .company-detail {
    position: fixed;
    max-height: 70dvh;
    z-index: 900;
    box-shadow: 0 -6px 24px rgba(0,0,0,0.18);
  }
  .detail-header { padding: 14px 16px 10px; }
  .detail-body { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
  .close-btn { width: 36px; height: 36px; font-size: 16px; }

  /* 提供環境カード: 幅が足りないときは申請ボタンを下段に折り返す */
  .env-card { flex-wrap: wrap; padding: 12px; }
  .env-card-label { flex: 1 1 170px; }
  .apply-btn { flex: 1 1 auto; padding: 10px 16px; }

  /* 一覧ビュー: 見出しと検索欄を縦積みに */
  .list-container { padding: 16px 14px 32px; }
  .list-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }
  .list-header input { width: 100%; }

  /* 申請モーダル: ボトムシート化 */
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    max-width: none;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  }
  .modal-close { width: 36px; height: 36px; }

  /* iOS Safariのフォーカス時自動ズーム防止（入力欄は16px以上にする） */
  .search-bar input,
  .list-header input,
  .form-group input,
  .form-group textarea,
  .form-group select { font-size: 16px; }
}

@media (max-width: 400px) {
  .header-org { font-size: 11px; }
  .nav-btn { padding: 6px 9px; font-size: 11px; }
}
