:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b91c1c;
  --ok: #047857;
  --border: #e2e8f0;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  --sidebar-width: 292px;
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.app.needs-config {
  display: grid;
  place-items: stretch;
}

h1 {
  margin: 0 0 4px;
  font-size: clamp(18px, 2vw, 28px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: #cbd5e1;
  font-size: 14px;
}

.location-form label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.location-form input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: white;
  outline: none;
}

.location-form {
  width: 100%;
}

.location-form input {
  width: 100%;
  height: 44px;
  font-size: 16px;
  border-color: var(--border);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

.location-form input::placeholder { color: #94a3b8; }

.location-form input:focus {
  border-color: rgba(37, 99, 235, 0.72);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

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

.gm-style .gm-style-iw-c {
  display: block !important;
  padding: 8px 30px 8px 12px !important;
}

.gm-style .gm-style-iw-d {
  overflow: hidden !important;
}

.gm-style .gm-style-iw-chr {
  position: absolute !important;
  top: 3px !important;
  right: 3px !important;
  width: 20px !important;
  height: 20px !important;
}

.gm-style .gm-style-iw-ch {
  display: none !important;
}

.gm-style .gm-ui-hover-effect {
  top: 0 !important;
  right: 0 !important;
  width: 20px !important;
  height: 20px !important;
  position: absolute !important;
}

.gm-style .gm-ui-hover-effect > span {
  width: 12px !important;
  height: 12px !important;
  margin: 4px !important;
}

.location-callout-title {
  max-width: 160px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.2;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.isochrone-border-label {
  --isochrone-label-color: #1d4ed8;
  --isochrone-label-angle: 0deg;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 22px;
  padding: 0 7px;
  border: 1px solid var(--isochrone-label-color);
  border-radius: 999px;
  color: var(--isochrone-label-color);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  font-size: 12px;
  line-height: 1;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  transform: rotate(var(--isochrone-label-angle)) scale(var(--isochrone-label-scale, 1));
  transform-origin: center;
}

.isochrone-border-label-location {
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.24);
}

.map-shell {
  position: absolute;
  inset: 0;
}

.sidebar {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 2;
  width: var(--sidebar-width);
  background: #f8fafc;
  border-right: 1px solid var(--border);
  box-shadow: 10px 0 36px rgba(15, 23, 42, 0.12);
  overflow: visible;
  transition: transform 220ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.sidebar-content {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px;
  overflow-y: auto;
}

.sidebar-content > * {
  flex: 0 0 auto;
}

.app.sidebar-collapsed .sidebar {
  border-right-color: transparent;
  box-shadow: none;
  transform: translateX(-100%);
}

.app.sidebar-collapsed .sidebar-content {
  pointer-events: none;
}

.sidebar-toggle {
  position: absolute;
  top: 13px;
  right: -26px;
  z-index: 4;
  width: 26px;
  height: 52px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-left-color: #f8fafc;
  border-radius: 0 12px 12px 0;
  color: var(--muted);
  background: #f8fafc;
  cursor: pointer;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
  color: var(--accent-dark);
  outline: none;
}

.sidebar-toggle-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-toggle-icon-right,
.app.sidebar-collapsed .sidebar-toggle-icon-left {
  display: none;
}

.app.sidebar-collapsed .sidebar-toggle {
  border-left-color: var(--border);
}

.app.sidebar-collapsed .sidebar-toggle-icon-right {
  display: block;
}

.locations-list {
  display: grid;
  gap: 18px;
  padding-left: 7px;
}

.location-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.location-item-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.location-item h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.location-remove {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  justify-self: end;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.location-remove:hover,
.location-remove:focus-visible {
  color: var(--danger);
  background: #fee2e2;
  outline: none;
}

.location-remove svg,
.isochrone-remove svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.location-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.isochrone-rows {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.isochrone-row {
  display: grid;
  grid-template-columns: 76px auto 32px;
  align-items: center;
  gap: 8px;
}

.isochrone-minutes {
  width: 76px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  color: var(--text);
  background: white;
  font: inherit;
  outline: none;
}

.isochrone-minutes:focus {
  border-color: rgba(37, 99, 235, 0.72);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.isochrone-unit {
  color: var(--muted);
  font-size: 13px;
}

.isochrone-remove {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.isochrone-remove:hover,
.isochrone-remove:focus-visible {
  color: var(--danger);
  background: #fee2e2;
  outline: none;
}

.isochrone-add-row {
  margin-top: 8px;
}

.isochrone-add,
.isochrone-update {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: white;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.isochrone-add {
  padding: 0 14px;
}

.isochrone-update {
  margin-left: 7px;
  width: calc(100% - 7px);
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.isochrone-add:hover,
.isochrone-add:focus-visible {
  border-color: rgba(37, 99, 235, 0.56);
  color: var(--accent-dark);
  outline: none;
}

.isochrone-update:hover,
.isochrone-update:focus-visible {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  outline: none;
}

.isochrone-update:disabled {
  color: #94a3b8;
  border-color: var(--border);
  background: #e2e8f0;
  cursor: not-allowed;
}

.map-style-picker {
  width: calc(100% - 7px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: auto;
  margin-left: 7px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #e2e8f0;
}

.map-style-button {
  height: 34px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.map-style-button.active {
  color: var(--text);
  background: white;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.map-style-button:hover,
.map-style-button:focus-visible {
  color: var(--accent-dark);
  outline: none;
}

.config-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f8fafc;
}

.config-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
}

.config-panel h1 {
  color: var(--text);
}

.config-panel .subtitle {
  color: var(--muted);
  line-height: 1.45;
}

.config-error {
  margin: 0;
  padding: 11px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: var(--danger);
  background: #fef2f2;
  line-height: 1.45;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.status-card {
  position: absolute;
  left: 16px;
  bottom: 20px;
  z-index: 3;
  max-width: min(460px, calc(100vw - 32px));
  padding: 13px 42px 13px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.94);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  font-size: 14px;
}

.status-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
}

.status-close:hover {
  color: var(--text);
  background: #f1f5f9;
}

.status-title {
  margin: 0 0 4px;
  font-weight: 800;
}

.status-body {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.status-body.error { color: var(--danger); }
.status-body.ok { color: var(--ok); }

@media (max-width: 760px) {
  .sidebar {
    inset: 0 0 auto;
    width: 100%;
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .sidebar-content {
    gap: 12px;
    padding: 12px;
  }

  .sidebar-toggle {
    top: auto;
    right: 12px;
    bottom: -34px;
    width: 52px;
    height: 34px;
    border-left-color: var(--border);
    border-top-color: #f8fafc;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
    transform: rotate(90deg);
  }

  .app.sidebar-collapsed .sidebar-toggle {
    right: 12px;
    bottom: -34px;
  }

  .app.sidebar-collapsed .sidebar {
    border-bottom-color: transparent;
    transform: translateY(-100%);
  }
}
