/* ========================================
   家族カレンダー - スタイル
   ======================================== */

:root {
    --primary: #4A90D9;
    --primary-light: #E3F2FD;
    --bg: #F5F7FA;
    --white: #FFFFFF;
    --text: #333333;
    --text-light: #888888;
    --border: #E0E0E0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    padding-top: var(--safe-top);
    padding-bottom: calc(70px + var(--safe-bottom));
    min-height: 100dvh;
}

/* ---- ヘッダー ---- */
.header {
    background: var(--white);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-nav button {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--text);
}

.header-nav button:active {
    background: var(--primary-light);
}

.month-label {
    font-size: 16px;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
}

.btn-today {
    font-size: 12px !important;
    padding: 4px 10px !important;
    background: var(--primary) !important;
    color: white !important;
    border-radius: 16px !important;
}

.btn-settings {
    font-size: 22px !important;
}

/* ---- カレンダーグリッド ---- */
.calendar-container {
    padding: 8px;
}

.weekday-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    padding: 8px 0;
}

.weekday-header span:first-child {
    color: #E53935;
}

.weekday-header span:last-child {
    color: #1E88E5;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.calendar-day {
    background: var(--white);
    min-height: 70px;
    padding: 4px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}

.calendar-day:active {
    background: var(--primary-light);
}

.calendar-day.other-month {
    background: #FAFAFA;
}

.calendar-day.other-month .day-number {
    color: #CCC;
}

.calendar-day.today {
    background: var(--primary-light);
}

.calendar-day.today .day-number {
    background: var(--primary);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.day-number {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.calendar-day:nth-child(7n+1) .day-number {
    color: #E53935;
}

.calendar-day:nth-child(7n) .day-number {
    color: #1E88E5;
}

/* ---- 祝日 ---- */
.calendar-day.holiday {
    background: #FFF5F5;
}

.calendar-day.holiday .day-number {
    color: #E53935 !important;
}

.day-holiday {
    font-size: 8px;
    color: #E53935;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    margin-bottom: 1px;
}

.day-events {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.day-event {
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.day-event-more {
    font-size: 9px;
    color: var(--text-light);
    text-align: center;
}

/* ---- 日別詳細 ---- */
.day-detail {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 200;
    overflow-y: auto;
    padding-bottom: calc(20px + var(--safe-bottom));
}

.day-detail.active {
    display: block;
}

.day-detail-header {
    background: var(--white);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 10;
}

.day-detail-header h2 {
    font-size: 16px;
}

.day-detail-header button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

.day-events-list {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.event-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
}

.event-card-color {
    width: 4px;
    border-radius: 2px;
    align-self: stretch;
    flex-shrink: 0;
}

.event-card-body {
    flex: 1;
    min-width: 0;
}

.event-card-member {
    font-size: 11px;
    color: var(--text-light);
    margin-bottom: 2px;
}

.event-card-title {
    font-size: 15px;
    font-weight: 600;
}

.event-card-time {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

.event-card-desc {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
}

.event-card-actions {
    display: flex;
    gap: 8px;
}

.event-card-actions button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.no-events {
    text-align: center;
    color: var(--text-light);
    padding: 40px 0;
    font-size: 14px;
}

/* ---- モーダル ---- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
    align-items: flex-end;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85dvh;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-bottom));
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

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

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

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:active {
    opacity: 0.7;
}

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

.btn-danger {
    background: #E53935;
    color: white;
    margin-top: 8px;
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

/* ---- メンバー選択 ---- */
.member-select {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.member-chip {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    opacity: 0.5;
}

.member-chip.selected {
    opacity: 1;
    border-color: currentColor;
}

/* ---- 下部ナビバー ---- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-bottom));
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    z-index: 150;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 12px;
    font-size: 10px;
    color: var(--text-light);
    font-family: inherit;
}

.nav-btn .nav-icon {
    font-size: 24px;
}

.nav-btn.active {
    color: var(--primary);
}

/* ---- 音声入力ボタン ---- */
.voice-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.4);
    transition: all 0.2s;
    position: relative;
    bottom: 12px;
}

.voice-btn:active {
    transform: scale(0.95);
}

.voice-btn.recording {
    background: #E53935;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(229, 57, 53, 0.4); }
    50% { box-shadow: 0 4px 24px rgba(229, 57, 53, 0.6); }
}

/* ---- 設定ページ ---- */
.settings-page {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 200;
    overflow-y: auto;
    padding-bottom: calc(20px + var(--safe-bottom));
}

.settings-page.active {
    display: block;
}

.settings-section {
    padding: 12px 16px;
}

.settings-section h3 {
    font-size: 13px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.member-list-item {
    background: var(--white);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}

.member-list-item .member-icon {
    font-size: 28px;
}

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

.member-list-item .member-name {
    font-weight: 600;
}

.member-list-item .member-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

.member-list-item button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.add-member-btn {
    background: var(--white);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 14px;
    width: 100%;
    font-size: 14px;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
}

/* ---- 音声入力結果 ---- */
.voice-result {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    margin: 12px;
    box-shadow: var(--shadow);
}

.voice-text {
    font-size: 14px;
    color: var(--text);
    padding: 10px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 12px;
    min-height: 40px;
}

.voice-status {
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
    margin-bottom: 8px;
}

/* ---- OCR ---- */
.ocr-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.ocr-option-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 12px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--white);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    transition: all 0.2s;
}

.ocr-option-btn:active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.ocr-option-icon {
    font-size: 36px;
}

.ocr-preview {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
    margin: 8px 0;
    display: block;
}

.ocr-progress {
    margin: 12px 0;
    text-align: center;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
}

.ocr-result-edit {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: vertical;
    min-height: 80px;
    margin-bottom: 8px;
}

.ocr-result-edit:focus {
    border-color: var(--primary);
}

.ocr-parsed {
    background: var(--bg);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.8;
}

.ocr-parsed .parsed-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ocr-parsed .parsed-label {
    color: var(--text-light);
    min-width: 50px;
}

.ocr-parsed .parsed-value {
    font-weight: 600;
}

/* ---- 検索 ---- */
.btn-search {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
}

.btn-search:active {
    background: var(--primary-light);
}

.search-results {
    max-height: 60dvh;
    overflow-y: auto;
}

.search-results .event-card {
    margin-bottom: 8px;
}

.search-results .event-card-date {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 2px;
}

.search-highlight {
    background: #FFF176;
    border-radius: 2px;
    padding: 0 2px;
}

/* ---- フィルター ---- */
.filter-bar {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-bar::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    white-space: nowrap;
    opacity: 0.5;
    background: var(--white);
    transition: all 0.2s;
    font-family: inherit;
}

.filter-chip.active {
    opacity: 1;
    box-shadow: var(--shadow);
}

/* ---- レスポンシブ ---- */
@media (min-width: 500px) {
    .calendar-day {
        min-height: 90px;
        padding: 6px;
    }
    .day-number {
        font-size: 14px;
    }
    .day-event {
        font-size: 11px;
    }
    .modal {
        border-radius: 20px;
        margin: 20px;
    }
}

/* ---- ダークモードとか後で足す場合用 ---- */
@media (prefers-color-scheme: dark) {
    /* 将来対応 */
}

/* ---- ローディング ---- */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ---- トースト通知 ---- */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 500;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}
