/* =====================================================
pptx 디자인에서 뽑은 다크 팔레트
===================================================== */
:root {
    --bg-main: #0B1220;
    /* 페이지 전체 배경 */
    --bg-card: #1B2438;
    /* 카드 배경 */
    --bg-table: #14203A;
    /* 테이블 셀 배경 */
    --bg-thead: #22304A;
    /* 테이블 헤더 */
    --header-blue: #152239;
    /* 상단바 */
    --tab-active: #0E4B9E;
    /* 활성 탭 */
    --tab-inactive: #2C3648;
    /* 비활성 탭 */
    --accent-cyan: #4FC3F7;
    /* 강조 청록 */
    --accent-title: #29B6F6;
    /* 타이틀 청록 */
    --dot-ok: #22C55E;
    /* 정상 (초록 원) */
    --dot-warn: #FFD54F;
    /* 경고 (노란 원) */
    --dot-danger: #F57373;
    /* 위험 (빨간 원) */
    --dot-orange: #FF9800;
    /* 주황 */
    --text-primary: #F1F1F1;
    --text-dim: #A0A8B8;
    --text-muted: #6B7280;
    --marker-red: #E53935;
    /* 섹션 앞 빨간 막대 */
    --border-soft: #263248;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Malgun Gothic', 'Segoe UI', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* =====================================================
상단 헤더 바 (제목 + 사용자 + 로그아웃)
===================================================== */
.top-bar {
    position: -webkit-sticky;  /* 구형 iOS 사파리 */
    position: sticky;          /* 스크롤해도 상단 고정 */
    top: 0;
    z-index: 900;              /* 모달(1000)보다는 아래 */
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    background: var(--header-blue);
    padding: 14px 24px;
    border-bottom: 1px solid var(--border-soft);
}

/* 좌측: 설정 메뉴 드롭다운 */
.settings-menu {
    position: relative;
    display: inline-block;
}

.settings-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;      /* 사용자·로그아웃과 같은 크기 */
    padding: 6px 10px;
    border-radius: 4px;
}

.settings-trigger:hover {
    background: rgba(255, 255, 255, 0.05);
}

.settings-trigger i.fa-wrench {
    color: var(--text-primary);
}

.settings-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: #1A2540;
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    min-width: 180px;
    z-index: 100;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.settings-dropdown a {
    display: block;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-dropdown a:last-child {
    border-bottom: none;
}

.settings-dropdown a:hover {
    background: rgba(79, 195, 247, 0.1);
    color: var(--accent-cyan);
}

.settings-menu.open .settings-dropdown {
    display: block;
}

/* 중앙: 타이틀 */
.brand-title {
    display: block;
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-title);
    text-align: center;
    letter-spacing: 1px;
    text-decoration: none;     /* 링크여도 밑줄 없음 */
    cursor: pointer;
}
.brand-title:hover {
    opacity: 0.85;
}

/* 우측: 사용자 + 로그아웃 */
.top-right {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
}

.user-badge {
    font-size: 13px;
    color: var(--text-primary);
}

/* 내 정보로 들어가는 링크임을 알린다 */
a.user-badge:hover {
    color: var(--accent-cyan);
    text-decoration-color: var(--accent-cyan);
}

.user-badge .tag {
    color: var(--accent-cyan);
    font-weight: 600;
    margin-left: 2px;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
}

.logout-link:hover {
    color: var(--accent-cyan);
}

/* =====================================================
대형 탭 4개 (오류 상황 / 통신 상태 / 측정 내역 / 설치 현황)
===================================================== */
.main-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 16px 24px 0;
}

.main-tab {
    padding: 14px;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 3px;
    border-radius: 6px 6px 0 0;
    background: var(--tab-inactive);
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}

.main-tab:hover {
    color: var(--text-primary);
}

.main-tab.active {
    background: var(--tab-active);
    color: #FFFFFF;
}

