:root {
  --brand-green: #0f8b6f;
  --brand-green-hover: #0c7a61;
  --brand-green-soft: #e6f4ef;
  --status-open: #0f8b6f;
  --status-open-bg: #e6f4ef;
  --status-closed: #7a847f;
  --status-closed-bg: #eef1ef;
  --status-emergency: #d64535;
  --bg: #f3f7f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --surface-3: #eef2f0;
  --border: #e2e8e4;
  --border-strong: #c9d3cd;
  --text: #16211d;
  --text-2: #4a554f;
  --text-3: #7a847f;
  --shadow-sm: 0 1px 2px rgba(22, 33, 29, 0.06);
  --shadow-md: 0 2px 8px rgba(22, 33, 29, 0.08), 0 1px 2px rgba(22, 33, 29, 0.06);
  --shadow-lg: 0 8px 24px rgba(22, 33, 29, 0.12), 0 2px 6px rgba(22, 33, 29, 0.06);
  --font-sans: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 680px;
  overflow: hidden;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex: 0 0 auto;
  gap: 20px;
  padding: 12px 18px;
}

.brand {
  align-items: center;
  color: var(--text);
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--brand-green);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 16px;
  font-weight: 800;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.brand > span:last-child {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand > span:last-child span {
  color: var(--brand-green);
}

.filters {
  background: var(--surface-3);
  border-radius: 999px;
  display: flex;
  gap: 2px;
  padding: 3px;
}

.filter-button {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
  padding: 7px 13px;
}

.filter-button.active {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.search-box {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-3);
  display: flex;
  flex: 1 1 320px;
  gap: 8px;
  max-width: 390px;
  min-width: 180px;
  padding: 8px 11px;
}

.search-box input {
  background: transparent;
  border: 0;
  color: var(--text);
  flex: 1;
  min-width: 0;
  outline: 0;
}

.topbar-meta {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-left: auto;
  min-width: 0;
}

#timeLabel {
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
}

.locate-button {
  background: var(--brand-green);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  padding: 9px 13px;
}

.content-grid {
  background: var(--border);
  display: grid;
  flex: 1;
  gap: 1px;
  grid-template-columns: minmax(320px, 380px) minmax(420px, 1fr) minmax(330px, 390px);
  min-height: 0;
}

.map-pane {
  background: var(--surface);
  grid-column: 2;
  min-width: 0;
  position: relative;
}

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

.map-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  left: 18px;
  padding: 12px 14px;
  position: absolute;
  top: 18px;
  z-index: 500;
}

.map-card strong {
  font-size: 14px;
}

.map-card span {
  color: var(--text-2);
  font-size: 12px;
}

.side-pane {
  display: contents;
}

.list-pane,
.chat-pane {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.list-pane {
  grid-column: 1;
  grid-row: 1;
}

.chat-pane {
  grid-column: 3;
  grid-row: 1;
}

.pane-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 15px 16px 11px;
}

.pane-header p {
  color: var(--brand-green);
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 5px;
}

.pane-header h1 {
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
}

.sort-button,
.status-text {
  color: var(--text-3);
  font-size: 12px;
}

.sort-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  flex: 0 0 auto;
  font-weight: 800;
  padding: 7px 10px;
  white-space: nowrap;
}

.sort-button:hover {
  border-color: var(--brand-green);
  color: var(--brand-green);
}

