/* Apple-style Design */

:root {
    /* Apple Colors */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #fafafa;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --text-tertiary: #b0b0b5;

    --accent-blue: #007aff;
    --accent-blue-hover: #0062cc;
    --accent-green: #34c759;
    --accent-red: #ff3b30;
    --accent-orange: #ff9500;
    --accent-purple: #af52de;

    --separator: rgba(0, 0, 0, 0.08);
    --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-large: 0 8px 32px rgba(0, 0, 0, 0.12);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 780px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 40px 0 32px;
}

header h1 {
    font-size: 34px;
    font-weight: 600;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.help-btn {
    width: 32px;
    height: 32px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--separator);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.help-btn:hover {
    background-color: var(--accent-blue);
    color: white;
    transform: scale(1.05);
}

/* Panel */
.panel {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    margin-bottom: 24px;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.panel:hover {
    box-shadow: var(--shadow-medium);
}

.panel-header {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    background: linear-gradient(to bottom, var(--bg-secondary), var(--bg-tertiary));
    border-bottom: 1px solid var(--separator);
}

.panel-header h2 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.toggle-icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.panel-content {
    padding: 24px;
}

.panel-content.hidden {
    display: none;
}

/* Form */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.1px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 12px 16px;
    font-size: 17px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.form-group input::placeholder {
    color: var(--text-tertiary);
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2386868b'%3E%3Cpath d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

.form-group select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px;
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 12px;
}

.radio-label {
    flex: 1;
    padding: 14px 20px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 2px solid transparent;
}

.radio-label:hover {
    background-color: var(--bg-secondary);
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

.radio-label input[type="radio"]:checked + span {
    color: var(--text-primary);
}

.radio-label span {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.radio-label:has(input[type="radio"]:checked) {
    background-color: rgba(0, 122, 255, 0.08);
    border-color: var(--accent-blue);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.2px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--accent-blue);
    border: 1px solid var(--separator);
}

.btn-secondary:hover {
    background-color: var(--bg-tertiary);
}

.btn-danger {
    background-color: rgba(255, 59, 48, 0.08);
    color: var(--accent-red);
}

.btn-danger:hover {
    background-color: rgba(255, 59, 48, 0.12);
}

/* BMR Display */
.bmr-display {
    margin-top: 20px;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.08), rgba(52, 199, 89, 0.03));
    border-radius: var(--radius-md);
    border: 1px solid rgba(52, 199, 89, 0.2);
}

.bmr-display.hidden {
    display: none;
}

.bmr-display p {
    font-size: 14px;
    color: var(--text-secondary);
}

.bmr-display strong {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent-green);
}

/* Daily Log */
.daily-log {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-subtle);
    margin-bottom: 24px;
    padding: 28px;
}

.daily-log h2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.daily-log h3 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.1px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

/* Sections */
.food-section,
.exercise-section {
    margin-bottom: 28px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--separator);
}

.food-section:last-child,
.exercise-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Food Search */
.food-search {
    position: relative;
    margin-bottom: 12px;
}