/* =====================================================
탭 컨텐츠 영역
===================================================== */
.tab-content {
    display: none;
    background: transparent;
    padding: 20px 24px 40px;
}

.tab-content.active {
    display: block;
}

/* 섹션 카드 (측정 오류 / 통신 오류 등) */
.section-card {
    background: transparent;
    margin-bottom: 24px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;          /* 좁아지면 제목과 버튼이 겹치지 않게 줄을 나눈다 */
    gap: 8px;
    /* 버튼·날짜선택 유무와 상관없이 띠 높이를 같게 유지한다.
       (내용이 없는 화면도 동일한 높이를 차지하도록 min-height 로 고정) */
    min-height: 44px;
    box-sizing: border-box;
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 10px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;         /* 버튼(약 30px)과 같은 높이 확보 */
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

/* 섹션 제목 앞 빨간 인디케이터 (pptx 특징) */
.section-title::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 18px;
    background: var(--marker-red);
    border-radius: 1px;
}

/* 화면별 제목 바 색 : 주문(하늘색) / 측정내역(녹색). 설치현황은 install-header 가 핑크 */
.section-title.bar-cyan::before  { background: var(--accent-cyan); }
.section-title.bar-green::before { background: var(--dot-ok); }
.section-title.bar-pink::before  { background: #FF2D78; }

/* 우측 필터 (일간 3 등) */
.section-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-input {
    width: 55px;
    padding: 4px 8px;
    background: #22304A;
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    border-radius: 3px;
    text-align: center;
    font-size: 13px;
}

.filter-tag {
    padding: 4px 10px;
    background: #22304A;
    color: var(--text-dim);
    border-radius: 3px;
    font-size: 13px;
}

/* 서브 탭 (재고율 순 / 측정시간 순 등) */
.sub-tabs {
    display: flex;
    gap: 6px;
}

.sub-tab {
    padding: 6px 14px;
    background: #2C3548;
    color: var(--text-dim);
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
}

.sub-tab.active {
    background: var(--accent-cyan);
    color: #0B1220;
    font-weight: 700;
}

/* =====================================================
데이터 테이블
===================================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-table);
    border-radius: 4px;
    overflow: hidden;
    font-size: 13px;
}

#tab-4 .data-table {
    table-layout: fixed;
}

.data-table thead th {
    background: var(--bg-thead);
    padding: 10px 6px;
    text-align: center;
    font-weight: 600;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
}

/* 컬럼 클릭 정렬 머리글.
   밑줄 대신 화살표로 표시한다. 화살표는 항상 그려 두고 활성 컬럼만 진하게 보여,
   어느 컬럼을 누를 수 있는지 미리 알 수 있게 한다.
   th 에 onclick 을 건 화면과 <a> 를 넣은 화면 둘 다 같은 모양이 된다. */
.data-table thead th.th-sort { cursor: pointer; user-select: none; }
.data-table thead th.th-sort:hover { color: var(--accent-cyan); }
.data-table thead th.th-sort a { color: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
.data-table thead th.th-sort a:hover { color: var(--accent-cyan); }
.data-table thead th.th-sort .ar { font-size: 10px; margin-left: 3px; opacity: .35; }
.data-table thead th.th-sort .ar.on { opacity: 1; color: var(--accent-cyan); }

.data-table tbody td {
    padding: 8px 6px;
    text-align: center;
    /* 모든 목록의 행 높이를 통일한다.
       내용 높이를 22px 로 고정해, 아이콘이 들어가는 측정내역도 같은 높이가 되게 한다. */
    height: 22px;
    line-height: 22px;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

/* 셀 안의 아이콘·배지·버튼이 행 높이를 넘지 않게 한다 (측정내역 사일로 이미지, 3D 버튼 등) */
.data-table tbody td img {
    max-height: 22px;
    vertical-align: middle;
}

/* vertical-align: middle 은 상자형 요소에만 준다.
   순수 텍스트 span 에까지 주면 글자 기준선과 중심이 어긋나 줄 상자가 커지고,
   그 결과 값이 빈 칸('-' = span.cell-null) 이 있는 행만 1~2px 높아진다.
   아래는 목록 셀 안에서 실제로 가운데 정렬이 필요한 상자형 span 들이다.
     .dot        통신상태·오류상황 상태 원
     .st-badge   고장신고 상태 배지
     .btn-2d     측정내역 2D 버튼 (자리맞춤용 btn-blank 포함)
     .badge-lock / .badge-off  사용자 관리 상태 배지
     .sig        주문관리·내보내기 신호 원
     .feed-btns  잔여사료 3D/2D 묶음 (자체 규칙이 480px 이하에만 있어 여기서 받아야 한다) */
.data-table tbody td a,
.data-table tbody td button,
.data-table tbody td .dot,
.data-table tbody td .st-badge,
.data-table tbody td .btn-2d,
.data-table tbody td .badge-lock,
.data-table tbody td .badge-off,
.data-table tbody td .sig,
.data-table tbody td .feed-btns {
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: rgba(79, 195, 247, 0.04);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* 피드빈 이름은 파란색 (pptx 특징) */
.cell-bin {
    color: var(--accent-cyan);
    font-weight: 600;
}

/* 시간 컬럼 파란색 */
.cell-time {
    color: var(--accent-cyan);
}

/* 오류 유형 색상 */
.cell-err {
    color: var(--dot-orange);
    font-weight: 600;
}

/* 배지 */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.danger {
    background: rgba(245, 115, 115, 0.15);
    color: var(--dot-danger);
    border: 1px solid rgba(245, 115, 115, 0.3);
}

.badge.warn {
    background: rgba(255, 213, 79, 0.15);
    color: var(--dot-warn);
    border: 1px solid rgba(255, 213, 79, 0.3);
}

.badge.ok {
    background: rgba(34, 197, 94, 0.15);
    color: var(--dot-ok);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* 상태 원 아이콘 */
.dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.ok {
    background: var(--dot-ok);
}

.dot.warn {
    background: var(--dot-warn);
}

.dot.danger {
    background: var(--dot-danger);
}

.dot.orange {
    background: var(--dot-orange);
}

/* 3D / 2D 버튼 (측정 내역 탭) */
.btn-3d,
.btn-2d {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    margin: 0 1px;
    /* 셀의 line-height(22px) 를 그대로 상속하면 버튼이 행보다 커진다.
       패딩(3+3) 을 더해 정확히 22px 가 되도록 고정한다. */
    line-height: 16px;
    vertical-align: middle;
}

.btn-3d {
    /* 조회 버튼 등과 같은 하늘색 계열로 통일 */
    background: var(--accent-cyan);
    color: #0B1220;
}

.btn-2d {
    background: #37475A;
    color: #FFFFFF;
}

/* NULL 값 표시 (데이터 없음) */
.cell-null {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.55;
    font-size: 12px;
}

/* 필터 셀렉트 (통신 상태 / 측정 내역 상단) */
.filter-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 600;
}

.filter-select {
    background: #22304A;
    color: var(--text-primary);
    border: 1px solid var(--border-soft);
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 13px;
    min-width: 90px;
}

.btn-search {
    background: var(--accent-cyan);
    color: #0B1220;
    padding: 5px 20px;
    border: none;
    border-radius: 3px;
    font-weight: 700;
    cursor: pointer;
    font-size: 13px;
}

/* 통신 상태 탭 상단의 두 개의 하위 통신 타이틀 (LTE / WIFI Halow) */
.comm-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;   /* 오른쪽 → 왼쪽 */
    gap: 16px;
    /* section-head 와 같은 규격 (버튼·필터 유무와 무관하게 띠 높이 통일) */
    min-height: 44px;
    box-sizing: border-box;
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 10px;
}

.comm-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;              /* section-title 과 동일 */
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.comm-title::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 18px;
    background: var(--accent-cyan);   /* 통신 상태 : 하늘색 */
    border-radius: 1px;
}

.comm-title.right {
    color: var(--text-primary);
}

.comm-title.right::before {
    background: var(--text-muted);
}

/* 설치 현황 탭용 카드 그리드 */
.install-section {
    margin-bottom: 24px;
}

.install-header {
    display: flex;
    align-items: center;
    gap: 10px;
    /* section-head 와 같은 규격으로 통일 (기존 padding-bottom 8 / margin 12 에서 변경) */
    min-height: 44px;
    box-sizing: border-box;
    padding: 4px 0 10px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: 700;
}

.install-header::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 18px;
    background: #FF2D78;
    border-radius: 1px;
}

.install-placeholder {
    min-height: 140px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-soft);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* 빈 데이터 안내 */
.empty-msg {
    text-align: center;
    padding: 30px 0;
    color: var(--text-muted);
    font-size: 13px;
}

/* 반응형 */
/* 테이블 가로 스크롤 (데이터 많은 관리자 화면) */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }

