:root {
    /* Moral/Nature Palette */
    --primary-color: #637E60;
    /* Sage Green */
    --primary-hover: #4F664C;
    --accent-color: #D9885E;
    /* Muted Orange for highlights */

    --bg-color: #FAF9F6;
    /* Warm Off-white/Cream */
    --card-bg: #FFFFFF;

    --text-primary: #3C403B;
    /* Soft Black */
    --text-secondary: #6B7068;
    /* Muted Green-Grey */

    --border-color: #E8E6DE;
    --shadow-soft: 0 4px 20px -2px rgba(99, 126, 96, 0.1);

    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-number: 'Outfit', 'Inter', sans-serif;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header */
header {
    background-color: var(--bg-color);
    /* Blend with body */
    padding: 20px;
    border-bottom: none;
}

.header-inner {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-search {
    flex: 1;
    display: flex;
    max-width: 700px;
    background: var(--card-bg);
    border-radius: 50px;
    /* Fully rounded pill shape */
    padding: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
}

.header-search input {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    outline: none;
    font-size: 1rem;
    color: var(--text-primary);
}

.header-search button {
    padding: 0 25px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
}

.header-search button:hover {
    background-color: var(--primary-hover);
}

/* Nav Ribbon - Integrated Navigation Bar Style */
.nav-ribbon {
    background: var(--card-bg);
    display: flex;
    justify-content: center;
    padding: 0;
    margin: 20px auto 0;
    max-width: 1100px;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    position: sticky;
    top: 20px;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 15px 10px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    border-radius: 0;
    position: relative;
    border-right: 1px solid var(--border-color);
}

.nav-btn:last-child {
    border-right: none;
}

.nav-btn:hover {
    background-color: rgba(99, 126, 96, 0.03);
    color: var(--primary-color);
}

.nav-btn.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
}

.nav-btn.active::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--accent-color);
    box-shadow: 0 -2px 6px rgba(217, 136, 94, 0.4);
}

/* Main Content with Fade-in animation */
main {
    max-width: 1100px;
    margin: 20px auto 40px;
    background: var(--card-bg);
    min-height: 600px;
    box-shadow: var(--shadow-soft);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.tab-content {
    display: none;
    padding: 0;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spinner for Loading States */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(99, 126, 96, 0.2);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.tab-content.active {
    display: block;
}

.toolbar {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toolbar-title {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-title::before {
    content: "🌱";
    /* Nature icon */
}

/* Table Styles - Clean & Airy */
.data-table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    table-layout: auto;
    /* Allow content to define width */
}

.data-table th {
    padding: 18px 25px;
    text-align: center;
    /* Changed from left to center */
    background-color: #FAFAF8;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    font-family: var(--font-heading);
    white-space: nowrap;
}

.data-table td {
    padding: 16px 12px;
    text-align: center;
    /* Changed from left to center */
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: #F4F6F4;
    /* Very light green hover */
    cursor: pointer;
}

/* Columns */
.city-cell {
    width: 48px;
    white-space: nowrap;
}

.title-cell {
    min-width: 120px;
    font-weight: 500;
}

.time-cell {
    font-family: 'SF Mono', Consolas, monospace;
    color: var(--text-secondary);
    font-size: 0.9em;
    white-space: nowrap;
    /* Prevent date wrapping */
}

.dt-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}

.dt-year {
    display: block;
    font-size: 0.8em;
    opacity: 0.8;
}

.dt-date {
    display: block;
    font-weight: 600;
}

.dt-time {
    display: block;
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* Specific for Co-Cast "Other Casts" which should stretch */
.cast-cell {
    min-width: 200px;
    max-width: 320px;
    /* Limit width to force wrap */
    white-space: normal;
    /* Allow wrapping */
}

.cast-list-layout {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* 3 items per row */
    gap: 4px 8px;
    /* row-gap 4px, col-gap 8px */
    width: 100%;
}

.cast-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    font-size: 0.9em;
}

/* Detail View */
#detail-view {
    padding: 40px;
}

.hidden {
    display: none !important;
}

.back-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 30px;
    border-radius: 50px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.back-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Co-Cast Panel & Rows */
.cocast-panel {
    max-width: 600px;
    margin: 40px auto;
    background: #fff;
    padding: 35px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(99, 126, 96, 0.08);
}

.cocast-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.cast-name-input {
    width: 100%;
    padding: 15px 20px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    font-size: 1rem;
    transition: border 0.3s, box-shadow 0.3s;
    box-sizing: border-box;
    background: #FAFAF8;
}

.cast-name-input:focus {
    border-color: var(--primary-color);
    background: #FFF;
    box-shadow: 0 0 0 4px rgba(99, 126, 96, 0.1);
}

.cocast-row .cast-name-input {
    flex: 1;
    margin-bottom: 0;
}

.circle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: var(--bg-color);
    color: var(--text-secondary);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.circle-btn:hover {
    transform: scale(1.1);
}

.circle-btn.add {
    background: rgba(99, 126, 96, 0.1);
    color: var(--primary-color);
}

.circle-btn.add:hover {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 126, 96, 0.2);
}

