/*
  Global design tokens (CSS variables).
  Centralized so we only change colors here instead of hunting through the file.
*/
:root {
  --bg-color: #f1f5f9;
  --card-bg: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --border: #cbd5e1;
  --input-bg: #f8fafc;
}

/*
  Reset: zero out browser defaults so layouts are predictable across browsers.
  box-sizing: border-box makes width/height include padding+border.
*/
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
}

/*
  Block layout (not flex). margin: 0 auto on .phone-mockup centers it
  predictably in both normal and preview-mobile modes.
*/
body {
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  padding: 20px;
}

.phone-mockup {
  max-width: 560px;
  margin: 0 auto;
}

.container {
  background-color: var(--card-bg);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
}

h2 {
  text-align: center;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-main);
}

.subtitle {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-main);
}

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

label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"], select {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--input-bg);
  color: var(--text-main);
  font-size: 1rem;
  transition: all 0.2s;
}

input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* IMEI split input (prefix + suffix) */
.imei-input-wrapper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--input-bg);
  overflow: hidden;
  transition: all 0.2s;
}

.imei-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.imei-prefix {
  padding: 12px 16px;
  background-color: #e2e8f0;
  color: var(--text-main);
  border-right: 1px solid var(--border);
  font-family: monospace;
  font-size: 1rem;
  user-select: none;
}

.imei-input-wrapper input {
  border: none;
  border-radius: 0;
  box-shadow: none;
  flex: 1;
  font-family: monospace;
  min-width: 0;
  background-color: var(--input-bg);
}

.imei-input-wrapper input:focus {
  box-shadow: none;
}

.hint-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: block;
}

/* Symptom checkboxes */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: var(--input-bg);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-main);
  font-size: 0.95rem;
}

.checkbox-label:hover {
  background-color: #f1f5f9;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-label.selected {
  border-color: var(--primary);
  background-color: rgba(37, 99, 235, 0.05);
}

.checkbox-label.error {
  border-color: var(--error);
  background-color: rgba(220, 38, 38, 0.05);
  animation: shake 0.4s;
}

.checkbox-error-msg {
  color: var(--error);
  font-size: 0.85rem;
  margin: 6px 0 0 4px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Buttons */
button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background-color: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

button:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: #f1f5f9;
  border: 1px solid var(--border);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #e2e8f0;
}

.btn-success {
  background-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background-color: #059669;
}

/* Speed test metric cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.metric-card {
  background-color: var(--input-bg);
  border-radius: 12px;
  padding: 16px 8px;
  text-align: center;
  border: 1px solid var(--border);
  transition: border-color 0.3s;
}

.metric-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.1);
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--primary);
  min-height: 28px;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.status-text {
  font-size: 0.85rem;
  text-align: center;
}

.status-text:not(:empty) {
  margin-top: 8px;
}

.text-error { color: var(--error); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.text-warning { color: var(--warning); }

/* Loading spinner inside buttons */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 1s ease-in-out infinite;
  display: none;
}

button .spinner {
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
}

.btn-secondary .spinner {
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: var(--text-main);
}

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

button.loading .spinner {
  display: inline-block;
}

.hidden { display: none !important; }

/* Modal overlays (privacy policy preview, floor picker) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 1000;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal h3 {
  font-size: 1.15rem;
  margin-bottom: 16px;
}

.modal section {
  margin-bottom: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-main);
}

.modal section h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--primary);
}

.modal ul {
  padding-left: 20px;
  color: var(--text-muted);
}

.modal ul li {
  margin-bottom: 4px;
}

/* Leaflet map */
#map {
  width: 100%;
  height: 280px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 8px;
  z-index: 1;
}

.map-info {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-main);
  min-height: 38px;
}

.map-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Floor selector */
#floorGroup {
  margin-top: -10px;
  margin-bottom: 20px;
  padding-left: 12px;
  border-left: 3px solid var(--primary);
}

.floor-trigger {
  width: 100%;
  padding: 14px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0;
}

.floor-trigger.has-value {
  color: var(--text-main);
  border-color: var(--primary);
}

.floor-trigger:hover {
  background: #f1f5f9;
}

.floor-trigger::after {
  content: '▼';
  font-size: 0.7rem;
  color: var(--text-muted);
}

.floor-picker-modal {
  max-width: 460px;
}

.floor-section {
  margin-bottom: 16px;
}

.floor-section-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}

.floor-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.floor-grid.special {
  grid-template-columns: repeat(3, 1fr);
}

.floor-btn {
  width: 100%;
  padding: 12px 4px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.9rem;
  margin: 0;
  cursor: pointer;
  transition: all 0.15s;
  display: block;
}