@media (max-width: 820px) {
    .table-wrap .data-table { width: max-content; min-width: 100%; }
    .table-wrap .data-table th, .table-wrap .data-table td { white-space: nowrap; }
    /* 좁아지면 설정 메뉴가 타이틀과 겹친다.
       타이틀을 한 줄 차지하게 하고, 설정 메뉴를 사용자·로그아웃 줄로 내린다. */
    .top-bar {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "title  title"
            "menu   user";
        gap: 8px 12px;
        padding: 10px 14px;
    }
    .top-bar > :first-child { grid-area: menu; justify-self: start; }
    .top-bar .brand-title   { grid-area: title; }
    .top-bar .top-right     { grid-area: user; }

    .brand-title {
        font-size: 18px;
        letter-spacing: 0;
    }

    .main-tab {
        font-size: 14px;
        letter-spacing: 1px;
        padding: 12px 4px;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: 6px 4px;
    }
}

/* ===== 폰: 상단바 / 탭 2x2 ===== */
@media (max-width: 480px) {
    .top-bar { padding: 10px 14px; gap: 8px; }
    .brand-title { font-size: 17px; letter-spacing: 0; }
    .user-badge { font-size: 11px; }
    .main-tabs { grid-template-columns: repeat(2, 1fr); padding: 12px 14px 0; }
    .main-tab { font-size: 13px; letter-spacing: 2px; padding: 12px 6px; border-radius: 6px; }
    /* 농장주 상단바: 2줄 (타이틀 위 / 설정·사용자 아래)
       설정 메뉴를 띄우지 않고 아래 줄 왼쪽에 둬야 타이틀과 겹치지 않는다. */
    .top-bar-farmer { display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px; padding: 10px 14px; }
    .top-bar-farmer .brand-title { order: 1; flex: 1 1 100%; text-align: center; }
    .top-bar-farmer > :first-child { order: 2; flex: 0 0 auto; }
    .top-bar-farmer .top-right { order: 3; flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
    .tab-content { padding: 16px 12px 32px; }
    /* 제목과 오른쪽 버튼을 각각 한 줄씩 쓴다 */
    .section-head { flex-direction: column; align-items: stretch; }
    .section-head > * { width: 100%; }
    .section-head .btn-search { text-align: center; }
    /* 필터: 2개씩 자동 줄바꿈, 기간·조회는 한 줄 (관리자/농장주 공통) */
    .filter-row { flex-wrap: wrap; gap: 8px 10px; align-items: center; }
    .filter-group { flex: 1 1 42%; min-width: 0; }
    .filter-select { flex: 1; min-width: 0; }
    .filter-input { flex: 1; width: auto !important; min-width: 0; }
    .filter-period { flex: 1 1 100%; }
    .btn-search { flex: 1 1 100%; width: 100%; }
    /* 관리자 상단바: 2줄 */
    /* position 은 지정하지 않는다 — .top-bar 의 sticky 를 유지해야 함
       (sticky 도 positioned 이므로 settings-menu 의 absolute 기준점 역할을 함) */
    .top-bar-admin { display: flex; flex-wrap: wrap; align-items: center; row-gap: 8px; }
    .top-bar-admin .brand-title { order: 1; flex: 1 1 100%; text-align: center; }
    .top-bar-admin > :first-child { order: 2; flex: 0 0 auto; }
    .top-bar-admin .top-right { order: 3; flex: 1; display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
}

.page-btn {
    display: inline-block;
    padding: 6px 12px;
    background: #22304A;
    color: var(--text-dim);
    border-radius: 4px;
    font-size: 13px;
    text-decoration: none;
    border: 1px solid var(--border-soft);
}

.page-btn:hover {
    background: #2C3648;
    color: var(--text-primary);
}

.page-btn.active {
    background: var(--accent-cyan);
    color: #0B1220;
    font-weight: 700;
    border-color: var(--accent-cyan);
}

.more-wrap {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

.btn-more {
    padding: 8px 28px;
    background: #22304A;
    color: var(--accent-cyan);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
}

.btn-more:hover {
    background: #2C3648;
    border-color: var(--accent-cyan);
}

/* ===== 온습도 상세 (모달) ===== */
.env-detail-head { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:16px; }
.env-detail-title { font-size:17px; font-weight:800; flex:1; text-align:center; }
.env-stat-line { font-size:15px; font-weight:700; margin-top:4px; }
.env-table { width:100%; border-collapse:collapse; font-size:13px; }
.env-table th, .env-table td { padding:9px 8px; border-bottom:1px solid var(--border-soft); text-align:center; }
.env-table th { color:var(--text-dim); font-weight:600; background:var(--bg-table); }
.env-table td { font-weight:600; }
.env-paging { display:flex; align-items:center; justify-content:center; gap:14px; margin-top:16px; }
.env-page-ind { font-size:14px; font-weight:700; color:var(--text-dim); }

/* env 상세 통계 3칸 그리드 + 반응형 */
.env-stats-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:16px; }
.env-stat-box { padding:16px 14px; }
.env-stat3 { display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin-top:12px; }
.env-stat3 .s3 { text-align:center; }
.env-stat3 .s3-lbl { font-size:12px; color:var(--text-dim); margin-bottom:4px; }
.env-stat3 .s3-val { font-size:18px; font-weight:800; }
.env-head-spacer { width:64px; flex:0 0 auto; }
@media (max-width:480px) {
    .env-stats-grid { grid-template-columns:1fr; gap:10px; }
    .env-detail-title { font-size:15px; }
    .env-stat3 .s3-val { font-size:16px; }
    .env-table { font-size:12px; }
    .env-table th, .env-table td { padding:7px 4px; }
    .env-head-spacer { width:40px; }
}

/* ===== 피드빈 카드/온습도 모달 오버레이 (공통) ===== */
.fb-modal-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.62); z-index:1000; align-items:center; justify-content:center; padding:20px; }
.fb-modal-overlay.show { display:flex; }
.fb-modal { position:relative; background:var(--bg-card); border:1px solid var(--border-soft); border-radius:16px; width:780px; max-width:100%; max-height:92vh; overflow:auto; padding:26px 26px 20px; }
/* 모달 안에서는 카드가 이미 모달 테두리 안에 있으므로 자기 테두리·배경·패딩을 없앤다
   (테두리가 두 겹으로 보이던 문제) */
