/* 共通ボタン */
.btn {
    display: inline-block;
    padding: 8px 16px;
    background: #007cba;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}
.btn:hover { background: #005a8b; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: #dc3545; }
.btn-danger:hover { background: #c82333; }

/* メッセージ */
.message {
    padding: 12px;
    margin-bottom: 16px;
    border-radius: 4px;
    border: 1px solid;
}
.message.success { background: #d4edda; border-color: #c3e6cb; color: #155724; }
.message.error { background: #f8d7da; border-color: #f5c6cb; color: #721c24; }

/* ログイン画面 */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-box {
    background: white;
    padding: 32px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 360px;
}
.login-box h1 { margin-bottom: 24px; font-size: 24px; }
.login-box label { display: block; margin-bottom: 8px; font-weight: 500; }
.login-box input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; margin-bottom: 16px; }
.login-box button { width: 100%; padding: 12px; }

/* 管理画面レイアウト */
.admin-layout { 
    min-height: 100vh; 
    height: 100vh;
    display: flex; 
    flex-direction: column;
    overflow: hidden;
}
.admin-header {
    background: white;
    border-bottom: 1px solid #ddd;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.admin-header h1 { font-size: 20px; }
.header-actions { display: flex; gap: 8px; }
.admin-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 24px;
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    min-height: 0;
}

/* フォームセクション */
.form-section, .list-section {
    background: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.form-section h2, .list-section h2 { margin-bottom: 20px; font-size: 18px; }
.list-section { padding: 16px; }
.list-section h2 { margin-bottom: 12px; font-size: 16px; }

/* フィルターボックス */
.filter-box {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.filter-box input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}
.filter-box input:focus {
    outline: none;
    border-color: #007cba;
}
#filter-count {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
}

.pin-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}
.required { color: #dc3545; }
.pin-form input, .pin-form textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 16px;
}
.pin-form textarea { resize: vertical; }
.pin-form select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* 座標入力セクション */
.coord-inputs-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    margin-bottom: 16px;
    align-items: end;
}
.coord-input-group { display: flex; flex-direction: column; }
.coord-input-group label { margin-bottom: 6px; }
.coord-input-group input { margin-bottom: 0; }

.map-picker-large { margin-bottom: 16px; }
.map-picker-large label { display: block; margin-bottom: 8px; font-weight: 500; font-size: 14px; }
#admin-map { 
    height: 400px; 
    border: 1px solid #ddd; 
    border-radius: 4px;
}

.preview-img { max-width: 150px; height: auto; margin-top: 8px; border-radius: 4px; display: block; }
#image-preview { margin-top: 8px; }
#image-preview small { display: block; margin-top: 4px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; }

/* Facebook埋め込みセクション */
.facebook-section { margin-bottom: 16px; }
.facebook-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.facebook-input-row input {
    flex: 1;
    margin-bottom: 0;
}
.facebook-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.facebook-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
}
.facebook-url {
    flex: 1;
    color: #007cba;
    cursor: pointer;
    word-break: break-all;
    font-size: 11px;
    line-height: 1.3;
}
.facebook-url:hover { text-decoration: underline; }
.facebook-item .btn-sm { flex-shrink: 0; }

.facebook-reorder {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.btn-reorder {
    padding: 0 4px;
    background: #eee;
    border: 1px solid #ccc;
    border-radius: 2px;
    cursor: pointer;
    font-size: 8px;
    line-height: 1;
    color: #666;
}
.btn-reorder:hover {
    background: #ddd;
    color: #333;
}

/* Facebookプレビューモーダル */
.fb-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}
.fb-modal.active { display: flex; }
.fb-modal-content {
    background: white;
    border-radius: 8px;
    padding-top: 50px;
    position: relative;
    max-width: 560px;
    max-height: 90vh;
    overflow: auto;
}
.fb-modal-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: #333;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 1;
}
.fb-modal-close:hover { background: #555; }
#fb-modal-body {
    width: 350px;
    min-height: 400px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}