.floor-btn:hover {
  background: #e2e8f0;
  border-color: var(--primary);
}

.floor-btn.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.floor-modal-footer {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.floor-modal-footer button {
  flex: 1;
  margin-top: 0;
}

.speed-test-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}

.speed-test-note .note-caution {
  color: var(--text-warning, #b45309);
  font-style: normal;
  font-weight: 500;
}

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0 16px;
}

/*
  PHONE MOCKUP PREVIEW
  Activated by clicking the "📱 携帯表示" toggle button. Adds the
  .preview-mobile class on <body> which enables the styles below.
  Hidden on real mobile devices (no point showing a fake phone there).
*/
.phone-status-bar {
  display: none;
}

.preview-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  width: auto;
  padding: 10px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  transition: all 0.2s;
}

.preview-toggle:hover {
  background: var(--input-bg);
  transform: scale(1.02);
}

/* Hide preview toggle on real mobile devices */
@media (max-width: 767px) {
  .preview-toggle {
    display: none;
  }
}

body.preview-mobile {
  background: linear-gradient(135deg, #1e293b 0%, #475569 100%);
  padding: 32px 20px;
}

body.preview-mobile .phone-mockup {
  max-width: 414px;
  margin: 0 auto;
  background: #0f172a;
  padding: 14px;
  border-radius: 54px;
  box-shadow:
    0 0 0 2px #1e293b,
    0 0 0 4px #475569,
    0 35px 80px rgba(0,0,0,0.5);
  position: relative;
}

/* Phone notch (camera cutout) */
body.preview-mobile .phone-mockup::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 130px;
  height: 28px;
  background: #0f172a;
  border-radius: 0 0 18px 18px;
  z-index: 100;
}

/* Fake status bar (clock, signal, battery) */
body.preview-mobile .phone-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 28px 4px;
  background: var(--bg-color);
  border-radius: 40px 40px 0 0;
  height: 48px;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
}

body.preview-mobile .phone-status-bar .status-icons {
  display: flex;
  gap: 4px;
  align-items: center;
  font-size: 0.9rem;
}

/* Container inside the phone frame: drop its own border/shadow */
body.preview-mobile .phone-mockup .container {
  border-radius: 0 0 40px 40px;
  border: none;
  box-shadow: none;
  max-width: none;
  margin: 0;
  padding: 20px 24px 32px;
}

/* ============================================================
   RESPONSIVE — real mobile devices
   These rules ONLY apply outside preview-mobile mode (which has
   its own phone-frame styling). On real phones, we want tighter
   padding, slightly smaller fonts, and a roomier map.
   ============================================================ */

/* Tablets and small laptops */
@media (max-width: 767px) {
  body:not(.preview-mobile) {
    padding: 12px;
  }

  body:not(.preview-mobile) .container {
    padding: 20px 16px;
    border-radius: 12px;
  }

  h2 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8rem;
    margin-bottom: 20px;
  }

  h3 {
    font-size: 0.95rem;
  }

  /* Modals: shrink padding so content doesn't get cut off on small screens */
  .modal {
    padding: 20px 16px;
    max-height: 90vh;
  }

  .modal h3 {
    font-size: 1rem;
  }

  /* Map: taller on mobile since vertical scroll is the natural gesture */
  #map {
    height: 320px;
  }
}

/* Small phones (iPhone SE, older Androids) */
@media (max-width: 400px) {
  body:not(.preview-mobile) .container {
    padding: 16px 12px;
  }

  /* Inputs and buttons: smaller padding to fit on narrow screens */
  input[type="text"], select, .floor-trigger {
    padding: 10px 12px;
    font-size: 0.95rem;
  }

  button {
    padding: 12px;
    font-size: 0.95rem;
  }

  /* IMEI prefix: shrink horizontal padding so the input has room */
  .imei-prefix {
    padding: 10px 10px;
    font-size: 0.9rem;
  }

  /* Symptom checkboxes: tighter on small screens */
  .checkbox-label {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  /* Metric cards: keep 2 columns but compress */
  .metric-card {
    padding: 12px 4px;
  }

  .metric-value {
    font-size: 1.25rem;
  }

  .metric-label {
    font-size: 0.7rem;
  }

  /* Floor picker grid: stay readable on small screens */
  .floor-grid {
    gap: 6px;
  }

  .floor-btn {
    padding: 10px 2px;
    font-size: 0.85rem;
  }

  /* Modal: even tighter on the smallest phones */
  .modal {
    padding: 16px 12px;
  }

  .modal section {
    font-size: 0.82rem;
  }
}

/* Landscape orientation on phones: reclaim vertical space */
@media (max-width: 767px) and (orientation: landscape) {
  #map {
    height: 220px;
  }
}
