:root {
    --primary-color: #00c853;
    /* Fresh Green */
    --primary-dark: #009624;
    --accent-color: #ff6d00;
    /* Orange for discounts */
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --text-main: #ffffff;
    --text-muted: #b0bec5;
    --danger: #ff5252;
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-main);
    min-height: 100vh;
    padding: 2rem;
    line-height: 1.6;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #4caf50, #81c784);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Glassmorphism Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

.controls-section {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: flex;
    gap: 2rem;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: var(--glass-shadow);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

input[type="number"],
input[type="text"],
select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input[type="number"]:focus,
select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 200, 83, 0.2);
}

/* Product Grid */
.category-section {
    margin-bottom: 3rem;
}

.category-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    padding-left: 1rem;
    border-left: 4px solid var(--primary-color);
    color: var(--text-main);
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.product-card {
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    overflow: visible;
    /* 改为visible，允许内容溢出 */
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.2);
}

.product-card.updated-today {
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 15px rgba(255, 109, 0, 0.15);
}

.product-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.spec-input {
    background: transparent;
    border: none;
    border-bottom: 1px dashed var(--text-muted);
    color: var(--text-muted);
    font-size: 0.85rem;
    width: 60px;
    text-align: center;
    padding: 0 2px;
    margin-left: 0.5rem;
}

.spec-input:focus {
    outline: none;
    border-bottom: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.product-name {
    font-size: 1.25rem;
    font-weight: 700;
}

.product-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Center vertically */
    margin-bottom: 1rem;
    gap: 0.5rem;
    overflow: visible;
    /* 确保内容不被裁剪 */
}

.edit-name-btn {
    cursor: pointer;
    font-size: 1rem;
    /* Slightly larger */
    opacity: 0.7;
    /* More visible by default */
    transition: opacity 0.2s;
    padding: 4px;
    /* Larger hit area */
    z-index: 10;
    /* Ensure it's on top */
    position: relative;
    /* Needed for z-index */
}

.edit-name-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    /* Feedback on hover */
}

.competitor-price-tag {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 160px;
    /* 再次增加宽度 */
    overflow: visible;
    /* 确保内容不被裁剪 */
}

.competitor-price-row {
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: visible;
    /* 确保内容不被裁剪 */
}

.competitor-price-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-main);
    font-size: 0.9rem;
    width: 80px !important;
    /* 增加到80px */
    min-width: 80px;
    /* 添加最小宽度 */
    text-align: center;
    padding: 2px 4px;
    margin: 0 2px;
}

.competitor-price-input:focus {
    outline: none;
    border-bottom-color: var(--primary-color);
}

.price-change-indicator {
    font-size: 0.75rem;
    margin-top: 2px;
    font-weight: normal;
}

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

.price-display {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 12px;
    margin-top: 1rem;
}

.main-price-input {
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--primary-color);
    color: var(--primary-color);
    font-size: 1.8rem;
    font-weight: 800;
    width: 120px;
    text-align: right;
    padding: 0 0.5rem;
    outline: none;
    transition: all 0.3s ease;
}

.main-price-input:focus {
    border-bottom-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.05);
}

.unit-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 0.5rem;
}

.margin-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.8rem;
}

.profit-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.competitor-margin-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.profit-positive {
    background: rgba(0, 200, 83, 0.2);
    color: #69f0ae;
}

.profit-negative {
    background: rgba(255, 82, 82, 0.2);
    color: #ff8a80;
}

/* Discount Timeline */
.discount-timeline {
    margin-top: 1.5rem;
    border-top: 1px solid var(--card-border);
    padding-top: 1rem;
}

.timeline-title {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.timeline-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    text-align: center;
}

.time-slot {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 0.2rem;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.time-slot:hover {
    background: rgba(255, 255, 255, 0.08);
}

.time-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.discount-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-color);
}

.preview-match {
    color: #4ade80;
}

.preview-nomatch {
    color: #ef4444;
    opacity: 0.7;
}

.preview-arrow {
    margin: 0 0.5rem;
    color: var(--text-muted);
}

/* Price Change Indicator */
.price-change-indicator {
    font-size: 0.8rem;
    margin-left: 0.5rem;
    font-weight: bold;
    display: inline-block;
}

.price-up {
    color: #ef4444;
}

/* Red for price rise */
.price-down {
    color: #4ade80;
}

/* Green for price fall */

/* History List Styles */
.history-list-container {
    margin-top: 1.5rem;
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid var(--card-border);
    padding-top: 1rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9rem;
}

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

.delete-history-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.5rem;
    transition: color 0.2s;
}

.delete-history-btn:hover {
    color: #ef4444;
}

