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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    color: #333;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ===== Top Bar (fixed row 1) ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: linear-gradient(135deg, #1a73e8 0%, #1557b0 100%);
    color: white;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.top-bar-left {
    display: flex;
    align-items: center;
    position: relative;
}

.counter-selector-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(255,255,255,0.15);
    border-radius: 20px;
    cursor: pointer;
    font-size: 20px;
    font-weight: 500;
    transition: background 0.2s;
}

.counter-selector-toggle:active {
    background: rgba(255,255,255,0.25);
}

.selector-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.selector-arrow.open {
    transform: rotate(180deg);
}

.top-bar-right {
    position: relative;
}

.hamburger-btn {
    width: 36px;
    height: 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.hamburger-btn:active {
    background: rgba(255,255,255,0.2);
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 2px;
    background: white;
    border-radius: 2px;
}

/* ===== Dropdown Menu ===== */
.dropdown-menu {
    position: absolute;
    top: 100%;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    min-width: 200px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.25s ease;
    z-index: 200;
}

.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(4px);
}

.counter-dropdown {
    left: 0;
}

.hamburger-menu {
    right: 0;
    min-width: 200px;
}

.menu-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 16px;
    color: #333;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-item:active {
    background: #f0f2f5;
}

.menu-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 4px 10px;
}


.counter-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 20px;
    color: #333;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.counter-item:active {
    background: #e8f0fe;
}

.counter-item.active {
    background: #e8f0fe;
    color: #1a73e8;
    font-weight: 500;
}

/* ===== Add Bar (fixed row 2) ===== */
.add-bar {
    position: fixed;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid #e0e0e0;
    align-items: center;
    z-index: 90;
    box-sizing: border-box;
}

.item-name-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    box-sizing: border-box;
}

.item-name-input:focus {
    border-color: #1a73e8;
}

.add-btn {
    white-space: nowrap;
    padding: 10px 16px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: #1a73e8;
    color: white;
    transition: all 0.2s;
}

.add-btn:active {
    transform: scale(0.96);
}

/* ===== List Area (scrollable row 3) ===== */
.list-area {

    position: fixed;
    left: 0;
    right: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #f5f6f8;
    z-index: 1;
    box-sizing: border-box;
}

.list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid #e8e8e8;
    flex-wrap: wrap;
    gap: 6px;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.layout-toggle, .sort-toggle {
    display: flex;
    background: #f0f2f5;
    border-radius: 8px;
    overflow: hidden;
}

.layout-option, .sort-option {
    padding: 4px 10px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
}

.layout-option.active, .sort-option.active {
    background: #1a73e8;
    color: white;
}

.reverse-label {
    font-size: 15px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* ===== Voter List Items ===== */
.voter-list {
    padding: 8px;
    padding-bottom: 56px; /* 为底部状态栏留出空间，避免遮挡最后一项 */
}

/* List layout */
.voter-item {
    display: flex;
    align-items: center;
    /*padding: 14px 16px;*/
    padding: 12px 0;
    background: white;
    border-radius: 12px;
        margin-bottom: 5px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    /*gap: 12px;*/
    transition: all 0.2s;
    cursor: pointer;
}

.voter-item:active {
    transform: scale(0.98);
    background: #fafafa;
}

.vote-count {
    font-size: 22px;
    font-weight: 700;
    color: #1a73e8;
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.voter-name {
    flex: 1;
    font-size: 17px;
    font-weight: 500;
    color: #333;
    padding: 2px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.voter-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-sm {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    background: #f0f2f5;
    transition: all 0.15s;
}

.btn-sm:active {
    transform: scale(0.9);
}

.btn-danger {
    color: #e74c3c;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state h3 {
    font-size: 18px;
    color: #666;
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 14px;
}

/* ===== Grid Layout ===== */
.voter-list.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

/* 紧缩模式：项目多且超出屏幕时 */
.voter-list.grid.grid-compact {
    gap: 1px;
}

.voter-list.grid.grid-compact .voter-item {
    padding-top: 0 !important;
        padding-bottom: 0 !important;
        transition: none !important;
    }
    
    .voter-list.grid.grid-compact .voter-item:active {
        transform: none !important;
}

.voter-list.grid.grid-compact .voter-name {
    font-size: 17px;
}

.voter-list.grid .voter-item {
    flex-direction: column;
    text-align: center;
    min-width: 0;
    width: 100%;
    margin-bottom: 0;
    transition: none !important;
}

.voter-list.grid .voter-item:active {
    transform: none !important;
    background: #fafafa;
}

.voter-list.grid .vote-count {
    min-width: auto;
    font-size: 28px;
}

.voter-list.grid.grid-compact .vote-count {
    font-size: 24px;
}

.voter-list.grid .voter-name {
    font-size: 17px;
    text-overflow: clip;
}

.voter-list.grid .voter-controls {
    display: none;
}

.voter-list.grid .btn-sm {
    width: 28px;
    height: 28px;
    font-size: 13px;
}

/* ===== Status Bar (fixed at bottom) ===== */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 10px 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
    font-size: 15px;
    color: #666;
    z-index: 150;
}

.status-item strong {
    color: #1a73e8;
}

/* ===== Notification ===== */
.notification {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 24px;
    background: #333;
    color: white;
    border-radius: 24px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.notification.error {
    background: #e74c3c;
}

/* ===== Overlay ===== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    opacity: 0;
    transition: opacity 0.25s;
}

.overlay.show {
    opacity: 1;
}

/* ===== Popup ===== */
.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: white;
    border-radius: 16px;
    min-width: 280px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 400;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    opacity: 0;
    transition: all 0.25s ease;
}

.popup.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.popup-wide {
    min-width: 320px;
    max-width: 95vw;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.popup-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.popup-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #f0f2f5;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    color: #666;
}

.popup-body {
    padding: 20px;
}

.popup-row {
    margin-bottom: 14px;
}

.popup-row label {
    display: block;
    font-size: 14px;
    color: #666;
    margin-bottom: 6px;
}

.popup-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    outline: none;
}

.popup-input:focus {
    border-color: #1a73e8;
}

.popup-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s;
}

.popup-btn:active {
    transform: scale(0.97);
}

/* 重命名按钮与删除按钮同色（红色） */
#popupRenameBtn {
    background: #e0e0e0 !important;
    color: black !important;
}
#popupDeleteBtn {
    background: #e0e0e0 !important;
}
.popup-textarea {
    width: 100%;
    min-height: 140px;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 14px;
    outline: none;
}

.popup-textarea:focus {
    border-color: #1a73e8;
}

/* ===== Help Content ===== */
.help-content h3 {
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
}

.help-content ul {
    padding-left: 20px;
    color: #555;
    line-height: 1.8;
}

/* ===== Chart Container (placeholder) ===== */
.chart-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 16px;
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    body {
        max-width: 480px;
        margin: 0 auto;
        border-left: 1px solid #e0e0e0;
        border-right: 1px solid #e0e0e0;
    }
}

/* ===== Pull-to-refresh indicator (optional) ===== */
.pull-indicator {
    text-align: center;
    padding: 10px;
    color: #999;
    font-size: 13px;
}
