/* === Base Reset & Variables === */
:root {
    --accent: #7C5CFF;
    --accent-light: #9B82FF;
    --accent-bg: #F0ECFF;
    --bg: #F5F5F7;
    --white: #FFFFFF;
    --text: #1A1A1A;
    --text-secondary: #8E8E93;
    --border: #E5E5EA;
    --success: #34C759;
    --danger: #FF3B30;
    --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --radius: 16px;
    --radius-sm: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
}

/* === Screen Management === */
.screen {
    display: none;
    padding: 16px;
    padding-bottom: 32px;
    min-height: 100vh;
    animation: fadeIn 0.2s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Welcome Screen === */
.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
    padding: 24px;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 24px;
}

.welcome-container h1 {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 16px;
}

.welcome-desc {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
}

.welcome-sub {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.welcome-note {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-style: italic;
}

/* === Buttons === */
.btn-primary {
    background: var(--accent);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    padding: 16px 32px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    max-width: 320px;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:active {
    transform: scale(0.97);
    background: var(--accent-light);
}

.btn-primary:disabled {
    background: var(--border);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.btn-full {
    max-width: 100%;
}

.btn-secondary {
    background: var(--white);
    color: var(--accent);
    border: 1.5px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-secondary:active {
    background: var(--accent-bg);
}

.btn-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white);
    border: none;
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(124, 92, 255, 0.4);
    transition: all 0.15s ease;
    z-index: 10;
}

.btn-fab:active {
    transform: scale(0.9);
}

.btn-send {
    background: var(--accent);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    width: 44px;
    height: 44px;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

/* === Menu Screen === */
.menu-header {
    text-align: center;
    padding: 16px 0;
}

.menu-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.user-stats {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.menu-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

.menu-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.menu-card:active {
    transform: scale(0.97);
}

.menu-card-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.menu-card-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.menu-card-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--accent);
    color: var(--white);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 24px;
}

.menu-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

.menu-footer {
    text-align: center;
    margin-top: 24px;
}

.link-subtle {
    color: var(--text-secondary);
    font-size: 14px;
    text-decoration: none;
}

.system-message {
    background: var(--accent-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 24px;
    font-size: 14px;
    line-height: 1.6;
}

.system-message-title {
    font-weight: 600;
    margin-bottom: 8px;
}

.system-message ol {
    padding-left: 20px;
    margin-bottom: 8px;
}

.system-message p {
    color: var(--text-secondary);
    font-size: 13px;
}

/* === Screen Header === */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 16px;
}

.screen-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.item-counter {
    font-size: 14px;
    color: var(--text-secondary);
}

/* === Wardrobe Grid === */
.wardrobe-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding-bottom: 80px;
}

.wardrobe-item {
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--card-shadow);
    position: relative;
}

.wardrobe-item img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.wardrobe-item-info {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wardrobe-item-category {
    font-size: 13px;
    color: var(--text-secondary);
}

.wardrobe-item-delete {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

/* === Modal === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.15s ease;
}

.modal-content {
    background: var(--white);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

.upload-preview {
    margin-bottom: 16px;
}

.upload-label {
    cursor: pointer;
}

.upload-placeholder {
    background: var(--bg);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    font-size: 15px;
    color: var(--text-secondary);
}

.upload-preview img {
    width: 100%;
    border-radius: var(--radius);
    max-height: 300px;
    object-fit: cover;
}

.category-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
}

.category-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.category-btn {
    background: var(--bg);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.category-btn.selected {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-actions button {
    flex: 1;
}

/* === Generation Form === */
.gen-form {
    padding-bottom: 32px;
}

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

.form-group label {
    display: block;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    background: var(--white);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
}

.form-input:focus {
    border-color: var(--accent);
}

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    background: var(--white);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.chip.selected {
    background: var(--accent);
    color: var(--white);
    border-color: var(--accent);
}

.rate-limit-info {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 12px;
}

/* === Loading === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(245, 245, 247, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    font-size: 17px;
    font-weight: 600;
}

.loading-sub {
    font-size: 14px !important;
    font-weight: 400 !important;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* === Results === */
.results-images {
    margin-bottom: 20px;
}

.result-card {
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--card-shadow);
    margin-bottom: 12px;
}

.result-label {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

.result-img {
    width: 100%;
    display: block;
}

.explanation-block {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-line;
    box-shadow: var(--card-shadow);
}

.result-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.result-actions button {
    flex: 1;
}

.result-actions .saved {
    background: var(--accent);
    color: var(--white);
}

/* === Refinement === */
.refinement-section {
    margin-bottom: 20px;
}

.refinement-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
}

.refinement-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip-refine {
    background: var(--accent-bg);
    color: var(--accent);
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.chip-refine:active {
    background: var(--accent);
    color: var(--white);
}

/* === Chat === */
.chat-section {
    margin-top: 16px;
    padding-bottom: 16px;
}

.chat-messages {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.chat-msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 15px;
    line-height: 1.5;
    max-width: 85%;
}

.chat-msg.user {
    background: var(--accent);
    color: var(--white);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    background: var(--white);
    box-shadow: var(--card-shadow);
    border-bottom-left-radius: 4px;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input-row .form-input {
    flex: 1;
}

/* === Saved Screen === */
.saved-list {
    padding-bottom: 32px;
}

.saved-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
}

.saved-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.saved-card-occasion {
    font-weight: 600;
    font-size: 15px;
}

.saved-card-date {
    font-size: 13px;
    color: var(--text-secondary);
}

.saved-card-tags {
    display: flex;
    gap: 6px;
}

.saved-tag {
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 15px;
}

/* === Utility === */
.hidden {
    display: none !important;
}
