/* ══════════════════════════════════════════════
   AgriPipe Simulator – Mobile-First CSS
   - 워드프레스 테마 여백 강제 초기화
   - overflow: hidden 제거 → 라벨 잘림 방지
   - 반응형 테이블: 모바일에서 100% 폭 확보
   ══════════════════════════════════════════════ */

/* 테마가 컨테이너에 overflow-x:hidden + max-width를 걸어도
   플러그인 래퍼는 항상 전체 폭을 사용하도록 강제 초기화 */
.agripipe-wrap,
.agripipe-wrap *,
#agripipe-simulator,
#agripipe-simulator * {
    max-width: none;
}

/* 워드프레스 테마 여백 초기화 – 숏코드 래퍼 */
#agripipe-simulator.ap19,
#agripipe-simulator.ap19 * {
    box-sizing: border-box;
}

#agripipe-simulator.ap19 {
    /* Design System Palette */
    --ap-bg: #fdfdf8;
    --ap-surface: #ffffff;
    --ap-surface-2: #eeefe9;
    --ap-surface-3: #e5e7e0;
    --ap-border: #bfc1b7;
    --ap-border-s: #b6b7af;
    --ap-ink: #4d4f46;
    --ap-ink-2: #23251d;
    --ap-ink-3: #65675e;
    --ap-ink-4: #9ea096;
    --ap-brand: #23251d;
    --ap-brand-soft: #eeefe9;
    --ap-accent: #d4c9b8;
    --ap-accent-border: #b17816;
    --ap-good: #2f9e6f;
    --ap-warn: #F7A501;
    --ap-bad: #c0392b;
    --ap-focus: rgba(59,130,246,.5);
    --ap-r: 10px;
    --ap-r-lg: 16px;
    --ap-shadow-sm: 0 1px 2px rgba(11,20,38,.05),0 1px 1px rgba(11,20,38,.04);

    /* 시스템 폰트 우선 사용 – Google Fonts 외부 요청 없음 */
    font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--ap-bg);
    color: var(--ap-ink);
    border-radius: var(--ap-r-lg);
    /* overflow: hidden 제거 – 캔버스 라벨 우측 잘림 원인 */
    overflow: visible;
    line-height: 1.5;
    font-size: 14.5px;
    /* 테마 margin/padding 강제 초기화 */
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* ── 공통 카드 ─────────────────────── */
.ap19-card { background: var(--ap-surface); border: 1px solid var(--ap-border); border-radius: var(--ap-r); box-shadow: var(--ap-shadow-sm); overflow: hidden; }
.ap19-card-header { display: flex; align-items: center; gap: 9px; padding: 12px 14px; border-bottom: 1px solid var(--ap-border); background: var(--ap-surface-2); }
.ap19-card-header::before { content: ''; display: block; width: 3px; height: 18px; background: var(--ap-ink-2); border-radius: 2px; flex-shrink: 0; }
.ap19-card-header h3 { margin: 0; font-size: .9rem; font-weight: 700; color: var(--ap-ink-2); }
.ap19-card-body { padding: 14px; }

