/* ベーススタイル */
:root {
    --primary-color: #4285f4;
    --secondary-color: #34a853;
    --accent-color: #fbbc05;
    --danger-color: #ea4335;
    --text-color: #333;
    --light-text: #757575;
    --background-color: #f5f5f5;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --spacing: 16px;
    --header-height: 90px;
    --footer-height: 50px;
}

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

body {
    font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* アプリコンテナ */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ヘッダー */
header {
    background-color: var(--primary-color);
    color: white;
    height: var(--header-height);
    display: flex;
    flex-direction: column;
    padding: 0 var(--spacing);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

header h1 {
    font-size: 1.2rem;
    margin: 10px 0 5px;
    text-align: center;
}

nav {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.nav-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    padding: 5px 10px;
    cursor: pointer;
    transition: 0.3s;
    flex: 1;
    text-align: center;
}

.nav-btn:hover, .nav-btn.active {
    color: white;
    border-bottom: 3px solid white;
}

/* メインコンテンツ */
main {
    flex: 1;
    padding: var(--header-height) 0 var(--footer-height);
    overflow-y: auto;
}

.screen {
    display: none;
    padding: var(--spacing);
}

.screen.active {
    display: block;
}

/* ボタンスタイル */
button {
    cursor: pointer;
    border-radius: var(--radius);
    padding: 10px 15px;
    font-weight: 500;
    transition: background-color 0.3s, transform 0.2s;
}

button:active {
    transform: scale(0.98);
}

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

.primary-btn:hover {
    background-color: #3b78e7;
}

.secondary-btn {
    background-color: #f1f3f4;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.secondary-btn:hover {
    background-color: #e8eaed;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border: none;
    background-color: var(--card-bg);
    color: var(--text-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    margin-bottom: 10px;
    font-weight: bold;
}

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

.danger:hover {
    background-color: #d32f2f;
}

.back-btn {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--primary-color);
    padding: 5px 0;
}

.back-btn::before {
    content: "←";
    margin-right: 5px;
}

/* ホーム画面 */
.dashboard {
    padding: var(--spacing);
}

.dashboard h2 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

.stats {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

.stat-card {
    flex: 1;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    font-size: 1rem;
    color: var(--light-text);
    margin-bottom: 10px;
}

.stat-card p {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* スキャン画面 */
.scan-options {
    margin-bottom: 20px;
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
}

.option-group {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

.option-group:last-child {
    margin-bottom: 0;
}

.option-group label {
    width: 100px;
    margin-right: 10px;
}

.option-group select {
    flex: 1;
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.camera-container {
    position: relative;
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden;
    background-color: #000;
    aspect-ratio: 4/3;
    margin-bottom: 20px;
}

#camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

#card-frame {
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Standard business card aspect ratio is approximately 3.5:2 (landscape) or 2:3.5 (portrait) */
#card-frame.landscape {
    width: 70%;
    aspect-ratio: 1.75;  /* 3.5:2 aspect ratio */
}

#card-frame.portrait {
    height: 70%;
    aspect-ratio: 0.57;  /* 2:3.5 aspect ratio */
}

.camera-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    position: relative;
    z-index: 20;
}

.capture-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.camera-icon {
    font-size: 30px;
    display: block;
}

.capture-button::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: 2px solid white;
}

.scan-preview {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
    margin-top: 20px;
}

.preview-image-container {
    width: 100%;
    margin: 15px 0;
    text-align: center;
}

#preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.ocr-results {
    background-color: #f9f9f9;
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: 15px;
}

.scan-actions {
    display: flex;
    gap: 10px;
}

.scan-actions button {
    flex: 1;
}

/* 一覧画面 */
.search-bar {
    display: flex;
    margin-bottom: 15px;
}

#search-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius) 0 0 var(--radius);
    font-size: 1rem;
}

#search-btn {
    border-radius: 0 var(--radius) var(--radius) 0;
    border: none;
    background-color: var(--primary-color);
    color: white;
    padding: 0 15px;
}

.filter-options {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 15px;
}

