/* 요소에 hidden 속성과 display를 지정하는 클래스(.center-screen 등)가 동시에 걸리면,
   저자 스타일시트의 display 규칙이 브라우저 기본(hidden → display:none)보다 우선 적용돼서
   hidden이 무시되는 문제가 있다 — 로그인 화면이 JS로 hidden=true를 줘도 계속 보이던 버그의
   원인이었다. 이 규칙으로 hidden이 항상 이기게 고정한다. */
[hidden] { display: none !important; }

:root {
  --bg: #eef1f2;
  --surface: #ffffff;
  --sidebar: #ffffff;
  --border: #e2e6e8;
  --text: #16202a;
  --text-muted: #6b7680;
  --accent: #1b6b93;
  --accent-soft: #e5eef2;
  --good: #16a34a;
  --good-soft: #e7f6ec;
  --bad: #dc2626;
  --bad-soft: #fbe9e7;
  --warn: #d97a12;
  --warn-soft: #fdf1de;
  --offline: #9ca3af;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1417;
    --surface: #171d22;
    --sidebar: #141a1f;
    --border: #262e34;
    --text: #e7edf0;
    --text-muted: #8b979f;
    --accent: #62b6d8;
    --accent-soft: #16333e;
    --good: #34d17a;
    --good-soft: #123423;
    --bad: #f0605a;
    --bad-soft: #3a1917;
    --warn: #f0b23e;
    --warn-soft: #3a2a10;
    --offline: #6b7280;
  }
}

* { box-sizing: border-box; }
html, body {
  /* 모바일에서 어떤 이유로든(가로로 넓은 카드/차트, iOS Safari의 오버스크롤 바운스 등) 페이지가
     가로로 스크롤 가능해지면, position:fixed + transform으로 화면 밖에 숨겨둔 좌측 메뉴가
     스크롤 중에 잠깐 보이거나 끼어드는 것처럼 느껴질 수 있다 — 애초에 가로 스크롤 자체를
     막아 이 문제를 근본적으로 차단한다. */
  overflow-x: hidden;
}
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Pretendard, Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
}
button { font-family: inherit; }

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.card { background-color: var(--surface); border: 1px solid var(--border); border-radius: 10px; }

