/* ============================================================
   KAASA SmartOS Mobile — base.css
   공통 CSS 변수, 레이아웃, 타이포그래피
   모든 screen_*.html 이 이 파일을 참조합니다.
   ============================================================ */

:root {
  /* 브랜드 색상 */
  --green:        #1f7a4d;
  --green-2:      #2f9a62;
  --green-soft:   #e7f4ed;
  --green-dark:   #0f5132;
  --blue:         #2563eb;
  --blue-soft:    #eaf1ff;
  --orange:       #b45309;   /* WCAG AA: 흰배경 5.0:1 (구 #d97706=3.2 미달 → 어둡게) */
  --orange-soft:  #fff4df;
  --red:          #dc2626;
  --red-soft:     #ffeaea;
  --purple:       #7c3aed;
  --purple-soft:  #f1eaff;
  --gray:         #607066;
  --gray-soft:    #eef2ef;

  /* 배경·패널 */
  --bg:           #f4f7f4;
  --panel:        #ffffff;
  --panel-soft:   #f8fbf8;
  --border:       #dce6dc;
  --text:         #25322c;   /* 순black 완화·가독성(흰배경 대비 ~10:1 AA) */
  --muted:        #4d5a52;  /* WCAG AA 대비 충족 (구 #607066 → 어둡게) */

  /* 그림자·반경 */
  --shadow:       0 4px 16px rgba(31,42,36,.10);
  --radius:       16px;
  --radius-sm:    10px;

  /* 레이아웃 */
  --header-h:     52px;
  --tab-h:        60px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);

  /* Period 색상 (P1~P5) */
  --p1-color:     #4f46e5;   /* 인디고 — 일출 前 */
  --p1-soft:      #eef2ff;
  --p2-color:     #059669;   /* 에메랄드 — 첫 관수 */
  --p2-soft:      #d1fae5;
  --p3-color:     #0284c7;   /* 스카이 — 오전 */
  --p3-soft:      #e0f2fe;
  --p4-color:     #d97706;   /* 앰버 — 정오 고부하 */
  --p4-soft:      #fef3c7;
  --p5-color:     #7c3aed;   /* 바이올렛 — 오후~마감 */
  --p5-soft:      #f5f3ff;
  --p6-color:     #1e3a5f;   /* 네이비 — 야간 dry-back */
  --p6-soft:      #e7edf3;

  /* 상태 색상 */
  --ok:           var(--green);
  --warn:         var(--orange);
  --danger:       var(--red);
  --info:         var(--blue);

  /* 차트 공통 팔레트 (전 화면 차트 색의미 통일 — 온실/노지/공통 동일) */
  --chart-hot:    #dc2626;  /* 고온·최고기온·위험 */
  --chart-cool:   #2563eb;  /* 저온·습도·기본 라인 */
  --chart-good:   #16a34a;  /* 양호·VPD·생육 */
  --chart-warn:   #f59e0b;  /* 주의·경계 */
  --chart-rain:   #60a5fa;  /* 강수 */
}

/* ── 다크 모드 (html[data-theme="dark"]) ─────────────────────────────
   변수만 재정의 → 전 화면 자동 적용. 브랜드 그린은 대비 위해 약간 밝게. */
:root[data-theme="dark"] {
  --green:        #35c082;
  --green-2:      #2f9a62;
  --green-soft:   #15291f;
  --green-dark:   #8fe6b8;   /* 다크 배경 위 강조 텍스트 → 밝게 */
  --blue:         #5b9bff;
  --blue-soft:    #16243d;
  --orange:       #f0a64e;
  --orange-soft:  #2e2310;
  --red:          #f87171;
  --red-soft:     #351b1b;
  --purple:       #a78bfa;
  --purple-soft:  #241a3a;
  --gray:         #9fb0a6;
  --gray-soft:    #1c241f;

  --bg:           #0f1613;
  --panel:        #18211d;
  --panel-soft:   #131b17;
  --border:       #2a352e;
  --text:         #e7ece9;
  --muted:        #a3b3a9;

  --shadow:       0 4px 16px rgba(0,0,0,.45);

  /* Period soft 배경 — 다크 톤 */
  --p1-soft: #1b1f3a; --p2-soft: #0f2a20; --p3-soft: #0e2436;
  --p4-soft: #2e2410; --p5-soft: #221a3a; --p6-soft: #16202e;
}
/* 테마 전환 부드럽게 (모션 민감 사용자는 제외) */
@media (prefers-reduced-motion: no-preference) {
  body { transition: background-color .25s ease, color .25s ease; }
}