.circle-btn.remove {
    background: rgba(0, 0, 0, 0.05);
    color: #999;
}

.circle-btn.remove:hover {
    background: #e74c3c;
    color: white;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.2);
}

.add-input-btn-legacy {
    /* Backup of old style if needed */
    background: transparent;
    border: 1px dashed #CCC;
    color: #888;
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
    flex: 1;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.search-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    cursor: pointer;
    font-weight: 600;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(99, 126, 96, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.search-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 126, 96, 0.3);
}

.search-btn:active {
    transform: translateY(0);
}

/* Removed Badge Styles per request */

/* Input Panel Date */
.input-panel {
    text-align: center;
    padding: 50px;
}

.input-panel label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 15px;
}

.input-panel input {
    padding: 12px 20px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
}

.input-panel input:focus {
    border-color: var(--primary-color);
}

/* 售罄行样式 */
.data-table tr.sold-out {
    background-color: #F5F5F5;
    color: #999;
    opacity: 0.75;
}

.data-table tr.sold-out td {
    text-decoration: line-through;
}

/* 跳转定位的高亮动画 */
@keyframes highlightPulse {
    0% {
        background-color: transparent;
        transform: scale(1);
    }

    10% {
        background-color: #fff3cd;
        transform: scale(1.01);
        box-shadow: 0 0 15px rgba(255, 243, 205, 0.8);
    }

    100% {
        background-color: transparent;
        transform: scale(1);
    }
}

.highlight-row {
    animation: highlightPulse 2.5s ease-out;
    z-index: 10;
    position: relative;
}

.data-table tr.sold-out:hover {
    background-color: #EDEDED;
    opacity: 0.85;
}

/* 移动端响应式设计 - 保持表格布局，支持横向滚动 */
@media (max-width: 768px) {

    /* 导航栏优化 */
    .nav-ribbon {
        margin: 10px;
        border-radius: 12px;
        position: relative;
        top: 0;
    }

    .nav-btn {
        font-size: 0.85rem;
        padding: 12px 5px;
        border-right: 1px solid var(--border-color);
    }

    /* 主容器 */
    main {
        margin: 10px;
        border-radius: 12px;
    }

    /* 工具栏 */
    .toolbar {
        padding: 15px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .toolbar-title {
        font-size: 1rem;
    }

    .column-config {
        flex-wrap: wrap;
        width: 100%;
        font-size: 0.85rem;
    }

    /* 表格容器 - 支持横向滚动 */
    #hlq-list-container,
    #detail-content>div,
    #date-results,
    #cast-results {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 表格本身保持正常布局 */
    .data-table {
        font-size: 0.8rem;
        min-width: 100%;
        width: max-content;
        /* 允许表格根据内容宽度扩展 */
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
        font-size: 0.8rem;
        white-space: nowrap;
        /* 防止文字换行 */
    }

    /* 标题和重要文字可以换行 */
    .data-table .title-cell {
        white-space: normal;
        max-width: 150px;
        font-size: 0.85rem;
    }

    .data-table .cast-cell {
        white-space: normal;
        max-width: 200px;
        font-size: 0.75rem;
    }

    /* 详情页 */
    #detail-view {
        padding: 20px 15px;
    }

    #detail-view h2 {
        font-size: 1.3rem;
    }

    /* 日期时间容器在移动端保持横向布局，但缩小间距 */
    .dt-container {
        gap: 6px;
    }

    .dt-year,
    .dt-date,
    .dt-time {
        font-size: 0.75rem;
    }

    /* Co-Cast面板 */
    .cocast-panel {
        margin: 20px 10px;
        padding: 20px 15px;
    }

    .cocast-panel h3 {
        font-size: 1.2rem;
    }

    .cocast-actions {
        flex-direction: column;
        gap: 10px;
    }

    .add-input-btn,
    .search-btn {
        width: 100%;
    }

    /* 输入面板 */
    .input-panel {
        padding: 30px 15px;
    }

    .input-panel label {
        font-size: 1rem;
    }

    /* 城市筛选下拉框 */
    #city-filter {
        font-size: 0.85rem;
        padding: 4px 8px;
    }
}

