*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  overflow-x: hidden;
  width: 100%;
}

body {
  background-color: var(--color-ground);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: var(--space-4) var(--space-3) var(--space-10);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

::selection {
  background-color: var(--color-accent);
  color: #ffffff;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}

/* Header & Intro */
.app-header {
  margin-bottom: var(--space-6);
  border-bottom: 2px solid var(--color-border);
  padding-bottom: var(--space-5);
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 5vw, var(--font-size-xl));
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--color-ink);
  text-wrap: balance;
  word-break: break-word;
}

.owner-tag {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  font-weight: 600;
  display: inline-block;
}

.subtitle {
  color: var(--color-ink-muted);
  font-size: var(--font-size-sm);
  max-width: 75ch;
  text-wrap: pretty;
}

/* Metric summary strip */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.summary-card {
  background: var(--color-surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  min-width: 0;
}

.summary-label {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  display: block;
  margin-bottom: var(--space-1);
}

.summary-value {
  font-size: var(--font-size-lg);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

/* Section Header */
.section-header {
  margin-bottom: var(--space-3);
}

.section-header h2 {
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-ink);
  line-height: 1.2;
}

.section-header p {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
}

/* Strategic Section (Scatter Chart & SWOT Matrix) */
.analytics-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  align-items: stretch;
}

@media (max-width: 880px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

.analytics-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
}

/* Scatter Chart Visualisation */
.chart-container {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

.scatter-svg-wrap {
  width: 100%;
  height: 280px;
  position: relative;
}

.scatter-svg-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

.scatter-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  margin-top: var(--space-3);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.competitor {
  background-color: var(--color-accent);
}

.legend-dot.my-shop {
  background-color: var(--color-positive);
  outline: 2px solid var(--color-positive-bg);
}

.scatter-tooltip {
  font-size: var(--font-size-xs);
  background: var(--color-ink);
  color: #ffffff;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  margin-top: var(--space-2);
  min-height: 40px;
  line-height: 1.35;
}

/* SWOT Matrix Layout */
.swot-matrix {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  flex: 1;
}

@media (max-width: 540px) {
  .swot-matrix {
    grid-template-columns: 1fr;
  }
}

.swot-box {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.swot-box.strength {
  background-color: var(--color-positive-bg);
  border: 1px solid rgba(46, 107, 62, 0.25);
}

.swot-box.weakness {
  background-color: var(--color-negative-bg);
  border: 1px solid rgba(158, 43, 43, 0.25);
}

.swot-box.opportunity {
  background-color: var(--color-opportunity-bg);
  border: 1px solid rgba(29, 92, 138, 0.25);
}

.swot-box.threat {
  background-color: var(--color-threat-bg);
  border: 1px solid rgba(133, 77, 14, 0.25);
}

.swot-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.swot-box.strength .swot-title {
  color: var(--color-positive);
}

.swot-box.weakness .swot-title {
  color: var(--color-negative);
}

.swot-box.opportunity .swot-title {
  color: var(--color-opportunity);
}

.swot-box.threat .swot-title {
  color: var(--color-threat);
}

.swot-list {
  list-style: none;
  font-size: var(--font-size-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--color-ink);
  line-height: 1.35;
}

.swot-list li {
  position: relative;
  padding-left: 14px;
}

.swot-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  font-weight: bold;
}

.swot-box.strength .swot-list li::before { color: var(--color-positive); }
.swot-box.weakness .swot-list li::before { color: var(--color-negative); }
.swot-box.opportunity .swot-list li::before { color: var(--color-opportunity); }
.swot-box.threat .swot-list li::before { color: var(--color-threat); }

/* View Mode Selector Tabs */
.view-tabs-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.view-tabs {
  display: inline-flex;
  background: var(--color-surface-subtle);
  padding: 3px;
  border-radius: var(--radius);
  gap: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-ink-muted);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--color-ink);
}

.tab-btn.active {
  background: var(--color-surface);
  color: var(--color-accent);
}

.scoring-badge-info {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  background: var(--color-surface);
  padding: 4px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  line-height: 1.3;
}

/* Layout Split: Form & List/Table */
.main-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--space-6);
  align-items: start;
}

@media (max-width: 860px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* Form Panel */
.panel {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  padding: var(--space-5);
  min-width: 0;
}

.panel h2 {
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-2);
  line-height: 1.2;
}

.panel p.panel-sub {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  margin-bottom: var(--space-4);
}

.form-group {
  margin-bottom: var(--space-3);
}

.form-group label {
  display: block;
  font-size: var(--font-size-xs);
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: var(--color-ink);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

input, textarea, select {
  width: 100%;
  max-width: 100%;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-ground);
  color: var(--color-ink);
}