.status-text {
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.pharmacy-list {
  background: var(--surface-2);
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

.pharmacy-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  padding: 13px;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.pharmacy-card:hover,
.pharmacy-card.active {
  border-color: var(--brand-green);
  box-shadow: var(--shadow-md);
}

.pharmacy-card.active {
  transform: translateY(-1px);
}

.card-top {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.card-top h2 {
  font-size: 15px;
  line-height: 1.3;
  margin: 0;
}

.badge {
  border-radius: 999px;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  padding: 5px 8px;
  white-space: nowrap;
}

.badge.open {
  background: var(--status-open-bg);
  color: var(--status-open);
}

.badge.closed {
  background: var(--status-closed-bg);
  color: var(--status-closed);
}

.meta {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.45;
  margin: 8px 0 0;
}

.actions {
  display: flex;
  gap: 7px;
  margin-top: 11px;
}

.actions a {
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 9px;
  text-decoration: none;
}

.actions a.primary {
  background: var(--brand-green);
  border-color: var(--brand-green);
  color: #fff;
}

.notice,
.empty {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.6;
  padding: 14px;
}

.chat-header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  padding: 12px 16px;
}

.ai-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--brand-green), #14b89a);
  border-radius: 999px;
  color: #fff;
  display: flex;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.chat-header h2 {
  font-size: 14px;
  margin: 0 0 3px;
}

.chat-header p {
  align-items: center;
  color: var(--text-3);
  display: flex;
  font-size: 10px;
  gap: 5px;
  margin: 0;
}

.chat-header p span {
  background: var(--brand-green);
  border-radius: 50%;
  display: inline-block;
  height: 6px;
  width: 6px;
}

.chat-messages {
  background: var(--surface-2);
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.assistant-message,
.user-message {
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  max-width: 88%;
  padding: 10px 12px;
  white-space: pre-wrap;
}

.assistant-message {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.user-message {
  align-self: flex-end;
  background: var(--brand-green);
  color: #fff;
}

.message-meta {
  color: var(--text-3);
  display: block;
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 5px;
}

.pill-tool {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
}

.pill-tool-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.pill-tool-header strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.pill-tool-header span {
  color: var(--text-3);
  display: block;
  font-size: 10px;
  line-height: 1.35;
  margin-top: 2px;
}

.pill-upload-button,
.pill-identify-button {
  border-radius: 8px;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pill-upload-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 7px 9px;
}

.pill-upload-button input {
  display: none;
}

.pill-preview {
  align-items: center;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--text-3);
  display: flex;
  font-size: 11px;
  height: 74px;
  justify-content: center;
  overflow: hidden;
}

.pill-preview img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.pill-fields {
  display: grid;
  gap: 7px;
  grid-template-columns: minmax(0, 1.4fr) minmax(82px, 0.8fr) minmax(82px, 0.8fr);
}

.pill-fields input,
.pill-fields select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-width: 0;
  outline: 0;
  padding: 8px 9px;
}

.pill-identify-button {
  background: #16211d;
  border: 0;
  color: #fff;
  padding: 9px 10px;
}

.pill-result-message {
  max-width: 96%;
}

.pill-candidates {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.pill-candidate {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 9px;
  padding: 8px;
}

.pill-candidate img {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  flex: 0 0 auto;
  height: 54px;
  object-fit: contain;
  width: 72px;
}

.pill-candidate strong {
  display: block;
  font-size: 12px;
  line-height: 1.35;
}

.pill-candidate span {
  color: var(--text-2);
  display: block;
  font-size: 11px;
  line-height: 1.45;
  margin-top: 3px;
}

.pill-candidate span b {
  color: var(--text);
  font-weight: 850;
}

.chat-form {
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  padding: 10px 12px 8px;
}

.chat-form input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex: 1;
  min-width: 0;
  outline: 0;
  padding: 10px 11px;
}

.chat-form button {
  background: var(--brand-green);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
  padding: 0 13px;
}

.chat-disclaimer {
  color: var(--text-3);
  font-size: 10px;
  line-height: 1.4;
  margin: 0;
  padding: 0 12px 10px;
}

.pharm-marker {
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25));
  height: 38px;
  position: relative;
  width: 32px;
}

.pharm-marker-pin {
  align-items: center;
  background: var(--marker-color);
  border: 2px solid white;
  border-radius: 50% 50% 50% 50% / 55% 55% 45% 45%;
  color: white;
  display: flex;
  font-size: 18px;
  font-weight: 900;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.pharm-marker-tail {
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 8px solid var(--marker-color);
  bottom: 0;
  height: 0;
  left: 50%;
  position: absolute;
  transform: translateX(-50%);
  width: 0;
}

.cluster-marker {
  align-items: center;
  background: #0f8b6f;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(15, 139, 111, 0.28), 0 2px 8px rgba(22, 33, 29, 0.16);
  color: #fff;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  height: var(--cluster-size);
  justify-content: center;
  line-height: 1;
  min-height: 48px;
  min-width: 48px;
  padding: 0;
  pointer-events: auto;
  transform: translateZ(0);
  width: var(--cluster-size);
}

.cluster-marker strong {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
}

.cluster-marker span {
  font-size: 10px;
  font-weight: 800;
  margin-top: 3px;
  opacity: 0.9;
}

#map {
  background: var(--surface-3);
  font-family: var(--font-sans);
}

.user-loc-marker {
  height: 24px;
  position: relative;
  width: 24px;
}

.user-loc-dot {
  background: #2d7bf4;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  height: 14px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  z-index: 2;
}

.user-loc-pulse {
  animation: userPulse 2s ease-out infinite;
  background: rgba(45, 123, 244, 0.3);
  border-radius: 50%;
  height: 24px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
}

@keyframes userPulse {
  0% {
    height: 14px;
    opacity: 0.8;
    width: 14px;
  }
  100% {
    height: 50px;
    opacity: 0;
    width: 50px;
  }
}

@media (max-width: 1120px) {
  .app-shell {
    min-height: 100vh;
    overflow: auto;
  }

  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
  }

  .filters {
    order: 3;
    overflow-x: auto;
    width: 100%;
  }

  .search-box {
    flex-basis: calc(100% - 112px);
    max-width: none;
  }

  .topbar-meta {
    margin-left: 0;
    width: 100%;
  }

  .content-grid {
    display: flex;
    flex-direction: column;
    min-height: auto;
  }

  .chat-pane {
    order: 1;
  }

  .map-pane {
    order: 2;
    height: 48vh;
    min-height: 360px;
  }

  .side-pane {
    display: contents;
  }

  .list-pane {
    order: 3;
    min-height: 520px;
  }

  .chat-pane {
    max-height: min(620px, 78vh);
    min-height: 320px;
  }

  .pill-fields {
    grid-template-columns: 1fr 1fr;
  }

  .pill-fields input {
    grid-column: 1 / -1;
  }
}