/* ── 상단바 ────────────────────────── */
.ap19-topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--ap-border); background: var(--ap-surface); flex-wrap: wrap; gap: 8px; border-radius: var(--ap-r-lg) var(--ap-r-lg) 0 0; overflow: hidden; }
.ap19-topbar-logo { display: flex; align-items: center; gap: 8px; }
.ap19-topbar-logo .ap19-badge { background: var(--ap-ink-2); color: #fff; font-size: .65rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.ap19-topbar-logo h2 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--ap-ink-2); }

/* ── 버튼 ──────────────────────────── */
.ap19-btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--ap-border-s); background: var(--ap-surface-3); color: var(--ap-ink-2); font-size: .82rem; font-weight: 600; cursor: pointer; transition: background .14s,color .14s,border-color .14s; white-space: nowrap; }
.ap19-btn:hover { background: #f4f4f4; color: #F54E00; border-color: #F54E00; }
.ap19-btn:focus-visible { outline: 2px solid #3b82f6; outline-offset: 2px; }
.ap19-btn.primary { background: var(--ap-brand); border-color: var(--ap-brand); color: #fff; }
.ap19-btn.primary:hover { background: #F7A501; border-color: #F7A501; }
.ap19-btn.accent { background: var(--ap-accent); border-color: var(--ap-accent-border); color: var(--ap-ink-2); }
.ap19-btn.accent:hover { background: #F7A501; border-color: #F7A501; color: #fff; }

/* ── 메인 레이아웃 ─────────────────── */
.ap19-main { padding: 10px 8px 16px; display: flex; flex-direction: column; gap: 12px; }
.ap19-split { display: grid; grid-template-columns: 1fr 340px; gap: 12px; align-items: start; }
.ap19-col-left, .ap19-col-right { display: flex; flex-direction: column; gap: 12px; }

/* ── 캔버스 ── overflow:visible 로 라벨 보임 ── */
.ap19-canvas-top { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--ap-surface-2); border-bottom: 1px solid var(--ap-border); }
#canvas-wrapper { position: relative; width: 100%; height: 280px; background: #0a1628; overflow: hidden; border-radius: 0 0 var(--ap-r) var(--ap-r); }
#three-container { width: 100%; height: 100%; cursor: grab; }
.ap19-canvas-lbl { position: absolute; color: #fff; padding: 3px 8px; border-radius: 12px; font-size: .7rem; font-weight: 700; font-family: 'SF Mono','Consolas','Liberation Mono',monospace; pointer-events: none; transform: translate(-50%,-100%); white-space: nowrap; max-width: calc(50% - 4px); }

/* ── 탭 ────────────────────────────── */
.ap19-tab-wrap { display: flex; gap: 3px; padding: 12px 10px 0; }
.ap19-tab-btn { padding: 7px 12px; border-radius: 8px 8px 0 0; border: 1px solid var(--ap-border); border-bottom: none; background: var(--ap-surface-3); color: var(--ap-ink-3); font-size: .82rem; font-weight: 600; cursor: pointer; transition: background .2s,color .2s; white-space: nowrap; }
.ap19-tab-btn:hover { background: #f4f4f4; color: #F54E00; }
.ap19-tab-btn.active { background: var(--ap-surface); color: var(--ap-ink-2); border-top: 3px solid var(--ap-ink-2); margin-bottom: -1px; }
.ap19-controls-body { background: var(--ap-surface); border: 1px solid var(--ap-border); border-top: none; border-radius: 0 0 var(--ap-r) var(--ap-r); padding: 14px 10px; }

/* ── 컨트롤 그리드 ─────────────────── */
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(140px,1fr)); gap: 10px; }
.controls-grid label { display: block; font-size: .8rem; font-weight: 600; color: var(--ap-ink-2); }
.controls-grid label span { float: right; font-family: 'SF Mono','Consolas','Liberation Mono',monospace; color: var(--ap-ink-3); }
.controls-grid input[type="range"], .controls-grid select, .ap19-input { width: 100%; margin-top: 6px; }
.controls-grid input[type="range"] { height: 4px; background: var(--ap-surface-3); appearance: none; border-radius: 4px; }
.controls-grid select, .ap19-input { padding: 7px 8px; border: 1px solid var(--ap-border-s); border-radius: 6px; font-size: .82rem; background: var(--ap-surface-2); color: var(--ap-ink); transition: border-color .2s; }
.controls-grid select:focus, .ap19-input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px var(--ap-focus); }
.ap19-input::placeholder { color: var(--ap-ink-4); }

/* ── 위자드 ────────────────────────── */
.ap19-wizard-nav { display: flex; margin-bottom: 14px; border-bottom: 2px solid var(--ap-surface-3); }
.ap19-wiz-step { flex: 1; text-align: center; padding: 8px 2px; color: var(--ap-ink-4); font-size: .78rem; font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; transition: color .2s; }
.ap19-wiz-step:hover { color: #F54E00; }
.ap19-wiz-step.active { color: var(--ap-ink-2); border-bottom-color: var(--ap-ink-2); }
.ap19-wiz-content { display: none; }
.ap19-wiz-content.active { display: block; }
.ap19-wiz-actions { display: flex; justify-content: space-between; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--ap-border); }

/* ── 안전지표 ──────────────────────── */
.ap19-metric { margin-bottom: 10px; }
.ap19-metric-head { display: flex; justify-content: space-between; font-size: .8rem; margin-bottom: 4px; font-weight: 500; color: var(--ap-ink); }
.ap19-metric-head .ap19-metric-val { font-family: 'SF Mono','Consolas','Liberation Mono',monospace; font-weight: 700; color: var(--ap-ink-2); }
.ap19-progress-track { background: var(--ap-surface-3); height: 7px; border-radius: 4px; }
.ap19-progress-fill { height: 100%; border-radius: 4px; background: var(--ap-good); transition: width .35s; }

/* ── 자재표 – 반응형 래퍼 추가 ─────── */
.ap19-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ap19-mat-table { width: 100%; min-width: 260px; border-collapse: collapse; font-size: .83rem; text-align: left; color: var(--ap-ink); }
.ap19-mat-table th { background: var(--ap-ink-2); color: #fff; padding: 8px 10px; white-space: nowrap; }
.ap19-mat-table td { padding: 8px 10px; border-bottom: 1px solid var(--ap-border); }

/* ── 모달 ──────────────────────────── */
.ap19-modal-bg { display: none; position: fixed; inset: 0; background: rgba(11,20,38,.6); z-index: 9999; align-items: center; justify-content: center; padding: 16px; }
.ap19-modal-box { background: var(--ap-surface); border-radius: 14px; padding: 22px 18px 18px; width: 100%; max-width: 420px; box-shadow: 0 10px 25px rgba(0,0,0,.15); }

/* ════════════════════════════════════
   반응형 – 모바일 우선
   ════════════════════════════════════ */
@media (max-width: 768px) {
    #agripipe-simulator.ap19 { border-radius: 0; }
    .ap19-main { padding: 8px 0 14px; gap: 8px; }
    .ap19-split { grid-template-columns: 1fr; }
    /* 카드가 화면 폭 100% 꽉 차도록 */
    .ap19-card { border-radius: 0; border-left: none; border-right: none; }
    .ap19-topbar { padding: 8px 10px; border-radius: 0; }
    .ap19-controls-body { padding: 10px 8px; border-left: none; border-right: none; border-radius: 0; }
    .ap19-tab-wrap { padding: 10px 8px 0; }
    .ap19-tab-btn { padding: 6px 10px; font-size: .78rem; flex: 1; text-align: center; }
    .controls-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    #canvas-wrapper { height: 200px; }
    .ap19-card-body { padding: 10px 10px; }
    /* 자재표 전체 폭 */
    .ap19-table-scroll { margin: 0; }
    .ap19-mat-table th, .ap19-mat-table td { padding: 7px 8px; font-size: .78rem; }
}

@media (max-width: 480px) {
    .ap19-main { padding: 6px 0 12px; }
    .controls-grid { grid-template-columns: 1fr; }
    .ap19-wizard-nav { overflow-x: auto; gap: 0; }
    .ap19-wiz-step { font-size: .72rem; padding: 6px 2px; min-width: 56px; }
    .ap19-btn { font-size: .78rem; padding: 7px 8px; }
    /* 견적 버튼 영역 세로 배치 */
    .ap19-ctrl-submit { flex-direction: column !important; }
    .ap19-ctrl-submit .ap19-btn { flex: none !important; width: 100%; }
}

/* ── 인쇄 ──────────────────────────── */
@media print { .no-print { display: none !important; } }
