/* ================================================
   ポスティングエリア表示アプリ スタイルシート
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary:    #1a1f2e;
  --surface:    #242a3e;
  --surface2:   #2e3650;
  --border:     #3d4768;
  --text:       #e8ecf4;
  --text-muted: #8a92a8;
  --accent:     #4f8ef7;

  --tier1: #ff4444;
  --tier2: #4466ff;
  --tier3: #22bb55;

  --panel-height-collapsed: 56px;
  --panel-height-peek:      200px;
  --panel-height-full:      70vh;
}

html, body {
  height: 100%;
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--primary);
  color: var(--text);
  overflow: hidden;
}

/* ──────────────────────────────────────────
   地図エリア
   ────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

#map * {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

/* ──────────────────────────────────────────
   ヘッダー
   ────────────────────────────────────────── */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(26,31,46,0.95) 0%, rgba(36,42,62,0.95) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

#header h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex: 1;
  background: linear-gradient(90deg, #fff 0%, #b0c4f8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* 現在地ボタン */
#btn-locate {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), #2563d4);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 2px 10px rgba(79,142,247,0.4);
  white-space: nowrap;
}
#btn-locate:active { transform: scale(0.95); opacity: 0.9; }
#btn-locate svg { width: 16px; height: 16px; flex-shrink: 0; }

/* 追跡中バッジ */
#tracking-badge {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(34,187,85,0.2);
  border: 1px solid var(--tier3);
  font-size: 11px;
  color: var(--tier3);
  font-weight: 600;
}
#tracking-badge.active { display: flex; }
#tracking-badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--tier3);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.3); }
}

/* ──────────────────────────────────────────
   スライドアップパネル
   ────────────────────────────────────────── */
#panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: linear-gradient(180deg, rgba(36,42,62,0.98) 0%, rgba(26,31,46,0.99) 100%);
  backdrop-filter: blur(16px);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 30px rgba(0,0,0,0.5);
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  height: var(--panel-height-collapsed);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#panel.peek { height: var(--panel-height-peek); }
#panel.full { height: var(--panel-height-full); }

/* ドラッグハンドル */
#panel-handle {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 6px;
  cursor: pointer;
  user-select: none;
}
#panel-handle .bar {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.2s;
}
#panel-handle:active .bar { background: var(--accent); }

#panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* パネルコンテンツ */
#panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 14px 20px;
  -webkit-overflow-scrolling: touch;
}
#panel-body::-webkit-scrollbar { display: none; }

/* ──────────────────────────────────────────
   商圏セクション
   ────────────────────────────────────────── */
.tier-section {
  margin-bottom: 16px;
}

.tier-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}
.tier-header:active { background: rgba(255,255,255,0.05); }

.tier-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}
.tier1 .tier-dot { background: var(--tier1); color: var(--tier1); }
.tier2 .tier-dot { background: var(--tier2); color: var(--tier2); }
.tier3 .tier-dot { background: var(--tier3); color: var(--tier3); }

.tier-label {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}
.tier1 .tier-label { color: #ff7777; }
.tier2 .tier-label { color: #7799ff; }
.tier3 .tier-label { color: #55dd88; }

.tier-count {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text-muted);
}

.tier-chevron {
  transition: transform 0.25s;
  color: var(--text-muted);
  font-size: 12px;
}
.tier-header.open .tier-chevron { transform: rotate(180deg); }

/* 商圏コンテンツ */
.tier-content {
  display: none;
  padding: 4px 4px 0;
}
.tier-content.open { display: block; }

/* エリアカード */
.area-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.area-card .card-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.area-type-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 8px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-muted);
  white-space: nowrap;
}

.area-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.area-radius {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-delete {
  width: 26px; height: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(255,80,80,0.15);
  color: #ff6666;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.btn-delete:active { background: rgba(255,80,80,0.35); }

/* 追加フォーム */
.add-form {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 4px;
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.form-row:last-child { margin-bottom: 0; }

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 9px 10px;
  background: var(--primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.input-group input:focus,
.input-group select:focus {
  border-color: var(--accent);
}
.input-group input::placeholder { color: var(--text-muted); }

.input-group.short { flex: 0 0 80px; }

select option { background: var(--surface); }

.btn-add-area {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}
.btn-add-area:active { transform: scale(0.98); opacity: 0.85; }

.tier1 .btn-add-area { background: linear-gradient(135deg, #c43333, #ff5555); color: #fff; }
.tier2 .btn-add-area { background: linear-gradient(135deg, #2244cc, #5577ff); color: #fff; }
.tier3 .btn-add-area { background: linear-gradient(135deg, #1a8840, #33cc66); color: #fff; }

/* 凡例 */
#legend {
  position: fixed;
  top: 64px;
  right: 12px;
  z-index: 100;
  background: rgba(36,42,62,0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
}
.legend-swatch {
  width: 18px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* トースト通知 */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 500;
  background: rgba(46,54,80,0.96);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
#toast.error { border-color: #ff4444; color: #ff7777; }
#toast.success { border-color: var(--tier3); color: #55dd88; }

/* ローディング */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ──────────────────────────────────────────
   デスクトップ対応
   ────────────────────────────────────────── */
@media (min-width: 768px) {
  #panel {
    top: 64px;
    left: auto;
    right: 0;
    bottom: 0;
    width: 360px;
    height: auto !important;
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-top: none;
  }
  #panel-handle { display: none; }
  #panel-body { overflow-y: auto; padding: 14px 16px 24px; }
  #legend { right: 376px; }
}
