/* 모바일 전용 화면을 기준으로 작성했습니다. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    background: #f5f7fa;
    color: #1f2937;
    font-size: 16px;
    padding-bottom: env(safe-area-inset-bottom);
}

/* 입력 요소는 16px 이상으로 유지해야 iOS에서 자동 확대가 안 생깁니다. */
input, select, textarea, button {
    font-size: 16px;
    font-family: inherit;
}

/* 로그인/설치 화면 */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}
.auth-box {
    background: #fff;
    padding: 28px 20px;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 420px;
}
.auth-box h1 { text-align: center; margin-bottom: 20px; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; }
.auth-box label { font-size: 14px; color: #555; }
.auth-box input, .auth-box button {
    padding: 14px;
    border-radius: 10px;
    border: 1px solid #ddd;
    width: 100%;
}
.auth-box button {
    background: #2563eb;
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    padding: 15px;
}
.auth-box button:active { background: #1d4ed8; }
.user-select { display: flex; gap: 10px; margin-bottom: 8px; }
.user-radio {
    flex: 1;
    text-align: center;
    padding: 14px 8px;
    border: 1px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
}
.user-radio input { display: none; }
.user-radio:has(input:checked) { border-color: #2563eb; background: #eff6ff; color: #2563eb; }
.msg-ok { color: #059669; }
.msg-err { color: #dc2626; }
.hint { font-size: 12px; color: #999; }
fieldset { border: 1px solid #eee; border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* 상단 바 */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top));
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.brand { font-weight: 700; font-size: 17px; }
.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.logout-link { color: #999; text-decoration: none; }

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px 16px 96px;
}

.card {
    background: #fff;
    border-radius: 14px;
    padding: 18px 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.card h2 { margin-top: 0; font-size: 17px; }
.card-header-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-header-row h2 { margin: 0; }
.view-select { padding: 8px 10px; border-radius: 8px; border: 1px solid #ddd; font-size: 13px; max-width: 130px; }

/* 하단 탭 네비게이션 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    background: #fff;
    border-top: 1px solid #eee;
    padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0 10px;
    text-decoration: none;
    color: #9ca3af;
    font-size: 12px;
}
.bottom-nav a .icon { font-size: 20px; }
.bottom-nav a.active { color: #2563eb; font-weight: 600; }

/* 날짜 네비게이션 */
.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.date-nav a.date-arrow {
    text-decoration: none;
    color: #2563eb;
    font-weight: 500;
    font-size: 13px;
    padding: 8px 6px;
    white-space: nowrap;
}
#date-picker { flex: 1; min-width: 0; padding: 10px 6px; border-radius: 8px; border: 1px solid #ddd; text-align: center; }
.today-btn { padding: 8px 12px; border: 1px solid #2563eb; border-radius: 8px; color: #2563eb; text-decoration: none; white-space: nowrap; font-size: 13px; }

/* 기간별 통합 카드 (혈당 + 섭취 기록) */
#period-cards { display: flex; flex-direction: column; gap: 14px; }
.period-card { border-radius: 14px; }
.period-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.period-header h2 { margin: 0; font-size: 17px; }
.glucose-inline { display: flex; gap: 8px; }
.glucose-input { width: 84px; padding: 10px; border-radius: 8px; border: 1px solid #ddd; text-align: center; }
.save-glucose-btn { padding: 10px 14px; border: none; border-radius: 8px; background: #2563eb; color: #fff; cursor: pointer; font-weight: 600; white-space: nowrap; }
.save-glucose-btn:active { background: #1d4ed8; }
.glucose-value { font-size: 13px; color: #059669; min-height: 16px; margin-bottom: 12px; }

.intake-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.intake-list li { display: flex; align-items: center; gap: 8px; background: #f9fafb; padding: 10px; border-radius: 8px; font-size: 14px; }
.intake-content { flex: 1; }
.del-intake-btn { border: none; background: none; color: #dc2626; cursor: pointer; font-size: 12px; padding: 4px 6px; flex-shrink: 0; }

.type-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.type-badge.sm { padding: 2px 6px; font-size: 10px; }
.type-meal { background: #dbeafe; color: #1e40af; }
.type-snack { background: #fef3c7; color: #92400e; }
.type-drink { background: #d1fae5; color: #065f46; }
.type-etc { background: #e5e7eb; color: #374151; }

.intake-form { display: flex; flex-direction: column; gap: 8px; }
.intake-form .intake-type { padding: 10px; border-radius: 8px; border: 1px solid #ddd; }
.intake-form textarea { width: 100%; min-height: 56px; border-radius: 8px; border: 1px solid #ddd; padding: 10px; resize: vertical; }
.intake-form button { padding: 12px; border: none; border-radius: 8px; background: #059669; color: #fff; cursor: pointer; font-weight: 600; }
.intake-form button:active { background: #047857; }

/* 카드 내부 소구획 (먹은 것 / 운동) */
.sub-block { border-top: 1px dashed #eee; padding-top: 12px; margin-top: 12px; }
.sub-title { font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 8px; }
.list-empty { color: #9ca3af; font-size: 13px; padding: 2px 2px 8px; }

.exercise-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.exercise-list li { display: flex; align-items: center; gap: 8px; background: #f9fafb; padding: 10px; border-radius: 8px; font-size: 14px; }
.exercise-list .exercise-content { flex: 1; }
.del-exercise-btn { border: none; background: none; color: #dc2626; cursor: pointer; font-size: 12px; padding: 4px 6px; flex-shrink: 0; }
.exercise-form { display: flex; flex-direction: column; gap: 8px; }
.exercise-row { display: flex; gap: 8px; }
.exercise-row .exercise-type { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid #ddd; }
.exercise-row .exercise-duration { width: 70px; padding: 10px; border-radius: 8px; border: 1px solid #ddd; text-align: center; }
.exercise-form button { padding: 12px; border: none; border-radius: 8px; background: #ea580c; color: #fff; cursor: pointer; font-weight: 600; }
.exercise-form button:active { background: #c2410c; }
.exercise-badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; background: #ffedd5; color: #9a3412; flex-shrink: 0; }
.exercise-badge.sm { padding: 2px 6px; font-size: 10px; }

/* 필터 바 */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filter-bar label { font-size: 13px; display: flex; align-items: center; gap: 6px; flex: 1; min-width: 130px; }
.filter-bar select, .filter-bar input { flex: 1; min-width: 0; padding: 10px 6px; border-radius: 8px; border: 1px solid #ddd; }
.filter-bar button { width: 100%; padding: 12px; border-radius: 8px; background: #2563eb; color: #fff; border: none; cursor: pointer; font-weight: 600; }

/* 히스토리 */
.history-day { border-bottom: 1px solid #eee; padding: 14px 0; }
.history-date { font-weight: 700; margin-bottom: 8px; }
.history-glucose { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.g-badge { background: #eff6ff; color: #2563eb; padding: 5px 9px; border-radius: 8px; font-size: 12px; }
.meal-row { font-size: 13px; color: #444; margin-bottom: 8px; line-height: 1.6; }
.empty { color: #999; text-align: center; padding: 30px 0; }

/* 통계 */
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 500; color: #374151; }

.quick-range { display: flex; gap: 6px; margin-bottom: 12px; }
.quick-range button { flex: 1; padding: 9px 2px; border-radius: 8px; border: 1px solid #ddd; background: #fff; color: #555; font-size: 12px; cursor: pointer; white-space: nowrap; }
.quick-range button.active { border-color: #2563eb; background: #eff6ff; color: #2563eb; font-weight: 600; }

.range-label { flex: 1; text-align: center; font-size: 14px; font-weight: 500; }

.overall-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.overall-summary.two-col { grid-template-columns: repeat(2, 1fr); }
.metric-card { background: #f9fafb; border-radius: 10px; padding: 10px 4px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.metric-label { font-size: 11px; color: #888; }
.metric-value { font-size: 17px; font-weight: 600; color: #1f2937; }

.range-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: #f1f1f1; margin-bottom: 10px; }
.range-seg { height: 100%; }
.range-low { background: #60a5fa; }
.range-normal { background: #34d399; }
.range-warn { background: #fbbf24; }
.range-high { background: #f87171; }
.range-empty { background: #e5e7eb; }
.range-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: #555; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-item .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.stat-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.summary-card { background: #f9fafb; border-radius: 10px; padding: 10px 6px; text-align: center; }
.summary-card h4 { margin: 0 0 4px; font-size: 13px; }
.summary-card p { margin: 0; font-size: 11px; color: #555; line-height: 1.4; }

.chart-box { position: relative; height: 220px; margin: 16px 0 4px; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