#fb-modal-body iframe { display: block; }

/* ピン一覧テーブル（管理画面） */
.pins-table { display: flex; flex-direction: column; gap: 4px; }
.pin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
}
.pin-info { flex: 1; min-width: 0; }
.pin-info strong { 
    display: block; 
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pin-info small {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 2px;
}
.pin-actions { display: flex; gap: 4px; flex-shrink: 0; }
.empty-message { padding: 20px; text-align: center; color: #999; font-size: 13px; }

/* ============================
   フロント表示
   ============================ */
.container { 
    max-width: 1800px; 
    margin: 0 auto; 
    padding: 16px;
}

.main-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 地図エリア */
.map-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.map-area { 
    background: white; 
    border-radius: 8px; 
    overflow: hidden; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    min-height: 700px;
}
#map { width: 100%; height: 100%; min-height: 700px; z-index: 10; }

/* Facebook埋め込みエリア */
.facebook-container {
    display: none;
    gap: 5px;
    overflow-x: auto;
    margin: 0 -16px;
    padding: 16px;
    justify-content: safe center;
}
.facebook-embed {
    flex: 0 0 auto;
}
.facebook-embed iframe {
    height: 670px;
}

/* サイドバー（企業一覧） */
.sidebar {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}
.sidebar h2 {
    padding: 8px 12px;
    margin: 0;
    border-bottom: 1px solid #e0e0e0;
    font-size: 13px;
    background: #f8f8f8;
}
.pins-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
}

/* 都道府県グループ */
.prefecture-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
}
.prefecture-header {
    padding: 4px 8px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}

.prefecture-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 0 0 8px;
    align-items: center;
}

/* 企業アイテム */
.pin-item {
    padding: 3px 8px;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #ddd;
    transition: all 0.15s;
    background: #fafafa;
    white-space: nowrap;
}
.pin-item:hover { background: #e8f4fc; border-color: #007cba; }
.pin-item.active { background: #e3f2fd; border-color: #007cba; }
.pin-item-content { display: flex; align-items: center; gap: 4px; }
.pin-item-number {
    width: 16px;
    height: 16px;
    background: #007cba;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: bold;
    flex-shrink: 0;
}
.pin-item-name {
    font-weight: 500;
    font-size: 11px;
}

.loading { padding: 40px; text-align: center; color: #999; }

/* Leafletカスタムマーカー */
.custom-marker-container { background: transparent !important; border: none !important; }
.marker-pin {
    width: 28px;
    height: 28px;
    background: #007cba;
    border: 2px solid white;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.marker-pin:hover { background: #005a8b; }
.marker-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    color: white;
    font-weight: bold;
    font-size: 11px;
}

/* ポップアップスタイル */
.pin-popup { background: white !important; border-radius: 6px !important; }
.pin-popup .leaflet-popup-content { margin: 0 !important; padding: 0 !important; }
.popup-content { padding: 12px; font-size: 13px; }
.popup-content h3 { margin: 0 0 8px 0; font-size: 16px; color: #007cba; }
.popup-content p { margin: 0 0 8px 0; line-height: 1.5; color: #555; }
.popup-content p:last-child { margin-bottom: 0; }
.popup-content a { color: #007cba; text-decoration: none; }
.popup-content a:hover { text-decoration: underline; }
.popup-image { margin-bottom: 8px; }
.popup-image img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    max-width: 280px;
    display: block;
}

/* ============================
   レスポンシブ
   ============================ */
@media (max-width: 1200px) {
    .admin-content { grid-template-columns: 1fr; }
    .coord-inputs-row { grid-template-columns: 1fr; }
    .coord-input-group .btn { width: 100%; }
}

@media (max-width: 768px) {
    .admin-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .admin-content { padding: 16px; gap: 16px; }
    .pin-row { flex-wrap: wrap; }
}