.login-card { width: 340px; padding: 32px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }
.subtitle { margin: 0 0 12px; color: var(--text-muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.login-card input {
  padding: 9px 10px; border-radius: 6px; border: 1px solid var(--border);
  background-color: var(--bg); color: var(--text); font-size: 14px;
}
.login-card button {
  padding: 10px; border: none; border-radius: 6px; background-color: var(--accent);
  color: white; font-weight: 600; margin-top: 8px; cursor: pointer;
}
.error-text { color: var(--bad); font-size: 13px; margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

/* ---- shell layout ---- */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.app-shell.collapsed { grid-template-columns: 64px 1fr; }

.sidebar {
  background-color: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.icon-btn {
  border: none; background: transparent; color: var(--text-muted); font-size: 16px;
  cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1;
}
.icon-btn:hover { background-color: var(--accent-soft); }
.brand-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.app-shell.collapsed .brand-name,
.app-shell.collapsed .nav-label,
.app-shell.collapsed .nav-group-label { display: none; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13.5px; white-space: nowrap;
}
.nav-item:hover { background-color: var(--accent-soft); }
.nav-item.active { background-color: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-ico { width: 18px; height: 18px; flex: none; display: inline-flex; }
.nav-ico svg { width: 100%; height: 100%; }

/* ---- main column ---- */
.main-col { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--border); background-color: var(--surface);
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.ghost-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.ghost-btn:hover { background-color: var(--accent-soft); }

.content { padding: 22px 26px 60px; }
.view { display: flex; flex-direction: column; gap: 16px; }

/* ---- generic card ---- */
.card { padding: 18px; }
.card-head { font-weight: 700; font-size: 14.5px; color: var(--accent); margin-bottom: 12px; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head-row .card-head { margin-bottom: 0; }

.split-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }

/* ---- table ---- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background-color: var(--accent-soft); cursor: pointer; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; color: white; }
.badge-good { background-color: var(--good); }
.badge-warn { background-color: var(--warn); }
.badge-offline { background-color: var(--offline); }

/* ---- bar list (사용량) ---- */
.bar-list { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 70px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 10px; border-radius: 6px; background-color: var(--accent-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background-color: var(--accent); }
.bar-row .bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }

/* ---- 키오스크 상세정보 (설치정보 목록에서 지점명 클릭 시 이동) ---- */
.kiosk-link { color: var(--accent); text-decoration: none; cursor: pointer; }
.kiosk-link:hover { text-decoration: underline; }
.kiosk-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px 18px; margin-top: 4px; }
.kiosk-detail-grid .field-label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }
.kiosk-detail-grid .field-value { font-size: 14.5px; font-weight: 600; }
.location-edit-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.location-edit-row label { display: flex; flex-direction: column; gap: 3px; }

/* ---- log list (알림/이력) ---- */
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; max-height: 360px; overflow-y: auto; }
.log-list li { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-list li:last-child { border-bottom: none; }
.log-meta { color: var(--text-muted); font-size: 11.5px; }
.log-fail { color: var(--bad); font-size: 11.5px; margin-top: 2px; }

/* ---- search box / 기간검색 ---- */
.search-box {
  padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border);
  background-color: var(--bg); color: var(--text); font-size: 13px; width: 220px;
}
.filter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-box {
  padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border);
  background-color: var(--bg); color: var(--text); font-size: 13px; width: 140px;
  font-family: inherit;
}
/* 날짜 입력 위젯 아이콘이 다크 배경에서도 보이도록 반전 */
@media (prefers-color-scheme: dark) {
  .date-box::-webkit-calendar-picker-indicator { filter: invert(1); }
}

/* ---- 오늘/내일 예상 토글 ---- */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  padding: 6px 12px; border: none; background-color: var(--surface); color: var(--text-muted);
  font-size: 12.5px; cursor: pointer; border-right: 1px solid var(--border); font-family: inherit;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background-color: var(--accent); color: white; }

/* ---- 살수 타겟 지도 ---- */
.map-note { margin: 0 0 10px; }
.map-box {
  height: 520px; width: 100%; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
}
.map-legend { display: flex; gap: 18px; margin-top: 10px; font-size: 12.5px; color: var(--text-muted); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.legend-bad { background-color: var(--bad); }
.legend-good { background-color: var(--good); }

/* ---- empty state (연동 예정 / 준비 중) ---- */
.empty-state { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 32px 24px; }
.empty-ico { width: 40px; height: 40px; color: var(--text-muted); opacity: 0.6; }
.empty-ico svg { width: 100%; height: 100%; }
.empty-state h2 { margin: 0; font-size: 16px; }
.empty-state p { margin: 0; color: var(--text-muted); font-size: 13.5px; max-width: 62ch; line-height: 1.6; }

/* ---- 대시보드 히어로 배너 ---- */
.hero-banner {
  background-image: linear-gradient(135deg, var(--accent) 0%, #2f4bb0 100%);
  border-radius: 14px; padding: 26px 28px 46px; color: white;
}
.hero-banner-title { display: flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 700; margin: 0; }
.hero-banner-title svg { width: 24px; height: 24px; flex: none; }
.hero-banner-sub { margin: 6px 0 0; font-size: 13.5px; opacity: 0.85; }

/* 배너 아래로 살짝 겹쳐 떠 보이도록 음수 마진 사용 */
.summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: -30px; }
/* grid/flex 아이템은 기본적으로 min-width:auto라 안의 텍스트가 길면 트랙 폭을 억지로 늘려
   페이지 전체가 가로로 넘치게 된다 — 지점명이 긴 카드들(요약/액션카드)에 min-width:0으로
   내용에 맞춰 줄이는 대신 트랙 폭을 우선하도록 명시한다. */
.summary-row .card { box-shadow: 0 6px 18px rgba(0,0,0,0.08); }

.env-card-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.env-card-place {
  font-weight: 700; font-size: 15px; color: var(--accent); margin-bottom: 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.mini-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
/* 대시보드 상단 요약 카드에 강우량 박스를 추가하면서 4칸이 된 전용 변형 — 좁은 화면에서는
   아래 640px 미디어 쿼리에서 2칸으로 접는다. */
.mini-stat-grid-env { grid-template-columns: repeat(4, 1fr); }
.mini-stat-box { border-radius: 8px; padding: 10px 8px; text-align: center; color: white; }
.mini-stat-box .mini-stat-label { font-size: 11px; opacity: 0.9; }
.mini-stat-box .mini-stat-value { font-size: 13.5px; font-weight: 700; margin-top: 4px; }
.mini-stat-info { background-color: var(--accent); }
.mini-stat-warn { background-color: var(--warn); }
.mini-stat-good { background-color: var(--good); }
.mini-stat-bad { background-color: var(--bad); }

.status-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 190px; overflow-y: auto; }
.status-list li { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; }
.status-list .status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.status-list .status-time { color: var(--text-muted); white-space: nowrap; }

.chart-box { height: 220px; position: relative; }
.chart-box canvas { max-width: 100%; }
.chart-box-tall { height: 280px; }

/* ---- 기후위기 대응 현황 카드 ---- */
.action-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.action-card {
  border-radius: 10px; padding: 14px 16px; color: white; display: flex; flex-direction: column;
  gap: 10px; min-height: 100px; justify-content: space-between; cursor: default;
}
.action-card-good { background-color: var(--good); }
.action-card-warn { background-color: var(--warn); }
.action-card-bad { background-color: var(--bad); }
.action-card-top { font-size: 12px; opacity: 0.9; }
.action-card-headline { font-size: 17px; font-weight: 700; }
.action-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12.5px; }
.action-card-foot span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 미세먼지/폭염 등급 배지(테이블용) ---- */
.badge-info { background-color: var(--accent); }
.badge-bad { background-color: var(--bad); }
.badge-muted { background-color: var(--text-muted); }

