/* CSS variables for consistent theme management */
:root {
    --bg-main: #f4f6f9;
    --bg-card: #ffffff;
    --border-color: #e6eef4;
    --border-focus: #3b82f6;
    
    /* Text colors */
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    /* Elegant blue accents */
    --blue-50: #eff6ff;
    --blue-100: #dbeafe;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --blue-800: #1e40af;
    --blue-900: #1e3a8a;
    
    /* Accent details */
    --green-50: #f0fdf4;
    --green-600: #16a34a;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
    --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.06), 0 4px 12px -2px rgba(15, 23, 42, 0.04);
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    
    /* Font sizes */
    --font-family: 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.5;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.app-container {
    max-width: 1200px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Header Styles */
.app-header {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    width: 36px;
    height: 36px;
    color: var(--blue-700);
}

.header-titles h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--blue-900);
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.header-titles .subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.theme-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--blue-50);
    color: var(--blue-700);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--blue-500);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.5; }
}

/* Layout Grid */
.app-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    gap: 24px;
}

.card-budget {
    grid-column: 1;
    grid-row: 1;
}

.card-params {
    grid-column: 1;
    grid-row: 2;
}

.card-products {
    grid-column: 1;
    grid-row: 3;
}

.card-combo-list {
    grid-column: 2;
    grid-row: 1;
}

.card-results-summary {
    grid-column: 2;
    grid-row: 2 / span 2;
    display: flex;
    flex-direction: column;
}

.card-results-summary .card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Card design system */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

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

.card-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.text-primary { color: var(--blue-600) !important; }
.text-accent { color: var(--blue-900) !important; }

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 20px;
}

.card-body.no-padding {
    padding: 0;
}

/* Large Input Area (Coins budget) */
.card-budget {
    border-top: 4px solid var(--blue-600);
}

.input-large-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-large-wrapper input {
    width: 100%;
    padding: 16px 20px;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--blue-900);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--blue-50);
    transition: all 0.2s ease;
    outline: none;
}

.input-large-wrapper input:focus {
    border-color: var(--blue-500);
    background-color: #ffffff;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.input-large-wrapper .input-unit {
    position: absolute;
    right: 20px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--blue-800);
    pointer-events: none;
}

.input-action-group {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-action-group .input-large-wrapper {
    flex: 1;
}

.btn-calculate {
    padding: 0 24px;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    background-color: var(--blue-600);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-calculate:hover {
    background-color: var(--blue-700);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.budget-tip {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 10px;
    line-height: 1.5;
}

/* Basic Parameter Inputs */
.row-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input {
    padding: 10px 14px;
    font-size: 0.95rem;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
}

.input-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

/* Product Manage Table */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    text-align: left;
}

.data-table th {
    background-color: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

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

.data-table tbody tr:hover {
    background-color: #fdfefe;
}

/* Buttons */
.btn-primary {
    background-color: var(--blue-600);
    color: #ffffff;
    border: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background-color: var(--blue-700);
}

.btn-icon {
    width: 14px;
    height: 14px;
}

.btn-secondary {
    background-color: #ffffff;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: var(--text-muted);
}

.btn-text-edit, .btn-text-delete {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-text-edit:hover {
    background-color: var(--blue-50);
    color: var(--blue-600);
}

.btn-text-delete:hover {
    background-color: #fef2f2;
    color: #dc2626;
}

.action-icon {
    width: 16px;
    height: 16px;
}

/* Results Section */
.card-results-summary {
    border-top: 4px solid var(--blue-800);
}

.results-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-box {
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
}

.stat-box.main-stat {
    grid-column: span 2;
    background-color: var(--blue-50);
    border-color: rgba(59, 130, 246, 0.15);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-box.main-stat .stat-value {
    font-size: 2rem;
}

/* Progress bar visualization */
.utilization-bar-container {
    margin-bottom: 24px;
}

.utilization-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.utilization-bar-track {
    height: 10px;
    background-color: #e2e8f0;
    border-radius: 5px;
    overflow: hidden;
}

.utilization-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue-500), var(--blue-800));
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Procurement list */
.combo-details-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.combo-details-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--blue-900);
}

.combo-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 4px;
}

.combo-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    transition: all 0.2s ease;
}

.combo-item:hover {
    border-color: var(--blue-500);
    background-color: var(--blue-50);
}