/* 更小屏幕（手机竖屏）的进一步优化 */
@media (max-width: 480px) {

    /* 隐藏导航图标节省空间 */
    .nav-btn .material-icons {
        display: none;
    }

    .nav-btn {
        font-size: 0.8rem;
        padding: 10px 5px;
    }

    .nav-btn:last-child {
        border-right: none;
    }

    /* 表格进一步缩小 */
    .data-table {
        font-size: 0.75rem;
    }

    .data-table th,
    .data-table td {
        padding: 4px 2px;
        /* Extremely tight */
        font-size: 0.7rem;
    }

    .title-cell {
        max-width: 60px;
        /* Aggressive width limit */
        font-size: 0.75rem;
        line-height: 1.1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cast-cell {
        max-width: 70px;
        /* Aggressive width limit */
        font-size: 0.65rem;
        line-height: 1.1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stock-cell {
        white-space: nowrap;
        font-size: 0.65rem;
        padding: 4px 0;
        text-align: center;
        max-width: 40px;
        overflow: hidden;
    }

    /* Co-Cast面板 */
    .cocast-panel {
        padding: 15px 10px;
    }

    .cocast-panel h3 {
        font-size: 1.1rem;
    }

    /* 按钮 */
    .back-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    /* 工具栏标题 */
    .toolbar-title {
        font-size: 0.95rem;
    }
}

/* 平板横屏优化 */
@media (min-width: 769px) and (max-width: 1024px) {
    main {
        margin: 15px;
    }

    .data-table th,
    .data-table td {
        padding: 16px 20px;
        font-size: 0.9rem;
    }
}

/* --- Search Button Animations --- */

/* 1. 点击瞬间闪烁 */
@keyframes button-flash {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }

    50% {
        transform: scale(1.05);
        filter: brightness(1.5);
        box-shadow: 0 0 20px var(--primary-color);
    }

    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

.btn-flash {
    animation: button-flash 0.4s ease-out;
}

/* 2. 周期性跷跷板摇晃 (每2s动一下) */
@keyframes seesaw-burst {

    0%,
    80%,
    100% {
        transform: rotate(0deg);
    }

    85% {
        transform: rotate(3deg);
    }

    90% {
        transform: rotate(-3deg);
    }

    95% {
        transform: rotate(1.5deg);
    }
}

.btn-searching {
    background-color: #f1c40f !important;
    /* 亮黄色 */
    color: #333 !important;
    box-shadow: 0 4px 15px rgba(241, 196, 15, 0.4) !important;
    animation: seesaw-burst 2s infinite ease-in-out;
}

.btn-searching .material-icons {
    animation: spin 1s linear infinite;
}

.cancel-text {
    display: block;
    font-size: 0.75rem;
    opacity: 0.8;
    margin-top: 2px;
    font-weight: normal;
}

/* 3. 成功/结束后的回弹 */
@keyframes bounce-in {
    0% {
        transform: scale(0.9);
    }

    50% {
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.98);
    }

    100% {
        transform: scale(1);
    }
}

.btn-success-back {
    animation: bounce-in 0.5s ease-out;
}

/* --- Autocomplete Styles --- */

/* Input Wrap for Autocomplete Positioning */
.input-wrapper {
    position: relative;
    flex: 1;
}

/* Autocomplete Dropdown */
.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: #fff;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    /* Hidden by default */
}

