/* 모바일 전용 리밸런싱 계산기 - 2026 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #667eea;
    --primary-dark: #5568d3;
    --secondary-color: #764ba2;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --warning-color: #ed8936;
    --text-dark: #2d3748;
    --text-gray: #718096;
    --text-light: #a0aec0;
    --bg-white: #ffffff;
    --bg-light: #f7fafc;
    --border-color: #e2e8f0;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    min-height: 100vh;
    padding: 0;
    line-height: 1.6;
    color: var(--text-dark);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 터치 스크롤 개선 */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* 모바일 전용 고정 너비 컨테이너 */
.container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    background: transparent;
}

/* PWA 설치 배너 */
.install-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: var(--bg-white);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 16px;
    z-index: 10000;
    opacity: 0;
    transform: translateY(100px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.install-banner.show {
    transform: translateY(0);
    opacity: 1;
}

.install-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.install-text {
    flex: 1;
    min-width: 0;
}

.install-text strong {
    display: block;
    color: var(--text-dark);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.install-text p {
    color: var(--text-gray);
    font-size: 0.85rem;
    margin: 0;
}

.btn-install {
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-install:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.btn-dismiss {
    padding: 4px;
    background: transparent;
    color: var(--text-light);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    flex-shrink: 0;
}

.btn-dismiss:active {
    color: var(--text-gray);
}

/* 헤더 */
header {
    background: var(--bg-white);
    padding: 20px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 1.5rem;
    color: var(--text-dark);
    margin-bottom: 4px;
}

header .subtitle {
    font-size: 0.9rem;
    color: var(--text-gray);
    margin: 0;
}

/* 카드 섹션 */
.card {
    background: var(--bg-white);
    margin: 0;
    padding: 20px 16px;
    border-bottom: 8px solid var(--bg-light);
}

.card h2 {
    font-size: 1.25rem;
    color: var(--text-dark);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 포트폴리오 설정 */
.portfolio-setup {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

/* 입력 그룹 */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.input-group input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    color: var(--text-dark);
    background: var(--bg-white);
    transition: all 0.2s;
    /* 터치 최적화 - auto로 변경 */
    touch-action: auto;
    -webkit-appearance: none;
    appearance: none;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-group input:active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

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

.input-hint {
    font-size: 0.8rem;
    color: var(--text-gray);
    margin-top: -2px;
}

/* 검색 컨테이너 */
.search-container {
    position: relative;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 2px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 280px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
    display: none;
    box-shadow: var(--shadow-md);
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 14px;  /* 12px → 14px */
    min-height: 44px;  /* ✅ 최소 터치 영역 보장 */
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--bg-light);
    /* ✅ 터치 최적화 */
    touch-action: manipulation;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

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

.search-result-item:active {
    background: var(--bg-light);
}

.search-result-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 2px;
}

.search-result-details {
    font-size: 0.8rem;
    color: var(--text-gray);
}

.search-result-code {
    color: var(--primary-color);
    font-weight: 500;
}

/* 자산 목록 */
.assets-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.asset-item {
    background: var(--bg-light);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.asset-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.asset-info {
    flex: 1;
    min-width: 0;
}

.asset-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px;
    word-break: break-word;
}

.asset-code-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.asset-code {
    font-size: 0.85rem;
    color: var(--text-gray);
    font-family: 'Courier New', monospace;
}

.asset-code-input {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: 'Courier New', monospace;
    color: var(--text-dark);
    background: var(--bg-white);
    width: 120px;
}

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

.asset-ratio {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

.btn-delete {
    padding: 6px 12px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    /* 터치 최적화 */
    touch-action: manipulation;
}

.btn-delete:active {
    background: #e53e3e;
    transform: scale(0.95);
}

/* 총 비율 */
.total-ratio {
    margin-top: 16px;
    padding: 14px;
    background: var(--bg-light);
    border-radius: 10px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dark);
}

/* 금액 입력 */
.amount-inputs {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.total-amount-display {
    padding: 16px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 12px;
    text-align: center;
    color: white;
}

.total-amount-display .label {
    display: block;
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 4px;
}

.total-amount-display .amount {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

/* 버튼 */
.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    /* 터치 최적화 */
    touch-action: manipulation;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--success-color);
    color: white;
}

.btn-secondary:active {
    background: #38a169;
    transform: scale(0.98);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:active {
    background: #e53e3e;
    transform: scale(0.98);
}

.btn-info {
    background: var(--text-gray);
    color: white;
}

.btn-info:active {
    background: #4a5568;
    transform: scale(0.98);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 리밸런싱 결과 - 카드 형태 */
.rebalancing-result {
    margin-top: 20px;
}

.result-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.result-card {
    background: var(--bg-white);
    border: 2px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--bg-light);
}

.card-header h3 {
    font-size: 1.1rem;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.card-code {
    font-size: 0.85rem;
    color: var(--text-gray);
    font-family: 'Courier New', monospace;
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg-light);
}

.card-row.input-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;  /* 간격 증가 */
    padding: 14px 0;  /* 패딩 증가 */
}

.card-row:last-child {
    border-bottom: none;
}

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

.card-value {
    font-size: 0.95rem;
    color: var(--text-dark);
    font-weight: 600;
    text-align: right;
}

.card-value-highlight {
    font-size: 1.1rem;
    font-weight: 700;
    text-align: right;
}

.card-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.card-input {
    flex: 1;
    padding: 14px 16px;  /* 터치 영역 확대 */
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;  /* 글자 크기 증가 */
    color: var(--text-dark);
    background: var(--bg-white);
    /* 터치 최적화 */
    touch-action: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    /* 모바일 입력 개선 */
    -webkit-user-select: text;
    user-select: text;
    /* iOS 줄 바꿈 방지 */
    white-space: nowrap;
    /* 포커스 시 부드러운 전환 */
    transition: border-color 0.2s, box-shadow 0.2s;
}

.card-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);  /* 포커스 표시 강화 */
    background: #ffffff;  /* 포커스 시 배경 밝게 */
    /* iOS 포커스 유지 */
    -webkit-tap-highlight-color: transparent;
}

.card-input:active {
    border-color: var(--primary-color);
    /* 터치 시 즐각 피드백 */
    transform: scale(0.995);
    transition: transform 0.1s;
}

.btn-fetch-price-mini {
    padding: 10px 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    /* 터치 최적화 */
    touch-action: manipulation;
}

.btn-fetch-price-mini:active {
    background: var(--primary-dark);
    transform: scale(0.95);
}

.btn-fetch-price-mini:disabled {
    background: var(--text-light);
    cursor: not-allowed;
}

.highlight-row {
    background: var(--bg-light);
    margin: 0 -16px;
    padding: 12px 16px;
    border-radius: 8px;
    border-bottom: none !important;
}

.positive {
    color: var(--success-color);
}

.negative {
    color: var(--danger-color);
}

/* 알림 */
.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-top: 16px;
    font-size: 0.9rem;
}

.alert-success {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

.alert-info {
    background: #bee3f8;
    color: #2c5282;
    border: 1px solid #90cdf4;
}

.alert-warning {
    background: #feebc8;
    color: #7c2d12;
    border: 1px solid #fbd38d;
}

.alert-danger {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #fc8181;
}

/* 빈 상태 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-gray);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 0.95rem;
}

/* 로딩 상태 */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 스크롤바 스타일 */
.search-results::-webkit-scrollbar {
    width: 6px;
}

.search-results::-webkit-scrollbar-track {
    background: var(--bg-light);
}

.search-results::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 3px;
}

.search-results::-webkit-scrollbar-thumb:hover {
    background: var(--text-gray);
}

/* 터치 피드백 개선 - 입력 필드는 제외 */
button, .search-result-item, .asset-item {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 입력 필드는 텍스트 선택 허용 */
input, textarea {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* 입력 필드 줌 방지 (iOS) */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select,
    textarea,
    input {
        font-size: 16px !important;
    }
}

/* 안전 영역 지원 (노치 대응) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    header,
    .card {
        padding-left: max(16px, calc(16px + env(safe-area-inset-left)));
        padding-right: max(16px, calc(16px + env(safe-area-inset-right)));
    }
}

/* 하단 여백 (모바일 하단 제스처 대응) */
.card:last-of-type {
    padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
}
