/* === Mobile === */
@media (max-width: 768px) {
  .container { padding: 0 1rem; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    background: linear-gradient(135deg, #0f172a 0%, var(--primary-darker) 100%);
    flex-direction: column;
    padding: 0.5rem;
    box-shadow: var(--shadow-lg);
    border-top: 1px solid rgba(255,255,255,0.06);
  }
  .nav-links.open { display: flex; }
  .menu-toggle { display: block; }
  .hero { padding: 2rem 0.5rem 1.5rem; }
  .hero::before { display: none; }
  .hero h1 { font-size: 1.5rem; }
  .hero p { font-size: 1rem; }
  .hero-search { flex-direction: column; padding: 0.5rem; }
  .hero-search button { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .stat-card { padding: 1rem; }
  .stat-icon { width: 36px; height: 36px; border-radius: 10px; margin-bottom: 0.5rem; }
  .stat-icon svg { width: 18px; height: 18px; }
  .stat-number { font-size: 1.4rem; }
  .skeleton-pulse { width: 3.5rem; height: 1.3rem; }
  .stat-label { font-size: 0.7rem; }
  .stat-subtitle { font-size: 0.68rem; }
  .search-bar { flex-direction: column; padding: 0.625rem; }
  .search-bar input, .search-bar select, .autocomplete-wrap { min-width: 100%; }
  .price-table { font-size: 0.8rem; }
  .price-table th, .price-table td { padding: 0.5rem; }
  .price-group-header { flex-direction: column; align-items: flex-start; }
  .group-stats { width: 100%; justify-content: space-between; }
  .inner-table th, .inner-table td { padding: 0.4rem 0.5rem; font-size: 0.75rem; }
  .detail-stats { flex-direction: column; align-items: stretch; }
  .detail-stat { min-width: auto; }
  .price-range { flex-direction: column; align-items: flex-start; min-width: auto; }
  .prices-grouped-table th, .prices-grouped-table td { padding: 0.5rem 0.4rem; font-size: 0.8rem; }
  .detail-table th, .detail-table td { padding: 0.4rem 0.5rem; font-size: 0.75rem; }
  .detail-item { grid-template-columns: 5rem 1fr; gap: 0.25rem 0.5rem; padding: 0.5rem 0.75rem; }
  .di-nums { grid-column: 1 / -1; flex-direction: row; gap: 0.75rem; }
  .di-price { font-size: 0.82rem; }
  .detail-sort-bar { flex-wrap: wrap; }
  .detail-col-headers { display: none; }
  .year-filter { flex-wrap: wrap; }
  .page h1 { font-size: 1.375rem; }
  .card { padding: 0.875rem 1rem; }
  .footer { padding: 1.5rem 0; }
  .analyses-grid { grid-template-columns: 1fr; gap: 1rem; }
  .analyses-filters { flex-direction: column; align-items: stretch; }
  .analyses-search-wrap { width: 100%; }
  .filter-pills { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .article-content { padding: 1.5rem 1.25rem; }
  .article-header h1 { font-size: 1.4rem; }
  .article-meta-bar { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .article-tags-bar { margin-left: 0; }
  .section-header { flex-direction: column; gap: 0.25rem; }
}

/* === Tablet breakpoint === */
@media (min-width: 769px) and (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .analyses-grid { grid-template-columns: repeat(2, 1fr); }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
html { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* === Focus Visible === */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px; }

/* === Contractor Profile === */
.back-link {
    display: inline-flex; align-items: center; gap: 0.25rem;
    color: var(--primary); text-decoration: none; font-size: 0.9rem; font-weight: 500;
    margin-bottom: 1rem; padding: 0.25rem 0;
}
.back-link:hover { text-decoration: underline; }

.contr-name-link {
    color: var(--primary); text-decoration: none;
}
.contr-name-link:hover { text-decoration: underline; }

.profile-header { margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.profile-header h1 { font-size: 1.6rem; margin: 0; color: var(--text-primary); flex: 1; }
.cp-compare-btn {
    padding: 0.4rem 1rem; border: 1px solid var(--primary); border-radius: 0.5rem;
    background: transparent; color: var(--primary); font-size: 0.82rem; font-weight: 600;
    cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.cp-compare-btn:hover { background: #dbeafe; }
.cp-compare-btn.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }

#cp-stats { margin-bottom: 1.5rem; }
#cp-stats .stat-card { min-width: 0; }

.cp-munis { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.5rem; }
.cp-muni-tag {
    background: #f1f5f9; color: var(--text-secondary); padding: 4px 10px;
    border-radius: 6px; font-size: 0.8rem; font-weight: 500;
}
.cp-muni-toggle {
    background: none; border: none; color: var(--primary); font-size: 0.8rem;
    font-weight: 500; cursor: pointer; padding: 4px 6px;
}
.cp-muni-toggle:hover { text-decoration: underline; }

.cp-section-title {
    font-size: 1rem; font-weight: 600; color: var(--text-primary);
    margin: 1.5rem 0 0.75rem; padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.cp-cards { display: flex; flex-direction: column; gap: 0.5rem; }

.cp-card {
    background: var(--surface); border-radius: 0.5rem; padding: 0.75rem 1rem;
    border: 1px solid var(--border); transition: border-color 0.2s;
}
.cp-card:hover { border-color: var(--primary); }
.cp-card-border-green { border-left: 3px solid #059669; }
.cp-card-border-blue { border-left: 3px solid var(--primary); }

.cp-card-title {
    font-size: 0.92rem; font-weight: 500; color: var(--text-primary);
    margin-bottom: 0.35rem; line-height: 1.4;
}
.cp-card-meta {
    display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem;
    font-size: 0.8rem; color: var(--text-secondary);
}
.cp-card-meta .badge { font-size: 0.72rem; }
.cp-card-sn { color: var(--primary); font-weight: 500; }

.cp-load-more {
    display: block; width: 100%; margin: 1rem 0; padding: 0.6rem;
    background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px;
    color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
    cursor: pointer; text-align: center; transition: all 0.2s;
}
.cp-load-more:hover { background: #dbeafe; color: var(--primary); border-color: var(--primary); }

.cp-insights {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem; margin-bottom: 1.5rem;
}
.cp-insight {
    background: #ffffff;
    border: 1px solid #e2e8f0; border-left: 3px solid var(--primary);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cp-insight-label {
    font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase;
    letter-spacing: 0.03em; margin-bottom: 0.25rem; font-weight: 600;
}
.cp-insight-value {
    font-size: 1rem; font-weight: 600; color: var(--text-primary);
    line-height: 1.3; margin-bottom: 0.15rem;
}
.cp-insight-detail {
    font-size: 0.82rem; color: var(--primary); font-weight: 500;
}
.cp-specialization {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cp-cat-pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.cp-cat-pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 2rem;
    padding: 0.35rem 0.85rem; font-size: 0.82rem; color: var(--text-primary);
    font-weight: 500; white-space: nowrap;
}
a.cp-cat-link { text-decoration: none; cursor: pointer; transition: background 0.2s, border-color 0.2s; }
a.cp-cat-link:hover { background: #dbeafe; border-color: var(--primary); }
.cp-cat-count { color: var(--text-secondary); font-weight: 400; font-size: 0.75rem; }
.cp-type-breakdown {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cp-type-title {
    font-size: 0.85rem; font-weight: 700; color: var(--text-primary);
    margin: 0 0 0.75rem 0; text-transform: uppercase; letter-spacing: 0.03em;
}
.cp-type-bars { display: flex; flex-direction: column; gap: 0.5rem; }
.cp-type-row { display: flex; align-items: center; gap: 0.75rem; }
.cp-type-name { min-width: 100px; flex-shrink: 0; }
.cp-type-bar-wrap {
    flex: 1; height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden;
    display: flex;
}
.cp-type-bar { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.3s; }
.cp-type-stat {
    min-width: 90px; text-align: right; font-size: 0.85rem;
    font-weight: 600; color: var(--text-primary);
}
.cp-type-nums { font-weight: 400; color: var(--text-secondary); }

/* Contractor: Price positioning */
.cp-price-pos {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cp-price-pos-sub { font-size: 0.8rem; color: var(--text-secondary); margin: 0 0 0.75rem 0; }
.cp-pos-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.cp-pos-table th {
    text-align: left; padding: 0.4rem 0.5rem; font-size: 0.72rem; font-weight: 700;
    color: var(--text-secondary); border-bottom: 2px solid #e2e8f0; text-transform: uppercase;
    letter-spacing: 0.03em;
}
.cp-pos-table td { padding: 0.5rem 0.5rem; border-bottom: 1px solid #f1f5f9; }
.cp-pos-table tbody tr:hover { background: #f8fafc; }
.cp-pos-table tbody tr.cp-pos-row { cursor: pointer; }
.cp-pos-table tbody tr.cp-pos-row:hover { background: #dbeafe; }
.cp-pos-desc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.cp-pos-unit { color: var(--text-secondary); white-space: nowrap; }
.cp-pos-price { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cp-pos-cnt { font-size: 0.7rem; color: var(--text-muted); }
.cp-pos-diff { text-align: right; font-weight: 700; white-space: nowrap; }
.cp-pos-above { color: #dc2626; }
.cp-pos-below { color: #16a34a; }
.cp-pos-avg { color: var(--text-secondary); }

/* Contractor: Year volume chart */
.cp-year-chart {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cp-year-bars {
    display: flex; align-items: flex-end; gap: 0.25rem;
    height: 180px; padding-top: 0.5rem;
}
.cp-year-col {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    min-width: 0;
}
.cp-year-val {
    font-size: 0.65rem; font-weight: 600; color: var(--text-secondary);
    white-space: nowrap; margin-bottom: 0.2rem;
}
.cp-year-bar-wrap {
    width: 100%; max-width: 48px; height: 120px;
    display: flex; align-items: flex-end; justify-content: center;
}
.cp-year-bar {
    width: 100%; border-radius: 4px 4px 0 0;
    background: linear-gradient(180deg, var(--accent-blue) 0%, #3b82f6 100%);
    min-height: 4px; transition: height 0.4s ease;
}
.cp-year-label {
    font-size: 0.72rem; font-weight: 600; color: var(--text-primary);
    margin-top: 0.3rem;
}
.cp-year-cnt {
    font-size: 0.62rem; color: var(--accent-emerald); font-weight: 600;
}

/* === Contractor Comparison (B7) === */

/* Compare button in contractor table */
.cmp-btn {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem; font-weight: 600;
    border: 1.5px solid var(--border);
    border-radius: 1rem;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}
.cmp-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}
.cmp-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

/* Floating compare bar */
.compare-bar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    display: flex; justify-content: center;
    padding: 0.75rem 1rem;
    background: var(--primary-dark);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    animation: slideUp 0.25s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.compare-bar-inner {
    display: flex; align-items: center; gap: 1rem;
    max-width: 800px; width: 100%;
}
.compare-bar-names {
    flex: 1; color: #ffffff; font-weight: 600; font-size: 0.9rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.compare-bar-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.compare-bar-btn {
    padding: 0.5rem 1.5rem; border: none; border-radius: 0.5rem;
    background: #ffffff; color: var(--primary-dark); font-weight: 700;
    font-size: 0.85rem; cursor: pointer; transition: background 0.2s;
}
.compare-bar-btn:hover { background: #dbeafe; }
.compare-bar-clear {
    padding: 0.5rem 0.75rem; border: 1px solid rgba(255,255,255,0.3); border-radius: 0.5rem;
    background: transparent; color: #ffffff; font-size: 0.9rem; cursor: pointer;
    transition: background 0.2s;
}
.compare-bar-clear:hover { background: rgba(255,255,255,0.1); }

/* Compare page */
.cmp-legend {
    display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem;
    padding: 0.75rem 1rem; background: #ffffff; border: 1px solid #e2e8f0;
    border-radius: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cmp-legend-item {
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-weight: 600; font-size: 0.9rem; color: var(--text-primary);
}
.cmp-legend-dot {
    width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}

/* Stat comparison grid */
.cmp-stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem; margin-bottom: 1.5rem;
}
.cmp-stat-card {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.cmp-stat-label {
    font-size: 0.72rem; font-weight: 700; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.5rem;
}
.cmp-stat-value {
    padding: 0.3rem 0 0.3rem 0.75rem; margin-bottom: 0.25rem;
    font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Section container */
.cmp-section {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Authority / municipality cards */
.cmp-auth-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}
.cmp-auth-card {
    padding: 0.75rem 1rem; border-radius: 0.5rem;
    background: #f8fafc;
}
.cmp-auth-name {
    font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.cmp-auth-val {
    font-size: 0.85rem; color: var(--text-primary); line-height: 1.4;
}

/* Year chart comparison */
.cmp-year-chart {
    display: flex; align-items: flex-end; gap: 0.5rem;
    height: 200px; padding-top: 0.5rem;
}
.cmp-year-col {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    min-width: 0;
}
.cmp-year-bars-wrap {
    width: 100%; height: 160px; display: flex; align-items: flex-end;
    justify-content: center; gap: 2px;
}
.cmp-bar {
    flex: 1; max-width: 18px; min-height: 2px;
    border-radius: 3px 3px 0 0; transition: height 0.4s ease;
}
.cmp-year-label {
    font-size: 0.72rem; font-weight: 600; color: var(--text-primary);
    margin-top: 0.3rem; white-space: nowrap;
}

/* Type breakdown */
.cmp-type-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.4rem 0; border-bottom: 1px solid #f1f5f9;
}
.cmp-type-row:last-child { border-bottom: none; }
.cmp-type-name {
    min-width: 110px; flex-shrink: 0; font-size: 0.85rem;
    font-weight: 500; color: var(--text-primary);
}
.cmp-type-values {
    display: flex; gap: 0.5rem; flex: 1;
}
.cmp-type-cell {
    padding: 0.2rem 0.5rem 0.2rem 0.6rem;
    font-size: 0.85rem; font-weight: 600; color: var(--text-primary);
    font-variant-numeric: tabular-nums; background: #f8fafc; border-radius: 0.3rem;
}

/* Price comparison table */
.cmp-price-table th:nth-child(n+3),
.cmp-price-table td:nth-child(n+3) {
    text-align: right; min-width: 100px;
}

/* Profile links */
.cmp-links {
    display: flex; flex-direction: column; gap: 0.5rem;
    margin-top: 1.5rem; padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}
.cmp-profile-link {
    font-weight: 600; font-size: 0.9rem; text-decoration: none;
    transition: opacity 0.2s;
}
.cmp-profile-link:hover { opacity: 0.7; }

/* Responsive */
@media (max-width: 768px) {
    .compare-bar-names { font-size: 0.8rem; }
    .cmp-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .cmp-auth-grid { grid-template-columns: 1fr; }
    .cmp-year-chart { height: 160px; }
    .cmp-year-bars-wrap { height: 120px; }
    .cmp-type-row { flex-direction: column; align-items: flex-start; gap: 0.3rem; }
    .cmp-type-values { width: 100%; }
    .cmp-price-table { font-size: 0.75rem; }
}

/* === Authority Profile (B5) === */
.auth-name-link {
    font-size: 0.85rem; font-weight: 700; color: var(--primary);
    text-decoration: none; display: block;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.auth-name-link:hover { text-decoration: underline; }

#ap-stats { margin-bottom: 1.5rem; }
#ap-stats .stat-card { min-width: 0; }

.ap-meta {
    display: flex; flex-wrap: wrap; gap: 0.5rem;
    margin-bottom: 1.25rem;
}
.ap-meta-tag {
    background: #f1f5f9; color: var(--text-secondary);
    padding: 4px 12px; border-radius: 6px;
    font-size: 0.82rem; font-weight: 500;
}

.ap-section {
    background: #ffffff; border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.ap-contractor-link {
    color: var(--primary); text-decoration: none;
}
.ap-contractor-link:hover { text-decoration: underline; }

/* === Print === */
@media print {
  .navbar, .search-bar, .hero-search, .menu-toggle, .pagination { display: none !important; }
  .page { display: block !important; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: white; }
}