.fb-modal .fb-main {
    margin-bottom: 0;
    border: none;
    background: transparent;
    padding: 0;
}
/* '자세히' 상세 화면에서는 기존처럼 박스로 보여준다 (카드만 텍스트형) */
.env-detail .env-box {
    background: #0e1626;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 16px;
}

/* 카드 : 행(최저/평균/최고) × 열(온도/습도) 표 형태 */
/* 2열 그리드(.env-grid) 안에 들어가도 전체 폭을 쓰게 한다 (안 그러면 왼쪽 칸에만 갇힘) */
.env-grid > .env-stat { grid-column: 1 / -1; }

.env-stat {
    display: grid;
    /* 재고 정보 행(.stock-rows .r) 과 같은 폭·구분선을 쓰도록 전체 폭을 채운다 */
    grid-template-columns: auto repeat(3, 1fr);
    align-items: center;
    column-gap: 10px;
}
.env-stat .es-h {
    font-size: 14px;          /* 온도·습도 라벨과 같은 크기 */
    color: var(--text-dim);
    text-align: center;
    padding: 0 2px 6px;
}
.env-stat .es-k {
    font-size: 14px;
    color: var(--text-dim);
    text-align: left;
    padding: 9px 2px;
    border-bottom: 1px dashed var(--border-soft);
    white-space: nowrap;
}
.env-stat .es-v {
    font-size: 15px;
    font-weight: 800;
    text-align: center;
    padding: 9px 2px;
    border-bottom: 1px dashed var(--border-soft);
    white-space: nowrap;
}
.env-stat .es-v i { font-style: normal; font-size: 11px; font-weight: 700; margin-left: 1px; }

