/* === シンプル血圧記録 - sbpr スタイルシート === */

:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --border-radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

/* === ヘッダー === */
.app-header {
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.2em;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-left: 30px;
}

/* === 左上固定: ページ先頭へ戻るボタン === */
.scroll-to-top {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 9999;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(37, 99, 235, 0.85);
    color: white;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s, transform 0.1s;
}

.scroll-to-top:hover {
    background: rgba(37, 99, 235, 1);
}

.scroll-to-top:active {
    transform: translateY(1px);
}

.scroll-to-top:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.scroll-to-top-icon {
    width: 18px;
    height: 18px;
    display: block;
    pointer-events: none;
}

/* === 右上固定: バージョン情報 === */
.app-info-display {
    position: fixed;
    top: 6px;
    right: 10px;
    z-index: 9999;
    font-size: 0.65em;
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
    line-height: 1.3;
    pointer-events: none;
    white-space: nowrap;
}

/* === 印刷非表示 === */
.no-print {
    /* 印刷時は @media print で非表示にする */
}

/* === 更新バナー === */
.update-banner {
    background: var(--warning-light);
    color: #92400e;
    border-bottom: 1px solid #fbbf24;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 0.85em;
    font-weight: 500;
    position: sticky;
    top: 44px;
    z-index: 99;
}

.update-banner .btn {
    background: #f59e0b;
    color: white;
    padding: 4px 12px;
    font-size: 0.8em;
}

.update-banner .btn:hover {
    background: #d97706;
}

.update-banner-close {
    background: none;
    border: none;
    color: #92400e;
    cursor: pointer;
    font-size: 1.1em;
    padding: 2px 6px;
    opacity: 0.6;
    line-height: 1;
}

.update-banner-close:hover {
    opacity: 1;
}

/* === タブナビゲーション === */
.tab-nav {
    display: flex;
    background: white;
    border-bottom: 2px solid var(--gray-200);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-nav button {
    flex: 1;
    min-width: 80px;
    padding: 12px 16px;
    border: none;
    background: none;
    font-size: 0.9em;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-nav button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-nav button:hover:not(.active) {
    color: var(--gray-700);
    background: var(--gray-50);
}

/* === タブコンテンツ === */
.tab-content {
    display: none;
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.tab-content.active {
    display: block;
}

/* === カード === */
.card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--gray-200);
}

/* === フォーム === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 4px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 1em;
    color: var(--gray-800);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-group input[type="number"] {
    -moz-appearance: textfield;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.input-unit {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-unit input {
    flex: 1;
}

.input-unit .unit {
    font-size: 0.85em;
    color: var(--gray-500);
    white-space: nowrap;
}

/* === 3段階セレクタ === */
.level-selector {
    display: flex;
    gap: 4px;
}

.level-btn {
    flex: 1;
    padding: 6px 4px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: white;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-600);
    text-align: center;
    white-space: nowrap;
}

.level-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-400);
}

.level-btn.selected {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
    font-weight: 600;
}

/* === ボタン === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    gap: 6px;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

.btn-danger:hover {
    background: #b91c1c;
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85em;
}

.btn-block {
    width: 100%;
}

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

/* === 記録一覧 === */
.record-list {
    list-style: none;
}

.record-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
    gap: 12px;
}

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

.record-bp-values {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 1.1em;
    font-weight: 700;
    min-width: 120px;
}

.record-bp-values .systolic {
    color: var(--danger);
}

.record-bp-values .separator {
    color: var(--gray-400);
    font-weight: 400;
}

.record-bp-values .diastolic {
    color: var(--primary);
}

.record-meta {
    flex: 1;
    min-width: 0;
}

.record-meta .datetime {
    font-size: 0.8em;
    color: var(--gray-500);
}

.record-meta .pulse {
    font-size: 0.85em;
    color: var(--gray-600);
}

.record-meta .memo {
    font-size: 0.8em;
    color: var(--gray-400);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.record-meta .extra-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.8em;
    color: var(--gray-500);
    margin-top: 2px;
}

.record-meta .extra-info span {
    white-space: nowrap;
}

