/* ========== リセット・基本設定 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    background: #f5f5f5;
}

body {
    display: flex;
    flex-direction: column;
}

/* ========== ヘッダー ========== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #2E7D32;
    color: white;
    z-index: 1000;
    flex-shrink: 0;
}

.header-title {
    font-size: 1.2rem;
    font-weight: 600;
}

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

/* ========== ボタン ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: #2E7D32;
    color: white;
}

.btn-primary:hover {
    background: #1B5E20;
}

.btn-secondary {
    background: #757575;
    color: white;
}

.btn-secondary:hover {
    background: #616161;
}

.btn-danger {
    background: #D32F2F;
    color: white;
}

.btn-danger:hover {
    background: #B71C1C;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
}

/* ========== モード切替 ========== */
.mode-switcher {
    display: flex;
    background: white;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
}

.mode-btn {
    flex: 1;
    padding: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    color: #2E7D32;
    border-bottom-color: #2E7D32;
    background: #E8F5E9;
}

.mode-btn:hover:not(.active) {
    background: #f5f5f5;
}

/* ========== レイヤー選択 ========== */
.layer-selector {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background: #E8F5E9;
    border-bottom: 1px solid #C8E6C9;
}

.layer-selector select {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
}

.layer-selector .btn {
    flex-shrink: 0;
}

/* ========== 地図 ========== */
#map {
    flex: 1;
    z-index: 1;
}

/* ========== 現在地ボタン ========== */
.locate-btn {
    position: fixed;
    bottom: 80px;
    right: 15px;
    width: 50px;
    height: 50px;
    background: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2E7D32;
}

.locate-btn:hover {
    background: #f5f5f5;
}

.locate-btn:active {
    background: #e8e8e8;
}

/* ========== 追跡ボタン ========== */
.track-btn {
    position: fixed;
    bottom: 140px;
    right: 15px;
    width: 50px;
    height: 50px;
    background: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2196F3;
}

.track-btn:hover {
    background: #f5f5f5;
}

.track-btn:active {
    background: #e8e8e8;
}

.track-btn.active {
    background: #2196F3;
    color: white;
}

.current-location-marker {
    background: transparent !important;
    border: none !important;
}

/* ========== ステータスバー ========== */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #333;
    color: white;
    font-size: 0.85rem;
    flex-shrink: 0;
}

#coord-display {
    font-family: monospace;
    font-size: 0.8rem;
}

/* ========== モーダル ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: flex-end;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.modal-small {
    max-width: 400px;
    border-radius: 16px;
    margin-bottom: 20%;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #2E7D32;
    color: white;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
}

/* ========== フォーム ========== */
#tree-form {
    padding: 20px;
    overflow-y: auto;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fafafa;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2E7D32;
    background: white;
}

.form-group .required {
    color: #D32F2F;
}

.coord-display {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 8px;
}

.coord-display label {
    margin-bottom: 4px;
}

#form-coord-display {
    font-family: monospace;
    font-size: 0.9rem;
    color: #666;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.form-actions .btn {
    flex: 1;
}

#form-delete {
    flex: 0.5;
}

/* ========== ポップアップ ========== */
.tree-popup {
    min-width: 180px;
}

.popup-header {
    font-size: 1.1rem;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.popup-row {
    display: flex;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.popup-row .label {
    color: #666;
    margin-right: 8px;
    min-width: 50px;
}

/* ========== カスタムマーカー ========== */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

/* ========== 管理画面 ========== */
.admin-body {
    background: #f5f5f5;
}

.admin-main {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
}

.admin-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.admin-section h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    color: #2E7D32;
}

.admin-section h3 {
    font-size: 1rem;
    margin: 20px 0 10px;
    color: #666;
}

/* ファイルアップロード */
.upload-area {
    margin-bottom: 20px;
}

.file-input-wrapper {
    border: 2px dashed #ddd;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background: #fafafa;
}

.file-input-wrapper input[type="file"] {
    width: 100%;
}

.file-hint {
    font-size: 0.85rem;
    color: #666;
    margin-top: 8px;
}

/* レイヤーリスト */
.layer-list {
    margin-top: 20px;
}

.layer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 10px;
    background: #fafafa;
}

.layer-item .layer-name {
    font-weight: 500;
}

.layer-item .layer-actions {
    display: flex;
    gap: 8px;
}

.layer-item .btn {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* エクスポート */
#export-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

#export-form .form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.export-note {
    font-size: 0.85rem;
    color: #666;
    margin-top: 15px;
}

/* データテーブル */
.data-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.data-table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.data-table th {
    background: #f5f5f5;
    font-weight: 600;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: #fafafa;
}

.data-table .loading {
    text-align: center;
    color: #999;
    padding: 30px;
}

.data-table .btn {
    padding: 4px 8px;
    font-size: 0.8rem;
}

/* ========== ローディング ========== */
.loading {
    color: #999;
    font-style: italic;
}

/* ========== レスポンシブ ========== */
@media (min-width: 768px) {
    .modal-content {
        border-radius: 16px;
        margin: auto;
    }

    .admin-main {
        padding: 30px;
        max-width: 1200px;
        margin: 0 auto;
    }

    #export-form {
        flex-wrap: nowrap;
    }
}

/* ========== Leaflet カスタム ========== */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.leaflet-popup-content {
    margin: 12px 15px;
}
