/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #1a1a1a;
  background: #f5f5f4;
  line-height: 1.5;
}

/* --- App shell --- */
.app {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e8e8e6;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid #e8e8e6;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.logo-icon {
  font-size: 1.25rem;
  color: #2d2d2b;
  opacity: 0.9;
}

.logo-text {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #1a1a1a;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  color: #6b6b69;
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-item:hover {
  color: #1a1a1a;
  background: #f5f5f4;
}

.nav-item--active {
  color: #1a1a1a;
  background: #eef2f4;
}

.nav-icon {
  font-size: 0.75rem;
  opacity: 0.7;
}

.nav-item--active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid #e8e8e6;
}

.footer-label {
  font-size: 0.75rem;
  color: #9a9a98;
  font-weight: 500;
}

/* --- Main content --- */
.main {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 3rem;
}

.main-header {
  margin-bottom: 2rem;
}

.page-title {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: #1a1a1a;
}

.page-subtitle {
  margin: 0;
  font-size: 0.9375rem;
  color: #6b6b69;
}

/* --- Stats grid --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #6b6b69;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: #1a1a1a;
}

.stat-hint {
  font-size: 0.75rem;
  color: #9a9a98;
}

/* --- Content sections --- */
.content-section {
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
}

.section-header {
  margin-bottom: 1.25rem;
}

.section-header--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-header-text {
  flex: 1;
}

.view-more-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b6b69;
  text-decoration: none;
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.view-more-link:hover {
  color: #1a1a1a;
}

.view-more-icon {
  flex-shrink: 0;
}

.section-title {
  margin: 0 0 0.25rem;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #1a1a1a;
}

.section-desc {
  margin: 0;
  font-size: 0.875rem;
  color: #6b6b69;
}

/* --- Table --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: #6b6b69;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #e8e8e6;
  white-space: nowrap;
}

.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #f0f0ee;
  color: #2d2d2b;
}

td .badge {
  display: inline-block;
  min-width: 1.75rem;
  padding: 0.2rem 0.5rem;
  background: #eff6ff;
  color: #2563eb;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 6px;
  text-align: center;
}

td .badge--bot {
  background: #fef3c7;
  color: #92400e;
  min-width: auto;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table tbody tr:hover {
  background: #fafaf9;
}

.cell-subject {
  font-weight: 500;
  color: #1a1a1a;
}

.datetime {
  color: #6b6b69;
  font-variant-numeric: tabular-nums;
}

.location {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: #2d2d2b;
}

/* --- Two-column layout for bottom sections --- */
.content-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.content-section--half {
  flex: 1;
  min-width: 0;
}

/* --- Location list --- */
.location-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.location-item {
  display: grid;
  grid-template-columns: 1fr 2fr 3rem;
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid #f0f0ee;
  font-size: 0.875rem;
}

.location-item:last-child { border-bottom: 0; }

.location-name {
  font-weight: 500;
  color: #2d2d2b;
}

.location-bar {
  height: 6px;
  background: #e8e8e6;
  border-radius: 3px;
  overflow: hidden;
}

.location-fill {
  display: block;
  height: 100%;
  background: #2d2d2b;
  border-radius: 3px;
  min-width: 4px;
  transition: width 0.3s ease;
}

.location-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #6b6b69;
  font-weight: 500;
}

/* --- Chart placeholder --- */
.chart-placeholder {
  padding: 1rem 0;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  height: 140px;
  margin-bottom: 0.75rem;
}

.chart-day {
  flex: 1;
  min-width: 24px;
  height: 100%;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.chart-day .chart-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 8px;
  border-radius: 10px 10px 0 0;
  transition: height 0.3s ease;
}

.chart-day .chart-bar--sent {
  background: linear-gradient(to bottom, #2d2d2b, #2d2d2b00);
  z-index: 0;
}

.chart-day .chart-bar--opened {
  background: linear-gradient(to bottom, #e8e8e6, #e8e8e600);
  z-index: 1;
}

.chart-labels {
  display: flex;
  justify-content: space-around;
  font-size: 0.75rem;
  color: #9a9a98;
  font-weight: 500;
}

.chart-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: #6b6b69;
  font-weight: 500;
}

.chart-legend-item--sent::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.375rem;
  border-radius: 2px;
  background: #2d2d2b;
  vertical-align: middle;
}

.chart-legend-item--opened::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.375rem;
  border-radius: 2px;
  background: #e8e8e6;
  vertical-align: middle;
  box-shadow: 0 0 0 1px #ccc;
}

/* --- Forms & create page --- */
.form-message {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-size: 0.9375rem;
}

.form-message--error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.form-message--warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.form-message--warning code {
  font-size: 0.875em;
  background: rgba(0,0,0,.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.track-form {
  max-width: 28rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #2d2d2b;
}

.form-input {
  padding: 0.625rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid #e8e8e6;
  border-radius: 8px;
  transition: border-color 0.15s ease;
}

.form-input:focus {
  outline: none;
  border-color: #2d2d2b;
}

.form-input::placeholder {
  color: #9a9a98;
}

.form-hint {
  margin: 0;
  font-size: 0.8125rem;
  color: #6b6b69;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn--primary {
  background: #1a1a1a;
  color: #fff;
}

.btn--primary:hover {
  background: #2d2d2b;
}

.btn--secondary {
  background: #f5f5f4;
  color: #2d2d2b;
  border: 1px solid #e8e8e6;
}

.btn--secondary:hover {
  background: #e8e8e6;
}

.pixel-url-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.pixel-url {
  flex: 1;
  min-width: 0;
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  background: #f5f5f4;
  border: 1px solid #e8e8e6;
  border-radius: 8px;
  word-break: break-all;
}

.form-details {
  margin-top: 1rem;
  font-size: 0.875rem;
}

.form-details summary {
  cursor: pointer;
  color: #6b6b69;
  font-weight: 500;
}

.pixel-html {
  margin: 0.75rem 0 0.5rem;
  padding: 1rem;
  font-size: 0.8125rem;
  background: #f5f5f4;
  border: 1px solid #e8e8e6;
  border-radius: 8px;
  overflow-x: auto;
}

.pixel-html code {
  font-family: ui-monospace, monospace;
}

.link {
  color: #2d2d2b;
  font-weight: 500;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.table-empty,
.empty-state {
  padding: 1.5rem 0;
  font-size: 0.9375rem;
  color: #6b6b69;
  text-align: center;
}

.empty-state {
  text-align: left;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-row {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid #e8e8e6;
  }

  .sidebar-header {
    border-bottom: 0;
    padding: 1rem 1.25rem;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    padding: 0.5rem 0.75rem;
    flex-wrap: wrap;
  }

  .sidebar-footer {
    width: 100%;
    border-top: 1px solid #e8e8e6;
    padding: 0.75rem 1.25rem;
  }

  .main {
    padding: 1.5rem 1.25rem 2rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  .content-section {
    padding: 1.25rem 1rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
  }

  .location-item {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 0.25rem 1rem;
  }

  .location-item .location-bar {
    grid-column: 1 / -1;
  }

  .location-count {
    text-align: left;
  }
}