.record-meta .classification {
    display: inline-block;
    font-size: 0.75em;
    padding: 1px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.record-actions {
    display: flex;
    gap: 4px;
}

.record-actions button {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    background: var(--gray-100);
    color: var(--gray-600);
    transition: background 0.2s;
}

.record-actions button:hover {
    background: var(--gray-200);
}

.record-actions button.delete-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* === 血圧分類カラー === */
.bp-normal { background: var(--success-light); color: var(--success); }
.bp-elevated { background: #e0f2fe; color: #0369a1; }
.bp-high-normal { background: var(--warning-light); color: #b45309; }
.bp-grade1 { background: #fed7aa; color: #c2410c; }
.bp-grade2 { background: #fecaca; color: #dc2626; }
.bp-grade3 { background: #fca5a5; color: #991b1b; }

/* === 統計カード === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-item {
    text-align: center;
    padding: 12px;
    background: var(--gray-50);
    border-radius: 6px;
}

.stat-item .stat-label {
    font-size: 0.75em;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-item .stat-value {
    font-size: 1.4em;
    font-weight: 700;
    color: var(--gray-800);
    margin-top: 2px;
}

.stat-item .stat-unit {
    font-size: 0.7em;
    color: var(--gray-400);
}

/* === グラフ === */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 300px;
}

.chart-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.chart-controls button {
    padding: 6px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 20px;
    background: white;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-600);
}

.chart-controls button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.chart-controls button:hover:not(.active) {
    background: var(--gray-100);
}

/* === 設定 === */
.setting-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--gray-100);
}

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

.setting-item h3 {
    font-size: 0.95em;
    font-weight: 600;
    margin-bottom: 8px;
}

.setting-item p {
    font-size: 0.85em;
    color: var(--gray-500);
    margin-bottom: 8px;
}

/* === 日付フィルタ === */
.filter-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.filter-row input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.9em;
}

.filter-row span {
    color: var(--gray-500);
    font-size: 0.9em;
}

/* === 空状態 === */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
}

.empty-state .icon {
    font-size: 3em;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.95em;
}

/* === メッセージ === */
.message {
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.9em;
    margin-bottom: 12px;
    display: none;
}

.message.show {
    display: block;
}

.message.success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid #86efac;
}

.message.error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fca5a5;
}

.message.info {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid #93c5fd;
}

/* === 確認ダイアログ === */
.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.confirm-overlay.show {
    display: flex;
}

.confirm-dialog {
    background: white;
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-md);
}

.confirm-dialog h3 {
    margin-bottom: 12px;
}

.confirm-dialog p {
    margin-bottom: 20px;
    color: var(--gray-600);
}

.confirm-dialog .btn-group {
    justify-content: flex-end;
}

/* === AI診断 === */
.ai-disclaimer {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.85em;
    color: #c2410c;
    line-height: 1.5;
}

.ai-chat-messages {
    max-height: 500px;
    overflow-y: auto;
    padding: 8px 0;
}

.ai-msg {
    margin-bottom: 12px;
    display: flex;
    gap: 8px;
}

.ai-msg.user {
    justify-content: flex-end;
}

.ai-msg.assistant {
    justify-content: flex-start;
}

.ai-msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9em;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg.user .ai-msg-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-msg.assistant .ai-msg-bubble {
    background: var(--gray-100);
    color: var(--gray-800);
    border-bottom-left-radius: 4px;
}

.ai-msg-label {
    font-size: 0.7em;
    color: var(--gray-400);
    margin-bottom: 2px;
}

.ai-msg.user .ai-msg-label {
    text-align: right;
}

.ai-input-area {
    border-top: 1px solid var(--gray-200);
    padding-top: 12px;
    margin-top: 8px;
}

.ai-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ai-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.95em;
    resize: vertical;
    min-height: 44px;
    font-family: inherit;
    color: var(--gray-800);
}

.ai-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.ai-input:disabled {
    background: var(--gray-50);
    color: var(--gray-400);
}

.ai-status {
    font-size: 0.8em;
    color: var(--gray-500);
    margin-bottom: 6px;
    min-height: 1.2em;
}

.ai-status.loading {
    color: var(--primary);
}

.ai-status.error {
    color: var(--danger);
}

.ai-msg-bubble .ai-streaming-cursor {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--gray-400);
    margin-left: 2px;
    animation: blink 0.8s infinite;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* === 提案質問ボタン === */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    max-width: 85%;
}

.ai-suggestion-btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--primary);
    border-radius: 20px;
    background: white;
    color: var(--primary);
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, transform 0.1s;
    text-align: left;
    line-height: 1.4;
}

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

.ai-suggestion-btn:active {
    transform: scale(0.97);
}

/* === レスポンシブ === */
@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1em;
    }

    .tab-content {
        padding: 12px;
    }

    .card {
        padding: 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-row-3 {
        grid-template-columns: 1fr 1fr;
    }

    .level-btn {
        font-size: 0.75em;
        padding: 5px 2px;
    }

    .record-item {
        flex-wrap: wrap;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* === 印刷対応 === */
@media print {
    .no-print {
        display: none !important;
    }

    .app-header,
    .tab-nav,
    .btn,
    .record-actions,
    .filter-row {
        display: none !important;
    }

    .tab-content {
        display: block !important;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid var(--gray-200);
    }
}
