/* 모바일 전용 화면 — PC(style.css)와 완전히 분리 */
* { margin: 0; padding: 0; box-sizing: border-box; }
/* hidden 속성이 아래 display:flex 등에 밀리지 않도록 (뒤로 버튼만 자리 유지용 예외) */
[hidden]:not(#m-back) { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    background: #f3f4f6; color: #212529; font-size: 15px; line-height: 1.45;
    padding-top: calc(52px + env(safe-area-inset-top, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select { font-family: inherit; }

/* ── 상단 바 ── */
#m-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: #1a1a2e; color: #fff;
    display: flex; align-items: center; gap: 4px; padding-left: 4px; padding-right: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
#m-title { flex: 1; font-size: 16px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-iconbtn {
    width: 44px; height: 44px; border: none; background: none; color: #fff;
    font-size: 26px; line-height: 1; border-radius: 8px; cursor: pointer; flex-shrink: 0;
}
.m-iconbtn:active { background: rgba(255,255,255,0.15); }
#m-back { font-size: 32px; }
#m-back[hidden] { display: block; visibility: hidden; }

/* ── 드로어 ── */
#m-drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; }
#m-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 272px; max-width: 85vw; z-index: 201;
    background: #1a1a2e; color: #eee; display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
}
.m-drawer-head { padding: 18px 16px 14px; border-bottom: 1px solid #333; }
.m-drawer-brand { font-size: 15px; font-weight: 700; line-height: 1.35; }
#m-drawer-user { margin-top: 10px; font-size: 13px; color: #adb5bd; }
#m-drawer-user b { color: #fff; }
.m-badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; color: #fff; margin-right: 6px; }
.m-badge.admin { background: #ff6b6b; } .m-badge.user { background: #4dabf7; }
#m-nav { list-style: none; flex: 1; padding: 8px 0; overflow-y: auto; }
#m-nav a { display: block; padding: 14px 16px; color: #ccc; text-decoration: none; font-size: 15px; }
#m-nav a.active { background: #0f3460; color: #fff; font-weight: 600; }
#m-nav a:active { background: #16213e; }
#m-nav .m-nav-group { padding: 12px 16px 4px; font-size: 11px; color: #888; letter-spacing: 1px; }
#m-nav .m-nav-pid { font-size: 10px; color: #adb5bd; margin-right: 6px; font-family: monospace; }
.m-drawer-foot { border-top: 1px solid #333; padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); }
.m-drawer-link { display: block; padding: 13px 16px; color: #8fb3ff; text-decoration: none; font-size: 14px; }
.m-drawer-link:active { background: #16213e; }

/* ── 본문 ── */
#m-view { padding: 12px 12px 24px; max-width: 720px; margin: 0 auto; }
.m-card { background: #fff; border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.07); margin-bottom: 10px; }
.m-card.tap { cursor: pointer; }
.m-card.tap:active { background: #eef3ff; }
.m-h { font-size: 15px; font-weight: 700; margin: 14px 2px 8px; color: #1a1a2e; display: flex; align-items: baseline; gap: 8px; }
.m-h small { font-weight: 400; color: #868e96; font-size: 12px; }
.m-muted { color: #868e96; font-size: 13px; }
.m-small { font-size: 12px; }
.m-empty { padding: 36px 12px; text-align: center; color: #868e96; font-size: 14px; }
.m-err { background: #f8d7da; color: #721c24; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.m-info { background: #e8f4fd; color: #0c5460; padding: 12px 14px; border-radius: 10px; font-size: 13px; }

/* 입력·버튼 (터치 44px, iOS 확대 방지 16px) */
.m-input, .m-select {
    width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px;
    border: 1px solid #d0d5db; border-radius: 10px; background: #fff; color: #212529;
    -webkit-appearance: none; appearance: none;
}
.m-select { background-image: linear-gradient(45deg, transparent 50%, #868e96 50%), linear-gradient(135deg, #868e96 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.m-btn {
    min-height: 46px; padding: 10px 16px; font-size: 15px; font-weight: 600; border: none;
    border-radius: 10px; cursor: pointer; background: #e9ecef; color: #333; width: 100%;
}
.m-btn:active { filter: brightness(0.93); }
.m-btn.primary { background: #0f3460; color: #fff; }
.m-btn.ghost { background: #fff; border: 1px solid #d0d5db; }
.m-btn:disabled { opacity: 0.55; }
.m-row { display: flex; gap: 8px; }
.m-row > * { flex: 1; min-width: 0; }
.m-row > .m-btn { width: auto; }
.m-searchbox { position: relative; }
.m-searchbox .m-input { padding-right: 44px; }
.m-searchbox .m-clear { position: absolute; right: 2px; top: 1px; width: 44px; height: 44px; border: none; background: none; font-size: 20px; color: #adb5bd; }
.m-filters { display: none; margin-top: 8px; flex-direction: column; gap: 8px; }
.m-filters.open { display: flex; }
.m-chipbar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.m-chip { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; background: #f1f3f5; color: #495057; }
.m-chip.on { background: #e7f0ff; color: #0f3460; font-weight: 600; }

/* 업체 카드 */
.m-co-name { font-size: 16px; font-weight: 700; color: #1a1a2e; }
.m-co-sub { font-size: 12px; color: #868e96; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.m-co-addr { font-size: 13px; color: #495057; margin-top: 6px; }
.m-co-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.m-pill { flex-shrink: 0; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 10px; white-space: nowrap; }
.m-pill.ok { background: #d3f9d8; color: #2b8a3e; }
.m-pill.zero { background: #fff3bf; color: #e67700; }
.m-pill.none { background: #f1f3f5; color: #adb5bd; }

/* 상세 키-값 */
.m-kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; font-size: 14px; }
.m-kv dt { color: #868e96; font-weight: 600; font-size: 13px; }
.m-kv dd { color: #212529; word-break: break-word; white-space: pre-wrap; min-width: 0; }
.m-kv dd:empty::before, .m-kv dd.none { content: '-'; color: #ced4da; }
.m-kv a { color: #1c7ed6; text-decoration: none; }

/* 제품 카드 */
.m-pr-name { font-size: 15px; font-weight: 600; color: #212529; }
.m-pr-meta { font-size: 12px; color: #868e96; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.m-pr-qty { font-size: 13px; color: #0f3460; font-weight: 600; margin-top: 4px; }
.m-pr-qty small { font-weight: 400; color: #868e96; }
.m-pr-mat { font-size: 12px; color: #495057; margin-top: 5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* 작은 표 (3컬럼 이하만 사용) */
.m-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.m-table th { text-align: left; background: #f8f9fa; padding: 7px 8px; font-weight: 600; color: #495057; }
.m-table td { padding: 7px 8px; border-top: 1px solid #f1f3f5; }
.m-table .r { text-align: right; }

/* 간단 막대 (연도별 추이) */
.m-bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; padding: 4px 2px 0; }
.m-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.m-bar i { display: block; width: 100%; max-width: 36px; background: #4dabf7; border-radius: 4px 4px 0 0; }
.m-bar b { font-size: 11px; color: #495057; margin-bottom: 2px; }
.m-bar span { font-size: 10px; color: #868e96; margin-top: 3px; white-space: nowrap; }

/* 로딩 */
.m-loading { text-align: center; padding: 40px; color: #868e96; }
.m-spin { display: inline-block; width: 24px; height: 24px; border: 3px solid #dee2e6; border-top-color: #0f3460; border-radius: 50%; animation: mspin 0.7s linear infinite; }
@keyframes mspin { to { transform: rotate(360deg); } }

/* 로그인 */
.m-login { max-width: 380px; margin: 40px auto; }
.m-login h1 { font-size: 19px; margin-bottom: 4px; }
.m-login .m-input { margin-bottom: 10px; }
.m-login-err { color: #e03131; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 섹션 접기 */
details.m-sec { background: #fff; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.07); margin-bottom: 10px; }
details.m-sec summary { padding: 13px 14px; font-weight: 700; font-size: 15px; cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.m-sec summary::-webkit-details-marker { display: none; }
details.m-sec summary::after { content: '+'; color: #adb5bd; font-size: 18px; }
details.m-sec[open] summary::after { content: '−'; }
details.m-sec summary small { font-weight: 400; color: #868e96; font-size: 12px; margin-left: 6px; }
details.m-sec .m-sec-body { padding: 0 14px 14px; }

/* 세그먼트 탭 (P21 업체/품목 전환) + 날짜 배지 */
.m-seg { display: flex; background: #f1f3f5; border-radius: 10px; padding: 3px; }
.m-seg button { flex: 1; min-height: 40px; border: none; border-radius: 8px; background: none; font-size: 14px; font-weight: 600; color: #868e96; cursor: pointer; }
.m-seg button.on { background: #fff; color: #0f3460; box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.m-date { flex-shrink: 0; font-size: 12px; color: #495057; background: #f1f3f5; padding: 3px 8px; border-radius: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-row .m-searchbox { flex: 1; min-width: 0; }