.combo-item-left {
    display: flex;
    flex-direction: column;
}

.combo-item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.combo-item-cost {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.combo-item-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.combo-item-qty {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--blue-900);
}

.combo-item-profit {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--green-600);
}

/* Financial Breakdown */
.financial-breakdown {
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.finance-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.finance-row span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

/* Rankings Section (At bottom) */
.app-rankings {
    grid-column: span 2;
}

.card-rankings {
    border-top: 4px solid var(--blue-900);
}

.ranking-desc {
    font-size: 0.78rem;
    color: var(--text-secondary);
    background-color: #f8fafc;
    padding: 6px 12px;
    border-radius: 4px;
}

.ranking-table th.highlight-col {
    background-color: var(--blue-50);
    color: var(--blue-900);
    font-weight: 700;
}

.ranking-table td.highlight-col {
    background-color: rgba(59, 130, 246, 0.03);
    color: var(--blue-900);
    font-weight: 700;
    font-size: 0.95rem;
}

/* Star Rating indicator */
.star-rating {
    display: flex;
    gap: 2px;
    color: #fbbf24;
}

.star-rating svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Modal form designs */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.3);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: #ffffff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.modal-overlay.open .modal-content {
    transform: translateY(0);
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--blue-900);
}

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 50%;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background-color: #f1f5f9;
    color: var(--text-primary);
}

.close-icon {
    width: 20px;
    height: 20px;
}

#productForm {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-group input {
    padding: 10px 14px;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
}

.form-group input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 12px;
}

/* Empty UI messages */
.empty-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 24px;
}

/* Highlight row for best item in ranking */
.ranking-table tbody tr.best-rank-row {
    background-color: rgba(37, 99, 235, 0.02);
}

.ranking-table tbody tr.best-rank-row td {
    font-weight: 500;
}

/* Responsive adjustment */
@media (max-width: 968px) {
    .app-main {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    
    .card-budget {
        order: 1;
    }
    
    .card-combo-list {
        order: 2;
    }
    
    .card-results-summary {
        order: 3;
    }
    
    .card-params {
        order: 4;
    }
    
    .card-products {
        order: 5;
    }
    
    .app-rankings {
        grid-column: span 1;
    }
}

/* Explanation card styling at bottom */
.app-explanation {
    grid-column: span 2;
}

.card-explanation h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--blue-900);
    margin-bottom: 10px;
}

.card-explanation p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.card-explanation ul {
    padding-left: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Precise mobile browser adaptations (screen width <= 600px) */
@media (max-width: 600px) {
    body {
        padding: 8px;
        background-color: #f8fafc;
    }
    
    .app-container {
        gap: 12px;
    }
    
    .app-header {
        padding: 12px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .logo-area {
        gap: 10px;
    }
    
    .header-titles h1 {
        font-size: 1.15rem;
    }
    
    .header-titles .subtitle {
        font-size: 0.75rem;
    }
    
    .card-header {
        padding: 12px 14px;
    }
    
    .card-body {
        padding: 14px;
    }
    
    .input-action-group {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
    }
    
    .input-action-group .input-large-wrapper {
        flex: 1;
        min-width: 0;
    }
    
    .input-large-wrapper input {
        padding: 10px 52px 10px 12px;
        font-size: 1.1rem;
        border-radius: var(--radius-sm);
    }
    
    .input-large-wrapper .input-unit {
        right: 12px;
        font-size: 0.82rem;
    }
    
    .btn-calculate {
        padding: 0 16px;
        font-size: 0.95rem;
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }
    
    .row-inputs {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .results-stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-box.main-stat {
        grid-column: span 1;
    }
    
    .stat-box.main-stat .stat-value {
        font-size: 1.6rem;
    }
    
    /* Adapt tables to fit horizontally on tiny screens without overflowing */
    .data-table th, .data-table td {
        padding: 10px 8px;
        font-size: 0.82rem;
    }
    
    .ranking-table th, .ranking-table td {
        padding: 8px 4px;
        font-size: 0.76rem;
    }
    
    .combo-item {
        padding: 10px 12px;
    }
    
    .combo-item-qty {
        font-size: 0.95rem;
    }
    
    .combo-item-name {
        font-size: 0.88rem;
    }
    
    .app-explanation {
        grid-column: span 1;
    }
}

