:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(148, 163, 184, 0.1);
    --highlight-color: #10b981;
    --error-color: #ef4444;
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem;
    overflow-x: hidden;
    position: relative;
}

/* Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 10s infinite ease-in-out;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: #4f46e5;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 300px;
    height: 300px;
    background: #ec4899;
    bottom: -50px;
    right: -50px;
    animation-delay: 2s;
}

.blob-3 {
    width: 250px;
    height: 250px;
    background: #10b981;
    top: 40%;
    left: 60%;
    animation-delay: 4s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(30px, -30px);
    }
}

/* Container */
.container {
    width: 100%;
    max-width: 1000px;
    z-index: 1;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

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

/* Control Bar */
.control-bar {
    display: flex;
    align-items: center;
    /* Center vertically */
    gap: 1.5rem;
    margin-bottom: 2rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--glass-shadow);
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    flex: 1;
}

.control-bar .input-group {
    margin-bottom: 0;
}

.control-bar .btn-primary {
    width: auto;
    padding: 0.75rem 2rem;
    height: 100%;
    /* Fill height */
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    align-self: stretch;
    /* Stretch to match grid height if needed */
}

/* Result Section */
.result-section {
    margin-bottom: 2rem;
}

.result-group {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.result-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.result-group h3 {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 1rem;
    font-weight: 500;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.result-item .label {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.result-item .value {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-main);
}

.result-item.highlight .value {
    color: var(--highlight-color);
}

.result-item.highlight-profit .value {
    color: #3b82f6;
}

/* Cards */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--glass-shadow);
    transition: transform 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

/* Input Section */
.input-group {
    /* margin-bottom: 1.5rem; This is now handled by control-bar context */
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

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

.input-wrapper input {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

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

.input-wrapper .unit {
    position: absolute;
    right: 1rem;
    color: var(--text-muted);
}

.btn-primary {
    /* width: 100%; This is now handled by control-bar context */
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    border-radius: 8px;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.btn-primary:hover {
    opacity: 0.9;
}

/* Matrix Wrapper for Controls */
.matrix-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.matrix-container {
    overflow-x: auto;
    max-width: 100%;
    position: relative;
}

/* Add Buttons */
.add-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.col-btn {
    min-width: 40px;
    margin-left: 4px;
    border-radius: 4px;
}

.row-btn {
    width: 100%;
    height: 40px;
    border-radius: 4px;
    margin-top: 4px;
}

/* Editable Headers */
.matrix-cell.header-cell {
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--text-main);
    flex-direction: row;
    position: relative;
    min-width: 140px;
}

.header-input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-main);
    text-align: center;
    font-size: 0.9rem;
    padding: 4px;
    border-radius: 4px;
}

.header-input:hover,
.header-input:focus {
    border-color: var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

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

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.7rem;
    color: var(--error-color);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.matrix-cell.header-cell:hover .delete-btn {
    opacity: 1;
}

/* Total Cells */
.matrix-cell.total-cell {
    background: rgba(255, 255, 255, 0.02);
    border-left: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-main);
    flex-direction: column;
    gap: 4px;
}

.matrix-row.total-row .matrix-cell {
    background: rgba(255, 255, 255, 0.02);
    border-top: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-main);
}

.matrix-cell .stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.matrix-cell .stat-value {
    font-size: 0.9rem;
    color: var(--accent-color);
}

.matrix-header-row {
    display: flex;
}

.matrix-cell {
    flex: 1;
    min-width: 140px;
    /* Wider for two inputs */
    padding: 0.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    position: relative;
}

.matrix-cell.header-cell {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--text-main);
    flex-direction: row;
    /* Headers are single line */
}

.corner {
    background: rgba(255, 255, 255, 0.02);
}

.matrix-row {
    display: flex;
}

.matrix-cell .input-row {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 2px 4px;
}

.matrix-cell label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-right: 4px;
}

.matrix-cell input {
    width: 60px;
    background: transparent;
    border: none;
    color: var(--text-main);
    text-align: right;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 2px;
}

.matrix-cell input:focus {
    outline: none;
    color: var(--primary-color);
}

.matrix-cell input.people-input {
    color: var(--accent-color);
    /* Highlight people count */
    font-weight: 600;
}

/* Remove active state styling as it's less relevant now */
.matrix-cell.active {
    background: transparent;
    border-color: var(--border-color);
    box-shadow: none;
}