/* 좁은 화면 : 제목 + 정렬탭 + 필터가 겹치지 않게 줄을 나눈다.
   줄이 바뀌어도 버튼·입력칸이 가로로 늘어나지 않도록 크기를 고정한다. */
@media (max-width: 640px) {
    body .section-head { flex-wrap: wrap; gap: 8px; }
    body .section-title { flex: 1 1 100%; }
    body .sub-tabs { flex-wrap: wrap; }
    body .filter-row,
    body .section-filter { flex-wrap: wrap; gap: 8px; }

    /* 라벨은 글자 단위로 쪼개지지 않게 */
    body .filter-label { white-space: nowrap; flex: 0 0 auto; }
    /* 날짜처럼 요소가 많은 그룹은 한 줄을 통째로 쓰고, 모자라면 안에서 줄바꿈 */
    body .filter-group { flex-wrap: nowrap; }
    body .filter-group.filter-period { flex: 1 1 100%; flex-wrap: nowrap; }
    /* 날짜 두 칸이 한 줄에 들어가도록 폭을 줄여 고정한다 */
    body .filter-group.filter-period input[type=date] { flex: 0 1 auto; width: 118px; min-width: 0; padding: 4px 4px; }

    /* 줄이 바뀌어도 버튼·숫자 입력칸은 가로로 늘어나지 않게 (셀렉트는 기존 폭 유지) */
    body .btn-search { flex: 0 0 auto; width: auto; align-self: flex-start; }
    body .filter-input { flex: 0 0 auto; width: 55px; }
    body .filter-tag { flex: 0 0 auto; }
    body input[type=date] { flex: 0 0 auto; min-width: 132px; }
}