/* ── 리셋 & 기본 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;              /* 가독성: 기본 폰트 확대(농가·고령 대응) */
  line-height: 1.62;            /* 행간 확대로 읽기 편하게 */
  letter-spacing: -.01em;
  -webkit-tap-highlight-color: transparent;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
}
/* 가독성: 너무 작은 글씨 하한 보정(레이아웃 영향 최소) */
.kpi-label, .cost-sub, .drawer-head p, .sec-sub-label, .pest-cond { font-size: 11.5px !important; }
.bnav-tab { font-size: 11px !important; }

/* ── TOP HEADER ── */
.sf-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--header-h);
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--green-dark);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 16px; padding-right: 16px;
}
.sf-header .brand      { color: #fff; font-size: 16px; font-weight: 800; letter-spacing: -.03em; }
.sf-header .brand small { display: block; font-size: 10px; opacity: .65; font-weight: 400; }
.sf-header .hdr-right  { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border: none; background: rgba(255,255,255,.12);
  border-radius: 10px; color: #fff; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
/* WS 연결 배지 */
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--gray); display: inline-block;
}
.ws-dot.connected  { background: #34d399; }
.ws-dot.reconnecting { background: var(--orange); }

/* ── BOTTOM NAV ── */
.sf-bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--green-dark);
  display: flex;
  border-top: 1px solid rgba(255,255,255,.12);
}
.bnav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: rgba(255,255,255,.55); font-size: 10px; gap: 3px;
  border: none; background: none; cursor: pointer; padding: 6px 0;
  min-height: var(--tab-h); transition: color .18s;
}
.bnav-tab.active  { color: #fff; }
.bnav-tab .bnav-icon { font-size: 22px; line-height: 1; }

/* ── 드로어 ── */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.45);
  display: none; opacity: 0; transition: opacity .22s;
}
.drawer-overlay.open { display: block; opacity: 1; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 301;
  width: min(320px, 88vw); background: var(--green-dark); color: #fff;
  overflow-y: auto; transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  padding-top: env(safe-area-inset-top, 0px);
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 20px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.14); position: relative; }
.drawer-head h2 { font-size: 17px; font-weight: 800; }
.drawer-head p  { font-size: 11px; opacity: .65; margin-top: 4px; }
.drawer-close {
  position: absolute; top: 16px; right: 14px;
  background: rgba(255,255,255,.12); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 8px; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.drawer nav a {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,.85); text-decoration: none;
  padding: 12px 16px; border-radius: 10px; font-size: 14px; margin: 2px 8px;
  min-height: 48px; transition: background .15s;
}
.drawer nav a:active { background: rgba(255,255,255,.15); }
.drawer-group {
  margin: 10px 16px 4px; font-size: 10px; letter-spacing: .08em;
  color: rgba(255,255,255,.42); text-transform: uppercase;
}

/* ── MAIN 영역 ── */
main {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}
section { margin-bottom: 24px; }
.section-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 800; letter-spacing: -.01em;
  color: var(--text); margin: 4px 0 10px;
}
.section-label::before {
  content: ""; flex: 0 0 auto; width: 4px; height: 15px;
  border-radius: 3px; background: var(--green);
}
/* 노지 화면 등 섹션은 강조 바 색을 청록으로 (맥락 구분) */
.sf-main.field-ctx .section-label::before,
.field-ctx .section-label::before { background: var(--blue); }