.discount-profit {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.discount-profit.profit-negative {
    color: #ff8a80;
}

.discount-profit.profit-positive {
    color: #69f0ae;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #1a1a2e;
    margin: 10% auto;
    padding: 2rem;
    border: 1px solid var(--card-border);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.close-modal {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover {
    color: var(--text-main);
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.action-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.primary-btn:hover {
    background: var(--primary-dark);
}

/* Discount Settings Styles */
.discount-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-right: 0.5rem;
}

.discount-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    border-radius: 8px;
}

.discount-item input {
    width: 100px;
    padding: 0.5rem;
}

.delete-btn {
    background: rgba(255, 82, 82, 0.2);
    color: #ff8a80;
    border: 1px solid rgba(255, 82, 82, 0.3);
    border-radius: 6px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.delete-btn:hover {
    background: rgba(255, 82, 82, 0.4);
}

/* Chart Modal Styles */
.chart-container {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
}

.history-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.2rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.history-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.product-card {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Responsive */
@media (max-width: 768px) {
    .product-grid {
        grid-template-columns: 1fr;
    }

    .controls-section {
        flex-direction: column;
        align-items: stretch;
    }

    .timeline-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* List View Styles */
.product-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.product-grid.list-view .product-card {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1fr 0.5fr;
    align-items: center;
    padding: 0.5rem 1rem;
    gap: 1rem;
    margin-bottom: 0;
}

.product-grid.list-view .product-header {
    margin-bottom: 0;
    align-items: center;
}

.product-grid.list-view .product-name {
    font-size: 1rem;
}

.product-grid.list-view .competitor-price-tag {
    font-size: 0.8rem;
    padding: 0.1rem 0.4rem;
}

.product-grid.list-view .input-row {
    display: contents;
    /* Remove grid wrapper */
}

.product-grid.list-view .control-group {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.product-grid.list-view .control-group label {
    display: none;
    /* Hide labels in list view */
}

.product-grid.list-view input[type="number"] {
    padding: 0.3rem;
    font-size: 0.9rem;
    width: 80px;
}

.product-grid.list-view .price-display {
    margin-top: 0;
    padding: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.product-grid.list-view .main-price-input {
    font-size: 1.1rem;
    width: 80px;
    border-bottom: 1px solid var(--primary-color);
}

.product-grid.list-view .margin-info {
    margin-top: 0;
    flex-direction: row;
    gap: 1rem;
}

.product-grid.list-view .competitor-margin-badge {
    display: none;
    /* Hide competitor margin in list view for space */
}

.product-grid.list-view .discount-timeline {
    display: none;
    /* Hide timeline in list view */
}

.product-grid.list-view .unit-label {
    display: none;
}

.product-grid.list-view .history-btn {
    font-size: 1rem;
}

/* Table View Styles */
.table-header {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1fr 0.5fr;
    gap: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: var(--text-muted);
    text-align: center;
}

.product-grid.table-view {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.product-grid.table-view .product-card {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr 1fr 1fr 0.5fr;
    align-items: center;
    padding: 0.4rem 1rem;
    gap: 1rem;
    margin-bottom: 0;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.02);
}

.product-grid.table-view .product-card:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: none;
    box-shadow: none;
}

.product-grid.table-view .product-header {
    margin-bottom: 0;
    align-items: center;
}

.product-grid.table-view .product-name {
    font-size: 0.95rem;
}

.product-grid.table-view .input-row {
    display: contents;
}

.product-grid.table-view .control-group {
    flex-direction: row;
    align-items: center;
    justify-content: center;
}

.product-grid.table-view .control-group label {
    display: none;
}

.product-grid.table-view input[type="number"] {
    padding: 0.2rem;
    font-size: 0.9rem;
    width: 70px;
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
}

.product-grid.table-view input[type="number"]:hover,
.product-grid.table-view input[type="number"]:focus {
    background: rgba(0, 0, 0, 0.2);
    border-color: var(--card-border);
}

.product-grid.table-view .price-display {
    margin-top: 0;
    padding: 0;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-grid.table-view .main-price-input {
    font-size: 1rem;
    width: 70px;
    border-bottom: none;
    text-align: center;
}

.product-grid.table-view .margin-info {
    margin-top: 0;
    flex-direction: row;
    justify-content: center;
}

.product-grid.table-view .competitor-margin-badge {
    display: none;
}

.product-grid.table-view .discount-timeline,
.product-grid.table-view .unit-label {
    display: none;
}

/* Editable Competitor Price */
.competitor-price-input {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 80px;
    min-width: 60px;
    font-size: 0.85rem;
    text-align: center;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
    padding: 0;
}

.competitor-price-input:focus {
    border-bottom: 1px solid var(--primary-color);
    color: var(--text-main);
    outline: none;
}

/* Calculator Icon */
.calc-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem;
    opacity: 0.6;
    transition: all 0.2s;
    margin-left: 0.2rem;
}

.calc-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Cost Modal Specifics */
.close-cost-modal {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-cost-modal:hover {
    color: var(--text-main);
}