:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-color: #f1f5f9;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 14px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --header-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: 'Pretendard', sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    height: 100%;
    overflow: hidden;
}

/* ── 헤더 ── */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(99,102,241,0.3);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.header-emoji { font-size: 1.4rem; }

.header-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.header-sub {
    font-size: 0.7rem;
    opacity: 0.75;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.hdr-btn {
    background: rgba(255,255,255,0.18);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: auto;
    white-space: nowrap;
    font-family: inherit;
}

.hdr-btn:hover { background: rgba(255,255,255,0.28); transform: none; }

.count-badge {
    display: inline-block;
    background: rgba(255,255,255,0.35);
    border-radius: 999px;
    padding: 0.05rem 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

/* ── 히스토리 드롭다운 ── */
.history-dropdown {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    z-index: 50;
    background: white;
    border-bottom: 2px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    max-height: 55vh;
    overflow-y: auto;
}

.history-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-muted);
    background: #f8fafc;
    position: sticky;
    top: 0;
}

.history-clear-btn {
    background: none;
    color: #ef4444;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    padding: 0.2rem 0.55rem;
    font-size: 0.78rem;
    cursor: pointer;
    min-height: auto;
    font-family: inherit;
    font-weight: 600;
}
.history-clear-btn:hover { background: #fef2f2; transform: none; }

.history-list-scroll { padding: 0.25rem 0; }

.history-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f1f5f9;
}
.history-item:hover { background: #f8fafc; }
.history-item.active { background: #eef2ff; }

.history-item-text {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}

.history-item-answer {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 380px;
}

.history-item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: auto;
    flex-shrink: 0;
}

/* ── 메인 바디 ── */
.app-body {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0; bottom: 0;
    display: grid;
    grid-template-rows: 1fr auto auto;
    grid-template-columns: 1fr;
    max-width: 860px;
    margin: 0 auto;
    padding: 0.75rem 1rem 0.5rem;
    gap: 0;
    overflow: hidden;
}

/* ── 답변 영역 ── */
.answer-wrapper {
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 0.6rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #c7d2fe transparent;
    min-height: 0;        /* grid 1fr 내에서 축소 허용 */
    display: flex;
    flex-direction: column;
}
.answer-wrapper::-webkit-scrollbar { width: 5px; }
.answer-wrapper::-webkit-scrollbar-thumb { background: #c7d2fe; border-radius: 999px; }
.answer-wrapper::-webkit-scrollbar-track { background: transparent; }

.answer-box {
    flex: 1 1 auto;       /* height:100% 대신 flex로 채움 */
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    min-height: 120px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    line-height: 1.8;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    font-size: 0.97rem;
    color: var(--text-main);
    overflow: hidden;     /* 박스 밖으로 텍스트 새어나오지 않게 */
}

.answer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    color: var(--text-muted);
    text-align: center;
    gap: 0.5rem;
}

.placeholder-icon { font-size: 2.5rem; }
.placeholder-text { font-size: 1.05rem; font-weight: 700; color: #94a3b8; }
.placeholder-sub { font-size: 0.82rem; color: #cbd5e1; }

/* ── 빠른 액션 칩 ── */
.quick-chips {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding: 0.25rem 0 0.5rem;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.quick-chips::-webkit-scrollbar { display: none; }

.chip {
    background: white;
    color: var(--primary);
    border: 1.5px solid #c7d2fe;
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s;
    min-height: auto;
    font-family: inherit;
    flex-shrink: 0;
}
.chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99,102,241,0.25);
}

/* ── 입력 영역 ── */
.input-area {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding-top: 0.6rem;
}

.input-row {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
}

.input-row textarea {
    flex: 1;
    height: 80px;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.97rem;
    resize: none;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-main);
    line-height: 1.6;
}
.input-row textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}

#askBtn {
    width: 80px;
    min-height: 80px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    flex-shrink: 0;
    line-height: 1.4;
}
#askBtn:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(99,102,241,0.35); }
#askBtn:active { transform: translateY(0); }
#askBtn:disabled { opacity: 0.6; transform: none; cursor: default; }