/* ── 카드 ── */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.card-title {
  font-size: 14px; font-weight: 800; color: var(--text);
  margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}

/* ── KPI 그리드 ── */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi-grid.cols3 { grid-template-columns: repeat(3, 1fr); }
.kpi {
  background: var(--panel-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px;
}
.kpi-label { font-size: 11px; color: var(--muted); display: block; }
.kpi-value {
  font-size: 22px; font-weight: 800; letter-spacing: -.04em;
  margin-top: 2px; display: block; white-space: nowrap;
}
.kpi-unit  { font-size: 13px; font-weight: 400; }
.kpi-hint  { font-size: 11px; color: var(--muted); margin-top: 3px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--radius-sm); padding: 0 16px;
  font-size: 14px; font-weight: 700; cursor: pointer; color: #fff;
  background: var(--green); white-space: nowrap;
  min-height: 44px; transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .85; transform: scale(.97); }
.btn.full   { width: 100%; border-radius: 12px; font-size: 15px; min-height: 48px; }
.btn.sm     { min-height: 36px; font-size: 12px; padding: 0 12px; }
.btn.secondary { background: #64748b; }
.btn.orange    { background: var(--orange); }
.btn.blue      { background: var(--blue); }
.btn.red       { background: var(--red); }
.btn.outline   { background: none; border: 1.5px solid var(--green); color: var(--green); }
.btn.ghost     { background: none; color: var(--muted); }
.btn:disabled  { opacity: .45; pointer-events: none; }

/* ── 배지 ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 8px; padding: 3px 8px; font-size: 11px; font-weight: 700;
}
.badge.green  { background: var(--green-soft);  color: var(--green); }
.badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.red    { background: var(--red-soft);    color: var(--red); }
.badge.blue   { background: var(--blue-soft);   color: var(--blue); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.gray   { background: var(--gray-soft);   color: var(--muted); }

/* ── 알림 배너 ── */
.alert-banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 10px; border: 1px solid transparent;
}
.alert-banner.warn   { background: var(--orange-soft); border-color: #ffe1a8; color: #7c4a00; }
.alert-banner.danger { background: var(--red-soft);    border-color: #ffc7c7; color: #7f1d1d; }
.alert-banner.info   { background: var(--blue-soft);   border-color: #c9d8ff; color: #1e3a8a; }
.alert-banner.ok     { background: var(--green-soft);  border-color: #cbe7d5; color: #14532d; }
.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── 테이블 ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 300px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { background: #eef5ef; color: #23362b; font-size: 12px; font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── 프로그레스 바 ── */
.progress-bar { height: 8px; background: #e4ebe4; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; background: var(--green-2); transition: width .4s; }
.progress-fill.warn   { background: var(--orange); }
.progress-fill.danger { background: var(--red); }

/* ── Bottom Sheet ── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,.45);
  display: none;
}
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 401;
  background: var(--panel); border-radius: 20px 20px 0 0;
  padding: 20px 18px; padding-bottom: calc(20px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 80vh; overflow-y: auto;
}
.sheet.open       { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 99px; margin: 0 auto 16px; }
.sheet h4         { font-size: 17px; font-weight: 800; margin-bottom: 12px; }
.sheet-btn-row    { display: grid; gap: 8px; margin-top: 14px; }

/* ── 세그먼트 컨트롤 ── */
.seg {
  display: flex; background: var(--gray-soft); border-radius: var(--radius-sm);
  padding: 3px; gap: 2px; margin-bottom: 12px;
}
.seg-btn {
  flex: 1; padding: 8px 4px; border: none; background: none; border-radius: 8px;
  font-size: 12px; font-weight: 700; color: var(--muted); cursor: pointer;
  min-height: 36px; transition: all .15s;
}
.seg-btn.active { background: var(--panel); color: var(--green); box-shadow: 0 1px 4px rgba(0,0,0,.1); }

/* ── 로딩 스피너 ── */
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--border);
  border-top-color: var(--green); border-radius: 50%;
  animation: spin .7s linear infinite; margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 스켈레톤 로딩 ── */
.skeleton {
  background: linear-gradient(90deg, var(--gray-soft) 25%, #e8ede8 50%, var(--gray-soft) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
  border-radius: 6px; min-height: 20px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── 설명 박스 ── */
.explain {
  background: var(--panel); border-left: 4px solid var(--green);
  border-radius: var(--radius-sm); padding: 11px 13px;
  font-size: 13px; color: #34433a; margin-top: 8px;
}
.explain b { color: var(--green); }

/* ── 태블릿·데스크탑 ── */
@media (min-width: 768px) {
  main { padding: 24px; max-width: 800px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .kpi-grid.cols3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1100px) {
  body { padding-bottom: 0; }
  .sf-bottom-nav { display: none; }
  .sf-sidebar { display: flex !important; }
  main { max-width: none; padding: 28px; }
}

/* ── 데이터 신뢰도 뱃지 (실측/추정/Mock) ── */
.trust-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 9px; font-weight: 800; padding: 2px 7px;
  border-radius: 8px; vertical-align: middle; white-space: nowrap;
}
.trust-live { background: var(--green-soft); color: var(--green-dark); }   /* 실측/실데이터 */
.trust-model{ background: var(--blue-soft);  color: var(--blue); }          /* ML 모델 예측 */
.trust-est  { background: var(--orange-soft);color: var(--orange); }        /* 추정/표준값 */
.trust-mock { background: var(--gray-soft);  color: var(--muted); }         /* Mock(미연동) */

/* ── CLS 방지: KPI 카드 최소 높이 (데이터 로드 전후 레이아웃 고정) ── */
.kpi-card, .gh-kpi, .env-kpi-card, .fd-kpi, .f4-kpi, .pred-card, .c6-kpi, .f3-kpi, .f6-kpi, .f7-kpi {
  min-height: 84px;
}
.kpi-value, .gh-kpi-val, .env-value, .pred-value { min-height: 24px; }

/* ── 접근성 일관성 (전 화면 공통, 2026-06-09) ───────────────────────────── */
/* 키보드 포커스 링 — 마우스 클릭엔 안 보이고 키보드 탐색 시만 표시 */
a:focus-visible, button:focus-visible, select:focus-visible,
input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible,
.bnav-tab:focus-visible, .sum-tab:focus-visible, [onclick]:focus-visible {
  outline: 3px solid var(--green, #1f9d55);
  outline-offset: 2px;
  border-radius: 6px;
}
/* 콘텐츠 토글 탭 최소 터치 영역 확보 */
.sum-tab { min-height: 40px; }
/* 모션 감소 선호 사용자: 스피너·애니메이션 정지(어지럼 방지) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── UI/UX 효과성·효율성 (전 화면 공통, 2026-06-09) ───────────────────────── */
/* 1) 촉각 피드백 — 모든 인터랙티브 요소에 누름 반응(반응성 체감↑) */
button, .bnav-tab, .screen-card, .sum-tab, .svc-card, .jump-btn, a.card, [role="button"] {
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
button:active, .bnav-tab:active, .screen-card:active, .sum-tab:active,
.svc-card:active, .jump-btn:active, a.card:active, [role="button"]:active {
  transform: scale(.975);
}
/* 2) 헤더 아이콘 버튼 최소 터치영역(44px 권장) — 누르기 쉬움 */
.sf-header button, .sf-header [onclick] {
  min-width: 40px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
}
/* 3) 앵커 점프 시 sticky 헤더에 가리지 않도록 여유 확보(이동 정확도) */
[id] { scroll-margin-top: 64px; }
/* 4) 가로 스크롤 스트립 관성 스크롤(부드러운 탐색) */
[style*="overflow-x"], .strat-band { -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
/* 5) 링크형 카드 hover 시 살짝 떠오름(가시적 어포던스, 데스크톱) */
@media (hover: hover) {
  .screen-card:hover, .svc-card:hover, a.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); }
}