input:focus, textarea:focus, select:focus {
  background: var(--color-surface);
  border-color: var(--color-accent);
  outline: none;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

.btn-primary {
  width: 100%;
  background-color: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-primary:hover {
  background-color: var(--color-accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-message {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius);
  font-size: var(--font-size-xs);
  display: none;
  word-break: break-word;
}

.form-message.success {
  display: block;
  background-color: var(--color-positive-bg);
  color: var(--color-positive);
}

.form-message.error {
  display: block;
  background-color: var(--color-negative-bg);
  color: var(--color-negative);
}

/* List section */
.list-section {
  min-width: 0;
  width: 100%;
}

/* Filter and Sort Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  background: var(--color-surface-subtle);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
}

.search-box {
  flex: 1;
  min-width: 140px;
}

.search-box input {
  background: var(--color-surface);
  padding: 6px 10px;
  font-size: var(--font-size-xs);
}

.sort-box {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
}

.sort-box select {
  background: var(--color-surface);
  padding: 6px 8px;
  font-size: var(--font-size-xs);
  width: auto;
}

/* Table Comparison View (Side-by-Side with Scrollable Container) */
.table-comparison-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-6);
  width: 100%;
  max-width: 100%;
}

.comparison-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: var(--font-size-xs);
  text-align: left;
}

.comparison-table th,
.comparison-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
  word-break: break-word;
}

.comparison-table th {
  background: var(--color-surface-subtle);
  color: var(--color-ink);
  font-weight: 700;
  font-size: var(--font-size-xs);
  white-space: nowrap;
}

.comparison-table tr:last-child td {
  border-bottom: none;
}

.comparison-table tr:hover td {
  background-color: rgba(248, 245, 240, 0.7);
}

.table-col-name {
  font-weight: 700;
  color: var(--color-ink);
  font-size: var(--font-size-sm);
  word-break: break-word;
}

.table-col-location {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  margin-top: 2px;
  word-break: break-word;
}

.table-price {
  font-weight: 700;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table-rating {
  white-space: nowrap;
  font-weight: 600;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 700;
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  background-color: var(--color-score-bg);
  color: var(--color-score-ink);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.score-badge.rank-top {
  background-color: #FDE8D3;
  color: #8C3A00;
  border-color: #E6B58F;
}

.table-pros {
  color: var(--color-positive);
  background-color: var(--color-positive-bg);
  padding: var(--space-2);
  border-radius: var(--radius);
  line-height: 1.35;
  min-width: 120px;
  word-break: break-word;
}

.table-cons {
  color: var(--color-negative);
  background-color: var(--color-negative-bg);
  padding: var(--space-2);
  border-radius: var(--radius);
  line-height: 1.35;
  min-width: 120px;
  word-break: break-word;
}

.source-link {
  color: var(--color-accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: var(--font-size-xs);
  display: inline-block;
  word-break: break-word;
}

.source-link:hover {
  color: var(--color-accent-hover);
}

.text-muted {
  color: var(--color-ink-muted);
}

/* Card view */
.competitors-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  min-width: 0;
}

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-3);
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  color: var(--color-ink-muted);
  font-size: var(--font-size-xs);
}

.competitor-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  min-width: 0;
  word-break: break-word;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-ink);
  line-height: 1.2;
  word-break: break-word;
}

.card-location {
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  margin-top: 2px;
  word-break: break-word;
}

.card-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.badge-price {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge-rating {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-ink);
  background: var(--color-surface-subtle);
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Comparison side by side inside card */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

@media (max-width: 500px) {
  .comparison-grid {
    grid-template-columns: 1fr;
  }
}

.col-pros, .col-cons {
  padding: var(--space-2);
  border-radius: var(--radius);
  font-size: var(--font-size-xs);
  word-break: break-word;
}

.col-pros {
  background-color: var(--color-positive-bg);
  color: var(--color-positive);
}

.col-cons {
  background-color: var(--color-negative-bg);
  color: var(--color-negative);
}

.col-heading {
  font-weight: 700;
  font-size: var(--font-size-xs);
  margin-bottom: 2px;
  display: block;
}

.card-footer {
  margin-top: var(--space-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.btn-delete {
  background: transparent;
  border: none;
  color: var(--color-negative);
  font-size: var(--font-size-xs);
  cursor: pointer;
  padding: 2px 6px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-delete:hover {
  background-color: var(--color-negative-bg);
  border-radius: var(--radius);
}

/* Footer note */
.app-footer {
  margin-top: var(--space-8);
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--color-ink-muted);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
  line-height: 1.4;
}