.autocomplete-item {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: background 0.1s;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.highlight {
    background: rgba(99, 126, 96, 0.08);
    color: var(--primary-color);
}

.autocomplete-match {
    font-weight: bold;
    color: var(--primary-color);
}

/* --- Co-Cast Summary Card --- */
/* --- Co-Cast Summary Card (Minimalist Iteration) --- */
.cocast-summary-minimal {
    margin-bottom: 20px;
    padding: 24px;
    /* 极为淡雅的品牌色背景，接近纸张质感 */
    background: rgba(99, 126, 96, 0.04);
    /* 极细的边框 */
    border: 1px solid rgba(99, 126, 96, 0.15);
    border-radius: 12px;
    position: relative;
    /* 移除显眼阴影，保持扁平 */
    box-shadow: none;
}

.cocast-display-header {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    letter-spacing: -0.01em;
    padding-bottom: 15px;
    border-bottom: 1px dashed rgba(99, 126, 96, 0.2);
}

.cocast-stats-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cocast-stat-card {
    display: flex;
    flex-direction: column;
    padding: 2px 0;
    /* 移除卡片背景，让信息直接流淌 */
    background: transparent;
    border: none;
}

.cocast-stat-card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.cocast-show-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.cocast-show-count {
    color: var(--primary-color);
    font-weight: 700;
    /* 移除背景块，保留纯文字强调 */
    background: transparent;
    padding: 0;
    font-size: 1rem;
}

.cocast-role-row {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding-left: 0;
    /* 移除缩进，更对齐 */
    display: flex;
    align-items: center;
    margin-top: 4px;
}

.cocast-role-count {
    opacity: 0.6;
    margin-left: auto;
    font-size: 0.8rem;
    font-family: monospace;
    /* 数字等宽对齐 */
}

.cocast-footer {
    display: flex;
    justify-content: center;
    /* 居中 */
    margin-top: 25px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.4;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* --- Co-Cast Page Enhancements --- */

.cocast-header-styled {
    text-align: center;
    padding: 40px 20px 10px;
}

.cocast-summary-result {
    margin-bottom: 20px;
    padding: 15px;
    background: #f0f7ff;
    border-radius: 12px;
    border-left: 5px solid var(--primary-color);
}

.cocast-control-panel {
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f7ff;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.cocast-control-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.cocast-result-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.cocast-filters {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 0.9em;
    flex-wrap: wrap;
}

.cocast-filter-label {
    cursor: pointer;
    white-space: nowrap;
}

.cocast-filter-separator {
    color: #ccc;
    font-size: 0.8em;
}

.cocast-year-select {
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background: white;
}

.cocast-sort-btn {
    padding: 3px 10px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
}

/* Mobile Optimizations for Cocast */
@media (max-width: 480px) {
    .cocast-header-styled {
        padding: 20px 15px 5px;
        /* Reduced header padding */
    }

    .cocast-summary-result {
        padding: 12px;
        margin-bottom: 15px;
        border-radius: 8px;
    }

    .cocast-control-panel {
        padding: 10px 8px;
        /* Tighter padding */
        margin-bottom: 10px;
        border-radius: 8px;
    }

    .cocast-control-flex {
        gap: 8px;
        flex-direction: column;
        align-items: flex-start;
    }

    .cocast-result-title {
        font-size: 1rem;
        margin-bottom: 5px;
        width: 100%;
        border-bottom: 1px dashed rgba(0, 0, 0, 0.05);
        padding-bottom: 5px;
    }

    .cocast-filters {
        gap: 8px;
        font-size: 0.8em;
        width: 100%;
        justify-content: space-between;
    }

    .cocast-filters label {
        display: flex;
        align-items: center;
    }

    .cocast-year-select,
    .cocast-sort-btn {
        padding: 2px 5px;
        font-size: 0.85em;
    }

    .cocast-filter-separator {
        display: none;
        /* Hide separator on mobile to save space */
    }
}

.cast-role-tiny {
    font-size: 0.75em;
    color: var(--text-secondary);
    margin-left: 4px;
    opacity: 0.8;
}