/* ── 좁은 화면(모바일)에서 피드빈 카드가 깨지지 않게 ──
   JSP 인라인 스타일(.fb-main 등)보다 우선하도록 body 를 붙여 특이도를 높인다. */
@media (max-width: 480px) {
    body .fb-main { grid-template-columns: 1fr; gap: 14px; padding: 16px; }
    body .fb-modal { padding: 18px 14px 14px; }

    /* 라벨이 글자 단위로 쪼개지지 않게 */
    body .ratio-big { white-space: nowrap; flex-wrap: nowrap; }
    body .ratio-row { flex-wrap: wrap; gap: 8px; }
    body .stock-rows .r { font-size: 13px; gap: 10px; }
    body .stock-rows .r .k { white-space: nowrap; }
    body .stock-rows .r .v { white-space: nowrap; text-align: right; }

    /* 섹션 제목 + 버튼 : 제목은 한 줄 유지, 버튼은 필요하면 아래로 */
    body .surface-row,
    body .env-section .fb-sec-head { flex-wrap: wrap; gap: 8px; }
    body .fb-sec-title { white-space: nowrap; font-size: 14px; }
}

/* 좁은 화면에서 값이 카드 밖으로 밀리지 않도록 줄인다 */
@media (max-width: 420px) {
    .env-stat { column-gap: 4px; }
    .env-stat .es-h { font-size: 12px; }
    .env-stat .es-k { font-size: 12px; }
    .env-stat .es-v { font-size: 13px; padding: 8px 0; }
    .env-stat .es-v i { font-size: 10px; margin-left: 0; }
}

