* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    background: #f4f5f7;
    color: #1a1d23;
}

.layout { display: flex; min-height: 100vh; container: layoutc / inline-size; }
html, body { overflow-x: hidden; }

/* ── Sidebar ── */
.sidebar {
    width: 220px; flex-shrink: 0;
    background: #ffffff; color: #1a1d23;
    border-right: 1px solid #e5e7eb;
    display: flex; flex-direction: column; padding: 20px 0;
}
.brand { display: block; padding: 0 16px 24px; text-decoration: none; }
.brand-logo {
    display: block; width: 100%; max-width: 168px; height: auto;
}

.sidenav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidenav-label {
    font-size: 11px; color: #9ca3af; margin: 18px 10px 6px;
    text-transform: uppercase; letter-spacing: .04em;
}
.sidenav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    color: #1a1d23; text-decoration: none; font-size: 14px;
}
.sidenav a .ic { width: 18px; text-align: center; }
.sidenav a:hover { background: #f4f5f7; }
.sidenav a.active { background: #f0fdf4; color: #059669; }

.sidebar-bottom { margin-top: auto; }
.sidebar-foot {
    padding: 16px 20px;
    font-size: 11px; color: #9ca3af;
    border-top: 1px solid #e5e7eb;
}
.sidenav-toggle {
    display: flex; align-items: center; gap: 8px;
    width: calc(100% - 20px); margin: 0 10px 8px;
    padding: 10px 12px; border-radius: 8px;
    background: #f4f5f7; color: #1a1d23; border: 1px solid #e5e7eb;
    font-family: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.sidenav-toggle:hover { background: #e5e7eb; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 14px 28px; }
.topbar-brand { display: none; }
.search-form { display: flex; gap: 8px; max-width: 480px; }
.search-box { position: relative; flex: 1; }
.search-form input {
    width: 100%; padding: 9px 14px;
    border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.search-form button {
    padding: 9px 18px; border: none;
    background: #059669; color: #fff; border-radius: 8px;
    cursor: pointer; font-size: 14px; flex-shrink: 0;
}
.search-form button:hover { background: #047857; }

/* ── 검색 자동완성 드롭다운 ── */
.search-suggest {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px);
    margin: 0; padding: 4px; list-style: none;
    background: #fff; border: 1px solid #d1d5db; border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 320px; overflow-y: auto; z-index: 200;
    -webkit-overflow-scrolling: touch;
}
.suggest-item {
    display: flex; align-items: baseline; gap: 8px;
    padding: 10px 12px; border-radius: 6px;
    font-size: 14px; color: #1f2937; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.suggest-item:hover,
.suggest-item.is-active { background: #eff4ff; }
.suggest-name { font-weight: 600; flex-shrink: 0; }
.suggest-meta { font-size: 12px; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 28px; max-width: 980px; }
.page-title { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: #6b7280; font-size: 13px; margin-bottom: 20px; }

/* ── Footer ── */
.site-footer {
    border-top: 1px solid #e5e7eb;
    padding: 20px 28px;
    background: #f9fafb;
    margin-top: auto;
}
.footer-disclaimer {
    font-size: 12px; color: #374151;
    font-weight: 600; margin-bottom: 6px;
}
.footer-meta { font-size: 11px; color: #9ca3af; margin-top: 4px; }

/* ── Dashboard stat cards ── */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 14px; margin-bottom: 24px;
}
.stat-card {
    background: #fff; border: 1px solid #e5e7eb;
    border-radius: 12px; padding: 18px; min-width: 0;
}
.stat-card, .panel { overflow-wrap: anywhere; }
.stat-num { font-size: 22px; font-weight: 700; color: #059669; margin-bottom: 4px; }
.stat-label { font-size: 12px; color: #6b7280; }

.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.panel-wide { margin-bottom: 16px; }
.panel { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 18px; min-width: 0; }
.panel h2 { font-size: 15px; margin-bottom: 2px; }
.panel-sub { font-size: 12px; color: #9ca3af; margin-bottom: 12px; }

.rank-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rank-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.rank-list a { color: #1a1d23; text-decoration: none; font-weight: 600; }
.rank-list a:hover { color: #059669; }
.rank-list .tag {
    font-size: 11px; color: #6b7280;
    background: #f1f2f4; padding: 2px 6px; border-radius: 4px;
}
.rank-list .count { margin-left: auto; font-size: 13px; color: #6b7280; font-weight: 600; }
.rank-list.good .count { color: #16a34a; }
.rank-list.bad .count { color: #dc2626; }

.empty { color: #9ca3af; font-size: 13px; padding: 8px 0; }

/* ── Card list ── */
.search-group { margin-bottom: 24px; }
.search-group-title { font-size: 15px; margin-bottom: 10px; color: #374151; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
    background: #fff; border: 1px solid #e5e7eb;
    border-radius: 10px; padding: 14px 16px;
}
.card-head { display: flex; align-items: baseline; gap: 8px; }
.name { font-size: 16px; font-weight: 600; color: #1a1d23; text-decoration: none; }
.name:hover { color: #059669; }
.party { font-size: 13px; color: #059669; }
.vote-summary {
    margin-left: auto; font-size: 12px; color: #047857;
    background: #ecfdf5; padding: 3px 8px; border-radius: 6px; white-space: nowrap;
}
.region { font-size: 13px; color: #777; margin: 2px 0 10px; }
.votes { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
    flex: 1; min-width: 90px; padding: 8px 6px;
    border: 1px solid #d1d5db; border-radius: 8px;
    background: #fafafa; cursor: pointer; font-size: 13px;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { background: #ecfdf5; border-color: #6ee7b7; }
.btn:active { background: #e5e7eb; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; color: #4b5563; }
.voted-msg { margin-top: 8px; font-size: 12px; color: #16a34a; }
.blackout-notice {
    margin-top: 4px; padding: 8px 10px;
    background: #fef3c7; color: #92400e;
    border-radius: 6px; font-size: 12px;
}
.back { font-size: 13px; color: #059669; text-decoration: none; display: inline-block; margin-bottom: 10px; }
.chart-box { position: relative; width: 100%; height: 320px; }
.vote-panel { margin-bottom: 16px; }
.vote-panel .votes { margin-top: 12px; }
.vote-panel .voted-msg { margin-top: 10px; }

/* ── 인물 상세: 누적 통계 카드 ── */
.cum-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px; margin-top: 12px;
}
.cum-card {
    background: #f9fafb; border: 1px solid #eceef1;
    border-radius: 10px; padding: 14px; min-width: 0;
}
.cum-num { font-size: 18px; font-weight: 700; color: #14171f; overflow-wrap: anywhere; }
.cum-label { font-size: 12px; color: #6b7280; margin-top: 3px; }
.cum-sub { font-size: 12px; color: #9ca3af; margin-top: 6px; }

/* ── 페이지네이션 ── */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 14px; margin: 56px 0 8px;
}
.page-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 40px; padding: 0 18px;
    border: 1px solid #d1d5db; border-radius: 8px;
    background: #fff; color: #1f2937; font-size: 14px; font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.page-btn:hover { background: #f3f4f6; }
.page-btn:active { background: #e5e7eb; }
.page-btn.disabled { opacity: 0.4; pointer-events: none; }
.page-status { font-size: 13px; color: #6b7280; }

/* ── 하단 탭 네비게이션 (모바일 / '모바일 화면' 뷰 전환 시) ── */
.tabbar {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: #14171f; border-top: 1px solid #2a2e3a;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 100;
}
.tabbar a, .tabbar .tabbar-btn {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    padding: 9px 4px; min-height: 54px;
    color: #9aa0ab; text-decoration: none;
    font-size: 11px; font-weight: 600; font-family: inherit;
    background: none; border: 0; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.tabbar a.active { color: #fff; }
.tabbar a.active .tabbar-ic { color: #059669; }
.tabbar-ic { font-size: 20px; line-height: 1; }
.tabbar-mark { width: 22px; height: 22px; display: block; }

/* 좁은 화면(자동)이거나 '모바일 화면' 강제 시 하단 탭바 노출 */
@media (max-width: 640px) {
    .tabbar { display: flex; }
    .layout { flex-direction: column; }
}
html.force-mobile .layout { flex-direction: column; max-width: 460px; margin: 0 auto; }
html.force-mobile .tabbar {
    display: flex;
    left: 50%; right: auto; transform: translateX(-50%);
    width: 100%; max-width: 460px;
}

@container layoutc (max-width: 900px) { .stat-grid, .dash-grid { grid-template-columns: 1fr 1fr; } }

/* ── 모바일 레이아웃 (.layout 컨테이너 폭 기준 → 자동 좁은 화면 or .force-mobile) ── */
@container layoutc (max-width: 640px) {
    .sidebar { display: none; }

    .topbar { padding: 10px 14px; }
    .topbar-brand { display: block; margin-bottom: 10px; }
    .topbar-brand img { display: block; height: 30px; width: auto; }
    .search-form { max-width: none; gap: 6px; }
    .search-form input { padding: 12px 14px; font-size: 16px; }   /* 16px: iOS 자동 확대 방지 */
    .search-form button { padding: 12px 16px; font-size: 14px; }

    /* 자동완성: 터치 영역 확대 */
    .search-suggest { max-height: 60vh; }
    .suggest-item { padding: 13px 12px; min-height: 46px; font-size: 15px; }

    .content { padding: 18px 14px; }
    .page-title { font-size: 20px; }
    .page-sub { margin-bottom: 16px; }

    /* 대시보드 */
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
    .stat-card { padding: 14px; border-radius: 10px; }
    .stat-card:last-child { grid-column: 1 / -1; }
    .stat-num { font-size: 16px; }
    .dash-grid { grid-template-columns: 1fr; gap: 12px; }

    /* 카드 레이아웃 */
    .card { padding: 14px; border-radius: 12px; }
    .card-head { flex-wrap: wrap; row-gap: 4px; align-items: center; }
    .name { font-size: 17px; }
    .vote-summary { margin-left: 0; flex-basis: 100%; white-space: normal; }
    .region { margin: 4px 0 12px; }

    /* 투표 버튼: 세로로 꽉 채워 터치 영역 확대 */
    .votes { flex-direction: column; gap: 8px; }
    .btn {
        flex: none; width: 100%; min-width: 0;
        padding: 15px 12px; font-size: 15px; border-radius: 10px;
    }

    /* 하단 탭바 높이만큼 본문 하단 여백 확보 */
    .content, .site-footer {
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }
    .site-footer { padding-left: 14px; padding-right: 14px; }

    /* 페이지네이션: 터치 영역 확대 */
    .pagination { gap: 10px; margin: 48px 0 4px; }
    .page-btn { flex: 1; min-height: 48px; padding: 0 12px; font-size: 15px; }
    .page-status { flex: none; min-width: 56px; text-align: center; }
}