/* ---- 테이블 툴바(검색 + 페이지당 표시 수) ---- */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.table-toolbar select {
  padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border);
  background-color: var(--bg); color: var(--text); font-size: 13px; font-family: inherit;
}
.page-size-label { display: flex; align-items: center; gap: 6px; }
.table-caption { color: var(--text-muted); font-size: 12.5px; margin: 0; }

/* ---- 정렬 가능한 표 헤더 ---- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--accent); }
.sort-ico { display: inline-block; width: 0; height: 0; margin-left: 3px; vertical-align: middle;
  border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: 0.35; }
th.sortable.sort-asc .sort-ico { border-bottom: 5px solid currentColor; opacity: 1; }
th.sortable.sort-desc .sort-ico { border-top: 5px solid currentColor; opacity: 1; }

/* ---- 페이지네이션 ---- */
.pagination-row { display: flex; align-items: center; gap: 4px; }
.pagination-row button {
  padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
  background-color: var(--surface); color: var(--text); font-size: 12.5px; cursor: pointer; font-family: inherit;
}
.pagination-row button:hover:not(:disabled) { background-color: var(--accent-soft); }
.pagination-row button:disabled { opacity: 0.4; cursor: default; }
.pagination-row button.active { background-color: var(--accent); color: white; border-color: var(--accent); }

/* .sidebar-backdrop는 데스크톱 폭에서는 안 쓰는 모바일 전용 오버레이라 기본값을 display:none으로
   고정해둔다 — 이게 없으면 스타일이 하나도 안 걸린 평범한 <div>로 남아서, .app-shell 그리드(2열:
   사이드바+본문)에 세 번째 그리드 아이템으로 끼어들어 자동 배치가 다음 행으로 넘어가 버리고,
   결국 .main-col이 2행 1열(사이드바와 같은 폭)에 배치되는 버그가 났었다. */
.sidebar-backdrop { display: none; }