.input-hint {
    font-size: 0.72rem;
    color: #94a3b8;
    padding: 0.3rem 0.25rem 0;
}

/* ── 디버그 오버레이/드로어 ── */
.debug-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.35);
    z-index: 200;
    backdrop-filter: blur(2px);
}
.debug-overlay.show { display: block; }

.debug-drawer {
    position: fixed;
    top: 0;
    right: -540px;
    width: 520px;
    height: 100vh;
    background: white;
    box-shadow: -6px 0 32px rgba(0,0,0,0.15);
    z-index: 201;
    transition: right 0.28s cubic-bezier(.4,0,.2,1);
    display: flex;
    flex-direction: column;
}
.debug-drawer.open { right: 0; }

.debug-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
    flex-shrink: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    min-height: auto;
    line-height: 1;
    transition: all 0.15s;
}
.close-btn:hover { background: #f1f5f9; color: var(--text-main); transform: none; }

/* ── 탭 ── */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    padding: 0.65rem 0.9rem;
    cursor: pointer;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    white-space: nowrap;
    user-select: none;
}
.tab:hover { color: var(--primary); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: white;
}

.tab-badge {
    display: inline-block;
    background: #e0e7ff;
    color: var(--primary);
    border-radius: 999px;
    padding: 0 0.4rem;
    font-size: 0.72rem;
    margin-left: 0.25rem;
}

.debug-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }
.tab-content.active { display: block; }

/* ── 과업 감시 ── */
.guard-box {
    background: #f8fafc;
    border-radius: 10px;
    padding: 1rem 1.1rem;
    border-left: 4px solid #94a3b8;
    font-size: 0.92rem;
    line-height: 1.65;
}
.guard-box.good { border-left-color: #10b981; background: #f0fdf4; }
.guard-box.warn { border-left-color: #f59e0b; background: #fffbeb; }
.guard-box.bad  { border-left-color: #ef4444; background: #fef2f2; }

.guard-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}
.guard-title { font-weight: 700; font-size: 0.95rem; }
.guard-badge {
    background: #e0e7ff;
    color: #4338ca;
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
}
.guard-desc { color: var(--text-muted); font-size: 0.88rem; }

/* ── 추론 박스 ── */
.reasoning-box {
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap;
    color: var(--text-main);
}

/* ── 참고 문서 ── */
.hit-item {
    background: #f8fafc;
    border-radius: 8px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.65rem;
    border: 1px solid var(--border);
}
.hit-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
}
.meta-pill {
    background: #e0e7ff;
    color: #4338ca;
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.73rem;
    font-weight: 600;
}

/* ── 엔진 로그 ── */
.trace-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}
.trace-copy-btn {
    background: #f1f5f9;
    color: var(--primary);
    border: 1px solid #c7d2fe;
    border-radius: 7px;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    min-height: auto;
    font-family: inherit;
    transition: all 0.15s;
}
.trace-copy-btn:hover { background: var(--primary); color: white; transform: none; }

.trace-copy-status {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.trace-box {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    white-space: pre-wrap;
    background: #0f172a;
    color: #94a3b8;
    border-radius: 8px;
    padding: 0.9rem 1rem;
    overflow-x: auto;
}

/* APPROVAL_BUTTON_STYLES_V1 */
.approval-action-bar {
    margin: 12px 0 4px;
    padding: 12px 14px;
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.approval-bar-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #92400e;
}
.approval-bar-btns {
    display: flex;
    gap: 10px;
}
.approval-btn {
    padding: 7px 20px;
    border-radius: 7px;
    border: none;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .15s;
}
.approval-btn:hover { opacity: .82; }
.approval-btn--confirm {
    background: #16a34a;
    color: #fff;
}
.approval-btn--cancel {
    background: #dc2626;
    color: #fff;
}
@media (max-width: 600px) {
    .approval-bar-btns { flex-direction: column; }
    .approval-btn { width: 100%; }
}
