:root {
  color: #202428;
  background: #ffffff;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
  --panel-width: 360px;
  --border: #d9dddf;
  --muted: #687077;
  --surface: #f5f6f6;
  --teal: #0f766e;
  --red: #c24132;
  --shadow: 0 8px 24px rgba(22, 28, 31, 0.16);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

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

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

.side-panel {
  z-index: 3;
  display: flex;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border-right: 1px solid var(--border);
}

.panel-header {
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.35;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
}

.update-line {
  display: flex;
  align-items: center;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #9ca3af;
}

.status-dot.fresh {
  background: #15803d;
}

.status-dot.delayed {
  background: #d97706;
}

.status-dot.stale {
  background: var(--red);
}

.status-dot.inactive {
  background: #4b5563;
}

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

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  cursor: pointer;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
}

.icon-button:hover {
  background: var(--surface);
  border-color: var(--border);
}

.icon-button:focus-visible,
.text-button:focus-visible,
.store-row:focus-visible,
.primary-button:focus-visible,
.danger-button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 1px;
}

.icon-button svg,
.text-button svg,
.primary-button svg,
.danger-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.search-wrap {
  position: relative;
  margin: 12px 16px 10px;
}

.search-wrap svg {
  position: absolute;
  top: 11px;
  left: 11px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search-wrap input,
.settings-dialog input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #bfc5c8;
  border-radius: 6px;
  background: #ffffff;
  color: #202428;
}

.search-wrap input {
  padding-left: 38px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 16px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.summary-strip div {
  display: flex;
  min-width: 0;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px;
}

.summary-strip div + div {
  border-left: 1px solid var(--border);
}

.summary-strip strong {
  font-size: 17px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 11px;
}

.filter-section {
  margin: 0 16px;
  border-bottom: 1px solid var(--border);
}

.filter-section summary {
  cursor: pointer;
  padding: 9px 0 7px;
  font-weight: 700;
  list-style-position: inside;
}

.choice-grid,
.rank-grid {
  display: grid;
  gap: 7px 10px;
  padding: 2px 0 10px;
}

.choice-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rank-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.filter-choice {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
}

.filter-choice input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.rank-swatch {
  display: inline-grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 5px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.rank-S { background: #7c3aed; }
.rank-A { background: #0f766e; }
.rank-B { background: #2563eb; }
.rank-C { background: #c76a08; }
.rank-D { background: #606a74; }

.result-heading {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 6px;
  font-weight: 700;
}

.text-button,
.primary-button,
.danger-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  padding: 0 11px;
  border-radius: 6px;
}

.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--teal);
  font-weight: 700;
}

.text-button:hover {
  background: #e8f4f2;
}

.store-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.store-row {
  display: grid;
  width: 100%;
  min-height: 72px;
  cursor: pointer;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  padding: 11px 16px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #e6e8e9;
  background: #ffffff;
}

.store-row:hover,
.store-row.active {
  background: #edf7f5;
}

.store-main {
  min-width: 0;
}

.store-name {
  display: block;
  overflow: hidden;
  font-weight: 700;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-meta,
.store-product {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-quantity {
  align-self: center;
  min-width: 38px;
  color: var(--teal);
  font-weight: 800;
  text-align: right;
}

.empty-state {
  padding: 28px 18px;
  color: var(--muted);
  line-height: 1.6;
  text-align: center;
}

.map-shell {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: #e5e8e7;
}

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

.mobile-panel-button {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  display: none;
  background: #ffffff;
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.map-progress,
.map-error {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 28px));
  align-items: center;
  padding: 10px 12px;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.map-progress {
  display: flex;
  gap: 9px;
}

.map-progress[hidden],
.map-error[hidden] {
  display: none;
}

.map-error {
  color: #8b2820;
  border-left: 4px solid var(--red);
  line-height: 1.5;
}

.spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid #bedbd7;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.stock-marker {
  display: grid;
  width: 38px;
  height: 38px;
  cursor: pointer;
  place-items: center;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(21, 27, 30, 0.35);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.stock-marker:hover {
  transform: translateY(-2px);
}

.info-window {
  width: min(330px, 72vw);
  max-height: 420px;
  overflow: auto;
  color: #202428;
}

.info-window h3 {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.4;
}

.info-address,
.info-hours {
  margin: 0 0 4px;
  color: #596168;
  font-size: 12px;
  line-height: 1.5;
}

.info-map-link {
  display: inline-flex;
  margin: 5px 0 8px;
  color: #0b6b64;
  font-weight: 700;
}

.info-item {
  padding: 8px 0;
  border-top: 1px solid #e1e4e5;
}

.info-item-name {
  display: block;
  line-height: 1.45;
}

.info-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  margin-top: 3px;
  color: #596168;
  font-size: 12px;
}

.settings-dialog {
  width: min(480px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(26, 31, 34, 0.48);
}

.settings-dialog form {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.settings-dialog header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.settings-dialog header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.settings-dialog label {
  margin-top: 5px;
  font-weight: 700;
}

.secret-field {
  position: relative;
}

.secret-field input {
  padding-right: 45px;
}

.secret-field .icon-button {
  position: absolute;
  top: 2px;
  right: 2px;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.primary-button {
  border: 1px solid #0c645d;
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: #0c645d;
}

.danger-button {
  border: 1px solid #d5a39d;
  background: #ffffff;
  color: #a33429;
}

.danger-button:hover {
  background: #fff1ef;
}

.settings-error {
  padding: 8px 10px;
  border-left: 4px solid var(--red);
  background: #fff1ef;
  color: #8b2820;
  line-height: 1.5;
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .side-panel {
    position: absolute;
    z-index: 4;
    inset: auto 0 0 0;
    width: 100%;
    height: min(56vh, 520px);
    border-top: 1px solid var(--border);
    border-right: 0;
    box-shadow: 0 -8px 24px rgba(22, 28, 31, 0.18);
    transform: translateY(calc(100% - 0px));
    transition: transform 180ms ease-out;
  }

  body.panel-open .side-panel {
    transform: translateY(0);
  }

  .panel-header {
    min-height: 64px;
  }

  .map-shell {
    width: 100%;
    height: 100%;
  }

  .mobile-panel-button {
    display: grid;
  }

  body.panel-open .mobile-panel-button {
    left: auto;
    right: 12px;
  }

  .choice-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .map-progress,
  .map-error {
    bottom: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .side-panel,
  .stock-marker {
    transition: none;
  }

  .spinner {
    animation: none;
  }
}