/* 온습도 최저/평균/최고 : 카드에서는 박스 없이 한 줄 텍스트 */
.env-box .val-row { display:flex; justify-content:center; align-items:baseline;
                    gap:14px; flex-wrap:nowrap;
                    font-size:16px; font-weight:800; white-space:nowrap; }
.env-box .val-row em { font-style:normal; font-size:12px; font-weight:600;
                       color:var(--text-dim); margin-right:3px; }

.fb-modal-close { position:absolute; top:10px; right:16px; background:none; border:none; color:var(--text-dim); font-size:28px; line-height:1; cursor:pointer; z-index:2; }
.fb-modal-close:hover { color:var(--text-primary); }

/* 온습도 제목 : 조각 단위로만 줄바꿈 */
.env-detail-title { white-space: normal; }
.env-detail-title .nb { display: inline-block; white-space: nowrap; }

/* ===== 맨 위로 버튼 ===== */
.to-top {
    position: fixed;
    right: 24px;
    bottom: 28px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    color: var(--accent-cyan);
    border: 1px solid var(--border-soft);
    border-radius: 50%;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    z-index: 800;              /* 상단바(900)·모달(1000) 보다 아래 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity .18s, transform .18s, visibility .18s;
}
.to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.to-top:hover {
    border-color: var(--accent-cyan);
    color: var(--text-primary);
}
@media (max-width: 480px) {
    .to-top { right: 14px; bottom: 18px; width: 40px; height: 40px; font-size: 15px; }
}

/* 잔여사료 셀 : 가운데 정렬 유지(라벨과 같은 기준) */
.data-table td.col-feed { white-space: nowrap; }
/* 2D 버튼이 없는 행은 동일한 폭을 보이지 않게 채워 3D 위치를 맞춤 */
.btn-2d.btn-blank { visibility: hidden; pointer-events: none; }
/* 보관 기간이 지나 좌표가 없는 측정 : 버튼을 흐리게, 누를 수 없게 (툴팁은 보이도록 pointer-events 는 살린다) */
.btn-off, .btn-off:hover { opacity: .35; cursor: not-allowed; }
.btn-sm.btn-off:hover { background: transparent; }

/* 온습도 상세 : 최근 측정 시각 / 기록 없음 안내 */
.env-latest-date { text-align: center; color: var(--text-dim); font-size: 12px; margin: 2px 0 10px; }
.env-empty { text-align: center; color: var(--text-dim); padding: 26px 0; font-size: 13px; }

/* ══════════════════════════════════════════════════════════════
   공용 알림 / 확인 창
     브라우저 기본 alert · confirm 은 앱 WebView 에서 차단되거나
     시스템 팝업으로 떠서 화면과 어긋난다. 직접 그린 창을 쓴다.
   ══════════════════════════════════════════════════════════════ */
.ui-dialog-back { display: none; position: fixed; inset: 0; z-index: 3000;
                  background: rgba(0, 0, 0, .6); }
.ui-dialog-back.on { display: flex; align-items: center; justify-content: center; }
.ui-dialog-box { background: var(--bg-card); border: 1px solid var(--border-soft);
                 border-radius: 10px; padding: 22px 24px 18px;
                 width: 340px; max-width: 88vw; }
.ui-dialog-msg { font-size: 14px; line-height: 1.7; color: var(--text-primary);
                 white-space: pre-wrap; word-break: break-word; margin-bottom: 18px; }
.ui-dialog-actions { display: flex; gap: 8px; }
.ui-dialog-actions button { flex: 1; height: 38px; border: none; border-radius: 4px;
                            font-size: 13px; font-weight: 700; font-family: inherit;
                            cursor: pointer; }
.ui-dialog-no  { background: #2C3648; color: var(--text-primary); }
.ui-dialog-no:hover { background: #37455C; }
.ui-dialog-yes { background: var(--accent-cyan); color: #0B1220; }
.ui-dialog-yes:hover { filter: brightness(1.08); }

/* ───── 마지막으로 열어본 행 (lastRow.js) ─────
   목록에서 행을 눌러 다른 화면을 보거나 모달을 열었다 닫았을 때
   어디를 보고 있었는지 알려준다. 세션 동안만 유지된다. */
.data-table tbody tr.row-last > td {
    background: rgba(79, 195, 247, .10);
    box-shadow: inset 0 1px 0 rgba(79,195,247,.35), inset 0 -1px 0 rgba(79,195,247,.35);
}
.data-table tbody tr.row-last > td:first-child {
    box-shadow: inset 3px 0 0 var(--accent-cyan),
                inset 0 1px 0 rgba(79,195,247,.35), inset 0 -1px 0 rgba(79,195,247,.35);
}

/* ═════════════════════════════════════════════════════════════════════
   모달 높이 : 터치 기기(휴대폰·태블릿·앱 웹뷰) 전용 보정

   증상 : 긴 설정 모달의 아래(저장 버튼)가 잘리고 스크롤로도 닿지 않는다.
   원인 : ① 일부 화면은 상자에 높이 제한·스크롤이 없다 (제품·시험테스트·대리점 주문·농장주 피드빈).
          ② iOS 에서 vh 는 주소창·시스템 바가 숨은 상태의 높이라 실제 보이는 영역보다 크다.
             90vh 로 잡은 상자가 가운데 정렬되면 위아래로 삐져나가 버튼이 화면 밖에 남는다.

   · 상자 높이만 제한한다. 오버레이 여백·폭·정렬은 건드리지 않는다.
     가운데 정렬 화면은 위아래에 16px 씩 저절로 남고,
     위쪽 정렬 화면(농장주 피드빈, 여백 24px)도 상자 바닥이 화면 안에 들어온다.
   · 마우스를 쓰는 PC 는 hover:hover / pointer:fine 이라 이 블록 전체가 적용되지 않는다.
     화면 폭이 아니라 입력 장치로 가르므로 좁은 PC 창에서도 PC 동작 그대로다.
   · 각 화면의 <style> 이 이 파일보다 뒤에 나와 같은 선택자면 화면 쪽이 이긴다.
     그래서 한 단계 구체적인 선택자로 쓴다 (!important 없이 순서와 무관하게 이긴다).
       화면 .modal-box (클래스 1) < 여기 .modal-back .modal-box (클래스 2)
   · dvh 를 모르는 브라우저는 그 줄만 버리고 윗줄 vh 를 쓴다.
   · 기기 안전영역(노치·홈 막대)을 높이에서 뺀다. 지금은 viewport-fit=cover 가 없어 0 이다.
   ═════════════════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {

    /* 설정 화면들의 모달 (관리자·대리점·농장주 설정, 공통코드, 규격 관리, 대리점 주문) */
    .modal-back .modal-box {
        max-height: calc(100vh - 32px);
        max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overflow-y: auto;
        overscroll-behavior: contain;          /* 끝까지 내렸을 때 뒤 배경이 밀리지 않게 */
        -webkit-overflow-scrolling: touch;     /* 구형 iOS 관성 스크롤 */
    }

    /* 피드빈 카드 · 재고 재계산 모달 (측정내역, 홈). 오버레이 여백이 20px 이라 40px 을 뺀다 */
    .fb-modal-overlay .fb-modal {
        max-height: calc(100vh - 40px);
        max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
}