.food-search input {
    width: 100%;
    padding: 14px 18px;
    font-size: 17px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.food-search input:focus {
    outline: none;
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.food-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-large);
    z-index: 100;
    opacity: 0;
    transform: translateY(-8px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.food-results.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.food-results.hidden {
    display: none;
}

.food-results::-webkit-scrollbar {
    width: 6px;
}

.food-results::-webkit-scrollbar-track {
    background: transparent;
}

.food-results::-webkit-scrollbar-thumb {
    background-color: var(--text-tertiary);
    border-radius: 3px;
}

.food-results-item {
    padding: 14px 18px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid var(--separator);
}

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

.food-results-item:hover {
    background-color: var(--bg-tertiary);
}

.food-results-item .name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.food-results-item .calories {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Food Input */
.food-input {
    display: flex;
    gap: 12px;
    align-items: center;
}

.food-input input {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    font-size: 17px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.food-input input:focus {
    outline: none;
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.food-input span.unit {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Exercise Input */
.exercise-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background-color: var(--bg-secondary);
}

.tab-btn.active {
    background-color: var(--accent-blue);
    color: white;
}

.exercise-input-container {
    display: none;
}

.exercise-input-container.active {
    display: block;
}

.exercise-input {
    display: flex;
    gap: 12px;
    align-items: center;
}

.exercise-input input[type="text"] {
    flex: 2;
    min-width: 150px;
    padding: 12px 16px;
    font-size: 17px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.exercise-input input[type="number"] {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    font-size: 17px;
    border: none;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.exercise-input input:focus {
    outline: none;
    background-color: var(--bg-secondary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1);
}

.exercise-input span.unit {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* METs Input */
.mets-input {
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.mets-input .form-group {
    margin-bottom: 16px;
}

.mets-input .form-group label {
    font-size: 14px;
}

.mets-input .form-group select,
.mets-input .form-group input {
    font-size: 16px;
}

.mets-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin: 16px 0;
    border: 1px solid var(--separator);
}

.mets-preview .preview-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.mets-preview .preview-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent-blue);
}

/* Added Items */
.added-items {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.items-list {
    min-height: 120px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
}

.items-list .empty {
    color: var(--text-tertiary);
    font-size: 14px;
    text-align: center;
    margin: 32px 0;
}

.items-list .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.items-list .item:last-child {
    margin-bottom: 0;
}

.items-list .item:hover {
    transform: translateX(2px);
}

.items-list .item-info {
    flex: 1;
}

.items-list .item-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.items-list .item-detail {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-word;
}

.items-list .delete-btn {
    width: 28px;
    height: 28px;
    background-color: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-left: 12px;
}

.items-list .delete-btn:hover {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--accent-red);
    transform: scale(1.1);
}

/* Results */
.results {
    background: linear-gradient(135deg, var(--bg-secondary), #fafbfc);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-medium);
    margin-bottom: 24px;
    padding: 28px;
}

.results h2 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--separator);
    transition: background-color 0.2s ease;
}

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

.result-item .label {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-item .value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    font-feature-settings: 'tnum';
}

.result-item .unit {
    font-size: 14px;
    color: var(--text-tertiary);
    font-weight: 500;
    margin-left: 4px;
}

.result-item.highlight {
    padding-top: 20px;
    margin-top: 8px;
    border-top: 2px solid var(--separator);
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.05), transparent);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    border-bottom: none;
    transition: all 0.3s ease;
}

.result-item.highlight .value {
    font-size: 32px;
    font-weight: 700;
    transition: color 0.3s ease;
}

/* Calorie Deficit Colors */
.result-item.highlight.positive {
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.08), rgba(52, 199, 89, 0.02));
    border-top-color: var(--accent-green);
}

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

.result-item.highlight.negative {
    background: linear-gradient(135deg, rgba(255, 59, 48, 0.08), rgba(255, 59, 48, 0.02));
    border-top-color: var(--accent-red);
}

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

.result-item.highlight.neutral {
    background: linear-gradient(135deg, rgba(255, 149, 0, 0.08), rgba(255, 149, 0, 0.02));
    border-top-color: var(--accent-orange);
}

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

/* Actions */
.actions {
    text-align: center;
    padding: 16px 0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-xl);
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-large);
    animation: modalIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.close-btn {
    width: 32px;
    height: 32px;
    background-color: var(--bg-tertiary);
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

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

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: var(--text-tertiary);
    border-radius: 3px;
}

.modal-body section {
    margin-bottom: 24px;
}

.modal-body section:last-child {
    margin-bottom: 0;
}

.modal-body h3 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.2px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.modal-body h4 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.1px;
    margin-top: 16px;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.modal-body p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.modal-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

.modal-body code {
    display: block;
    padding: 12px 16px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
    font-size: 13px;
    color: var(--text-primary);
    margin: 8px 0;
    overflow-x: auto;
}

/* Modal Table */
.modal-body table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 12px;
}

.modal-body table th,
.modal-body table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--separator);
    font-size: 14px;
    text-align: left;
}

.modal-body table th {
    background-color: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
}

.modal-body table td {
    color: var(--text-secondary);
}

.modal-body table tr:last-child td {
    border-bottom: none;
}

.modal-body table tr:first-child th:first-child {
    border-top-left-radius: var(--radius-sm);
}

.modal-body table tr:first-child th:last-child {
    border-top-right-radius: var(--radius-sm);
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 16px;
    }

    header {
        padding: 24px 0 20px;
    }

    header h1 {
        font-size: 28px;
    }

    .added-items {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .food-input,
    .exercise-input {
        flex-direction: column;
        align-items: stretch;
    }

    .food-input input,
    .exercise-input input {
        width: 100%;
    }

    .food-input .unit,
    .exercise-input .unit {
        position: static;
        margin-left: 4px;
        margin-right: auto;
    }

    .btn {
        width: 100%;
    }

    .panel-content,
    .daily-log,
    .results {
        padding: 20px;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #1c1c1e;
        --bg-tertiary: #2c2c2e;
        --text-primary: #f5f5f7;
        --text-secondary: #86868b;
        --text-tertiary: #636366;
        --separator: rgba(255, 255, 255, 0.1);
    }
}