/* ---- FAQ ---- */
.faq-list { display: flex; flex-direction: column; gap: 10px; }
.faq-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.faq-q { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.faq-a { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

/* ---- 폭염/미세먼지(현재+AI 예측) 알림 배너 ---- */
.alert-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 26px; background-color: var(--bad-soft); border-bottom: 1px solid var(--bad);
  color: var(--text); font-size: 13.5px;
}
.alert-banner strong { color: var(--bad); }
.alert-banner-actions { display: flex; align-items: center; gap: 8px; }
.alert-banner-actions .ghost-btn { padding: 5px 10px; font-size: 12.5px; }
@media (max-width: 640px) { .alert-banner { padding: 10px 14px; } }

/* ---- 공지사항 ---- */
.notice-list { display: flex; flex-direction: column; gap: 10px; }
.notice-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.notice-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.notice-title { font-weight: 700; font-size: 14.5px; }
.notice-date { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.notice-content { margin-top: 6px; font-size: 13px; color: var(--text); white-space: pre-wrap; line-height: 1.6; }

/* ---- 반응형: 태블릿(아이콘 전용 사이드바) ---- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 64px 1fr; }
  .brand-name, .nav-label, .nav-group-label { display: none; }
  .split-grid { grid-template-columns: 1fr; }
  .summary-row { grid-template-columns: 1fr; margin-top: 14px; }
}

/* ---- 반응형: 모바일(사이드바를 오버레이 드로어로 전환) ----
   태블릿 폭에서는 사이드바가 64px 아이콘 레일로 계속 화면을 차지하지만, 휴대폰 폭에서는
   그마저도 좁은 화면을 많이 잡아먹는다. 이 폭부터는 사이드바를 화면 밖으로 완전히 숨기고
   ☰ 버튼으로 열고 닫는 오버레이 방식으로 바꾼다(appView에 mobile-nav-open 클래스를 토글해
   여는데, app.js의 sidebar-toggle 핸들러가 뷰포트 폭을 보고 .collapsed 대신 이 클래스를 쓴다). */
@media (max-width: 640px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 230px; z-index: 100;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,0.25);
    /* position:fixed + transform 조합은 일부 모바일 브라우저(특히 iOS Safari)에서 스크롤/
       바운스 중에 레이어를 다시 그리면서 잠깐 잘못된 위치에 그려지는 알려진 문제가 있다 —
       화면 밖에 숨어 있어야 할 드로어가 스크롤하는 순간 끼어드는 것처럼 보이는 원인 중 하나다.
       will-change로 별도 컴포지팅 레이어를 미리 만들어두면 스크롤 중 재계산 없이 그 레이어를
       그대로 옮기기만 하면 돼서 이 문제가 없어진다. */
    will-change: transform;
    -webkit-backface-visibility: hidden;
  }
  .app-shell.mobile-nav-open .sidebar { transform: translateX(0); }
  .brand-name, .nav-label, .nav-group-label { display: inline; } /* 열렸을 때는 전체 폭이라 라벨을 다시 보여준다 */

  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 99; }
  .app-shell.mobile-nav-open .sidebar-backdrop { display: block; }

  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 15px; }
  .content { padding: 14px 14px 40px; }
  #last-refreshed { display: none; } /* 좁은 화면에서 버튼과 겹치지 않도록 생략 */

  .hero-banner { padding: 18px 16px 30px; border-radius: 12px; }
  .hero-banner-title { font-size: 17px; }
  .hero-banner-sub { font-size: 12.5px; }
  .summary-row { margin-top: -20px; gap: 10px; }
  .mini-stat-grid { gap: 6px; }
  .mini-stat-grid-env { grid-template-columns: repeat(2, 1fr); }
  .mini-stat-box { padding: 8px 4px; }
  .mini-stat-box .mini-stat-label { font-size: 10px; }
  .mini-stat-box .mini-stat-value { font-size: 12px; }

  .chart-box { height: 190px; }
  .action-card-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .action-card-headline { font-size: 15px; }

  .card-head-row, .table-toolbar { flex-direction: column; align-items: flex-start; }
  .search-box, .date-box { width: 100%; }
  .filter-row { width: 100%; }
}

@media (max-width: 420px) {
  .action-card-grid { grid-template-columns: 1fr; } /* 카드마저 두 칸이 빠듯한 초소형 화면 */
}