#sort-by {
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.card-item {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.card-image-preview {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-bottom: 1px solid var(--border-color);
}

.card-brief-info {
    padding: var(--spacing);
}

.card-brief-info h3 {
    font-size: 1.1rem;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-brief-info p {
    color: var(--light-text);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.card-date {
    font-size: 0.8rem;
    color: var(--light-text);
    text-align: right;
    margin-top: 5px;
}

/* 詳細画面 */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.detail-actions {
    display: flex;
    gap: 10px;
}

.card-detail {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
}

.card-images {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 10px;
}

.card-image {
    flex: 1;
    min-width: 200px;
    text-align: center;
}

.card-image h4 {
    margin-bottom: 10px;
    color: var(--light-text);
}

.card-image img {
    max-width: 100%;
    max-height: 250px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-info, .card-notes {
    margin-top: 25px;
}

.card-info h3, .card-notes h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

#detail-info {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 10px;
}

.info-label {
    font-weight: bold;
    color: var(--light-text);
}

.note-item {
    background-color: #f9f9f9;
    border-radius: var(--radius);
    padding: var(--spacing);
    margin-bottom: 10px;
}

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

.note-date {
    font-size: 0.8rem;
    color: var(--light-text);
}

/* メモ内のマークダウンスタイル */
.note-text {
    line-height: 1.5;
}

.note-text h1 {
    font-size: 1.5rem;
    margin: 15px 0 10px;
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.note-text h2 {
    font-size: 1.3rem;
    margin: 15px 0 10px;
    color: var(--secondary-color);
}

.note-text h3 {
    font-size: 1.1rem;
    margin: 12px 0 8px;
}

.note-text ul {
    padding-left: 20px;
    margin: 10px 0;
}

.note-text li {
    margin-bottom: 5px;
}

.note-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.note-text a:hover {
    text-decoration: underline;
}

.note-text p {
    margin: 8px 0;
}

.note-text strong {
    font-weight: bold;
}

.note-text em {
    font-style: italic;
}

.confidence-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: white;
}

.confidence-high {
    background-color: var(--secondary-color);
}

.confidence-medium {
    background-color: var(--accent-color);
}

.confidence-low {
    background-color: var(--danger-color);
}

#add-note {
    margin-top: 10px;
}

/* リサーチ画面 */
.research-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

#card-select {
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    min-width: 200px;
}

.research-form {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

#research-query {
    width: 100%;
    height: 100px;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
    resize: none;
    font-family: inherit;
}

.research-results {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

#results-container {
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: var(--radius);
    margin-top: 10px;
    white-space: pre-wrap;
    max-height: 400px; /* 高さを増やして表示領域を拡大 */
    overflow-y: auto;
}

/* リサーチ結果の箇条書きスタイル */
.research-list {
    list-style-type: disc;
    padding-left: 20px;
    margin: 0;
}

.research-item {
    margin-bottom: 12px;
    line-height: 1.5;
    text-align: left;
}

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

/* リサーチ結果のフルテキスト表示 */
.research-full-text {
    white-space: pre-wrap;
    line-height: 1.5;
}

/* リサーチコンテンツ全体 */
.research-content {
    margin-bottom: 15px;
}

.confidence-rating {
    background-color: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing);
    box-shadow: var(--shadow);
}

.rating-controls {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.rating-controls label {
    margin-right: 10px;
    width: 80px;
}

#confidence-rating {
    flex: 1;
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    z-index: 200;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.modal-content {
    background-color: var(--card-bg);
    margin: 15% auto;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 500px;
    position: relative;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
}

.modal h2 {
    margin-bottom: 20px;
    color: var(--primary-color);
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    font-family: inherit;
}

.form-group textarea {
    height: 100px;
    resize: vertical;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* フッター */
footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 15px var(--spacing);
    height: var(--footer-height);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

footer p {
    font-size: 0.8rem;
}

/* リサーチ中の表示 */
.research-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    animation: fadeIn 0.3s ease;
}

.research-loading-content {
    background-color: var(--primary-color);
    padding: 30px 40px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.research-loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid white;
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
    margin: 20px auto;
}

.research-loading-message {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.research-loading-submessage {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* レスポンシブ対応 */
@media (max-width: 600px) {
    .stats {
        flex-direction: column;
    }
    
    .card-images {
        flex-direction: column;
    }
    
    #detail-info {
        grid-template-columns: 1fr;
    }
    
    .info-label {
        margin-bottom: -8px;
    }
}

/* アニメーション */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.screen.active {
    animation: fadeIn 0.3s ease;
}

/* PWA関連のスタイル */
/* オフライン通知 */
.offline-notification {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    background-color: var(--accent-color);
    color: #333;
    padding: 10px var(--spacing);
    z-index: 150;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    animation: slideDown 0.3s ease-out;
    transition: opacity 0.5s, transform 0.5s;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.offline-notification.fade-out {
    opacity: 0;
    transform: translateY(-100%);
}

.offline-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.offline-icon {
    margin-right: 10px;
    font-size: 1.2rem;
}

/* PWAインストールボタン */
#install-pwa {
    background-color: var(--secondary-color);
    color: white;
    display: none; /* 初期状態では非表示 */
    position: fixed;
    bottom: calc(var(--footer-height) + 10px);
    right: 10px;
    padding: 12px 15px;
    border-radius: var(--radius);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 90;
    cursor: pointer;
}

#install-pwa:hover {
    background-color: #2d9348;
}

/* PWAスタンドアロンモード時のスタイル調整 */
@media (display-mode: standalone) {
    body {
        overscroll-behavior: none; /* オーバースクロール時の振る舞いを制御 */
    }
    
    header {
        padding-top: env(safe-area-inset-top); /* iPhoneのノッチ対応 */
    }
    
    footer {
        padding-bottom: env(safe-area-inset-bottom); /* iPhoneのホームバー対応 */
    }
}

/* ローディングインジケーター */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--light-text);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    margin-left: 10px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* OCR処理中のローディングスピナー */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

/* 空の状態・エラー状態 */
.empty-state, .error-state {
    padding: 20px;
    text-align: center;
    background-color: #f9f9f9;
    border-radius: var(--radius);
    color: var(--light-text);
}

.error-state {
    border-left: 4px solid var(--danger-color);
}

/* QRコードの結果表示 */
.qr-result {
    margin-top: 10px;
    padding: 10px;
    background-color: #e8f0fe;
    border-radius: var(--radius);
    border-left: 3px solid var(--primary-color);
}

/* OCRステータス表示 */
.ocr-status {
    margin: 15px 0;
    padding: 12px;
    border-radius: var(--radius);
    text-align: center;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.ocr-ready {
    background-color: #e6f4ea;
    color: #137333;
    border-left: 4px solid var(--secondary-color);
}

.ocr-error {
    background-color: #fce8e6;
    color: #c5221f;
    border-left: 4px solid var(--danger-color);
}

#ocr-data.ocr-ready, #ocr-data.ocr-error {
    padding: 10px;
    border-radius: var(--radius);
    margin-bottom: 10px;
}
