/* ============================================================
   genffice-tripreport — 셸 디자인 시스템

   토큰 체계와 4열 그리드는 genffice-docs · genffice-ksp 를 그대로 계승한다.
   액센트만 교체했다 (docs 인디고 / slide 주황 / ksp KDI블루 / tripreport 딥틸).
   같은 자리에 같은 이름을 쓰므로 셸 코드는 형제 앱 사이에서 옮겨 쓸 수 있다.
   ============================================================ */

:root {
  /* Surfaces */
  --bg-app: #fbfbfc;
  --bg-panel: #ffffff;
  --bg-sidebar: #f8f8fa;
  --bg-subtle: #f3f3f6;
  --bg-hover: #eeeef2;
  --bg-active: #e7e7ed;

  /* Text */
  --text-1: #18181b;
  --text-2: #5b5b66;
  --text-3: #8a8a95;
  --text-inv: #ffffff;

  /* Borders */
  --border-1: #ededf1;
  --border-2: #e0e0e6;
  --border-3: #c9c9d2;

  /* Accent — 딥틸 */
  --accent: #0f6f68;
  --accent-hover: #0c5f59;
  --accent-press: #0a4f4a;
  --accent-subtle: #e9f4f3;
  --accent-border: #c2e0dd;
  --accent-text: #0c5f59;

  /* Semantic */
  --success: #167c3c;
  --success-subtle: #e9f6ed;
  --warning: #9a5700;
  --warning-subtle: #fdf2e4;
  --danger: #c22b2b;
  --danger-subtle: #fdecec;
  --danger-border: #f5c9c9;

  /* 근거 추적 — 이 앱 고유의 축이라 토큰을 따로 둔다 */
  --ev: #7c3aed;
  --ev-subtle: #f4effe;
  --ev-border: #ddcffb;

  /* Type scale */
  --fs-10: 10px;
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-17: 17px;

  /* Radius */
  --r-4: 4px;
  --r-6: 6px;
  --r-8: 8px;
  --r-10: 10px;
  --r-14: 14px;

  /* Elevation */
  --sh-1: 0 1px 2px rgba(20, 20, 35, .05);
  --sh-2: 0 4px 12px rgba(20, 20, 35, .07), 0 0 0 1px rgba(20, 20, 35, .04);
  --sh-3: 0 16px 48px rgba(20, 20, 35, .16), 0 0 0 1px rgba(20, 20, 35, .06);
  --ring: 0 0 0 3px rgba(15, 111, 104, .16);

  /* Layout — Genffice 표준 4열 (메뉴 | 작업 | 대화 | 지면)
     인스펙터는 5번째 열이 아니라 **지면 열 안에서 지면 왼쪽에** 붙는다.
     그래서 접어도 4열 골격이 그대로 남고, 펼쳐도 지면은 맨 오른쪽이다. */
  --menu-w: 208px;
  --work-w: 276px;
  --stream-w: 380px;
  --insp-w: 400px;
  --split-w: 1px;
  --hit: 9px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
.hidden { display: none !important; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "Pretendard Variable", Pretendard, "Apple SD Gothic Neo",
    "Malgun Gothic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--fs-13);
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font-family: inherit; }
::selection { background: rgba(15, 111, 104, .18); }

* { scrollbar-width: thin; scrollbar-color: var(--border-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: transparent; border: 3px solid transparent;
  border-radius: 8px; background-clip: padding-box;
}
*:hover::-webkit-scrollbar-thumb { background: var(--border-3); background-clip: padding-box; }

/* ============================================================
   셸 — 4열 그리드
   ============================================================ */

.app {
  display: grid;
  grid-template-columns:
    var(--menu-w) var(--split-w)
    var(--work-w) var(--split-w)
    var(--stream-w) var(--split-w)
    minmax(320px, 1fr);
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.app.resizing { cursor: col-resize; user-select: none; }

.splitter {
  position: relative; z-index: 20;
  width: var(--split-w);
  background: var(--border-1);
  cursor: col-resize; touch-action: none;
  border: 0; padding: 0;
}
.splitter::after {
  content: ""; position: absolute; top: 0; bottom: 0;
  left: calc(var(--hit) * -1); right: calc(var(--hit) * -1);
}
.splitter::before {
  content: ""; position: absolute; inset: 0;
  background: transparent; transition: background .12s ease;
}
.splitter:hover::before,
.splitter:focus-visible::before,
.app.resizing .splitter.active::before {
  background: var(--accent); box-shadow: 0 0 0 1px var(--accent);
}
.splitter:focus-visible { outline: none; }

/* ============================================================
   버튼
   ============================================================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--border-2); border-radius: var(--r-6);
  background: var(--bg-panel); color: var(--text-1);
  font: inherit; font-size: var(--fs-12); font-weight: 500;
  white-space: nowrap; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover:not(:disabled) { background: var(--bg-subtle); border-color: var(--border-3); }
.btn:active:not(:disabled) { background: var(--bg-active); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { cursor: not-allowed; color: var(--text-3); }

.btn.primary {
  background: var(--accent); border-color: transparent;
  color: var(--text-inv); box-shadow: var(--sh-1);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: transparent; }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }
.btn.primary:disabled { background: var(--bg-subtle); border-color: var(--border-2); color: var(--text-3); box-shadow: none; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-1); }

.btn.icon { width: 28px; padding: 0; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn.sm { height: 24px; padding: 0 8px; font-size: var(--fs-11); }

/* ============================================================
   1열 · 메뉴
   ============================================================ */

.menu {
  display: flex; flex-direction: column; min-height: 0;
  padding: 12px 10px;
  background: var(--bg-sidebar);
  overflow: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 4px 6px 14px; }
.brand .logo {
  display: grid; place-items: center;
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 7px;
  background: linear-gradient(150deg, var(--accent), #2f9a91);
  color: #fff; font-size: var(--fs-11); font-weight: 700;
  letter-spacing: -.02em; box-shadow: var(--sh-1);
}
.brand .txt { min-width: 0; display: flex; flex-direction: column; }
.brand .mark { font-size: var(--fs-13); font-weight: 650; letter-spacing: -.01em; color: var(--text-1); line-height: 1.25; }
.brand .sub {
  font-size: var(--fs-11); color: var(--text-3); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav-label { padding: 12px 8px 4px; font-size: var(--fs-11); font-weight: 600; letter-spacing: .03em; color: var(--text-3); }

.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; height: 30px; padding: 0 8px;
  border: 0; border-radius: var(--r-6);
  background: transparent; color: var(--text-2);
  font: inherit; font-size: var(--fs-13); font-weight: 500;
  text-align: left; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active { background: var(--accent-subtle); color: var(--accent-text); font-weight: 600; }
.nav-item:focus-visible { outline: none; box-shadow: var(--ring); }
.nav-item .ico { display: grid; place-items: center; width: 16px; height: 16px; flex-shrink: 0; opacity: .85; }
.nav-item .ico svg { width: 16px; height: 16px; }
.nav-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .kb { font-size: var(--fs-10); font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; flex-shrink: 0; }

@keyframes stpulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

.menu-foot { margin-top: auto; padding: 10px 8px 2px; border-top: 1px solid var(--border-1); }
.model-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 8px; border-radius: var(--r-6);
  background: var(--bg-panel); border: 1px solid var(--border-1);
}
.model-chip .dot { width: 6px; height: 6px; flex-shrink: 0; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px var(--success-subtle); }
.model-chip strong { min-width: 0; font-size: var(--fs-11); font-weight: 600; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   2열 · 작업 패널
   ============================================================ */

.work { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg-panel); overflow: hidden; }

.panel-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 12px;
  border-bottom: 1px solid var(--border-1);
}
.panel-head h2 { font-size: var(--fs-13); font-weight: 650; letter-spacing: -.01em; }
.panel-head .badge {
  margin-left: auto; flex-shrink: 0;
  padding: 2px 7px; border-radius: 20px;
  background: var(--bg-subtle); border: 1px solid var(--border-1);
  font-size: var(--fs-11); font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.panel-head .badge.warn { background: var(--warning-subtle); border-color: transparent; color: var(--warning); }
.panel-head .badge.done { background: var(--success-subtle); border-color: transparent; color: var(--success); }

/* 5단계 프로세스 — genffice-ksp 2열 상단 .steps 와 같은 자리 */
.steps {
  flex: 0 0 auto; display: flex; gap: 3px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-1); background: var(--bg-sidebar);
}
.step-b {
  flex: 1; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px 5px;
  border: 1px solid transparent; border-radius: var(--r-6);
  background: transparent; color: var(--text-3);
  font: inherit; font-size: var(--fs-10); font-weight: 600;
  cursor: pointer; transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.step-b .si { display: grid; place-items: center; width: 15px; height: 15px; }
.step-b .si svg { width: 15px; height: 15px; }
.step-b .sl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-b .sd { position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--border-3); }
.step-b .sd[data-s="running"] { background: var(--warning); animation: stpulse 1.1s infinite; }
.step-b .sd[data-s="done"] { background: var(--success); }
.step-b .sd[data-s="ask"] { background: var(--danger); animation: stpulse 1.1s infinite; }
.step-b:hover:not(:disabled) { background: var(--bg-panel); color: var(--text-2); }
.step-b.ok { color: var(--success); }
.step-b.on { background: var(--bg-panel); border-color: var(--accent); color: var(--accent-text); box-shadow: var(--sh-1); }
.step-b:disabled { opacity: .4; cursor: not-allowed; }

.work-progress { flex: 0 0 auto; height: 2px; background: var(--bg-subtle); }
.work-progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .45s ease; }

.work-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }

.work-foot {
  flex: 0 0 auto; display: flex; gap: 6px; padding: 9px 10px;
  border-top: 1px solid var(--border-1); background: var(--bg-sidebar);
}
.work-foot .btn { flex: 1; }

.panel-empty { padding: 40px 20px; text-align: center; color: var(--text-3); }
.panel-empty b { display: block; font-size: var(--fs-12); font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.panel-empty span { font-size: var(--fs-11); line-height: 1.65; }

/* ============================================================
   4열 · 지면
   ============================================================ */

.canvas { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg-app); }
.cv-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 6px 14px;
  border-bottom: 1px solid var(--border-1); background: var(--bg-panel);
  flex-wrap: wrap;
}
.cv-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }

.cv-tabs { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--r-6); background: var(--bg-subtle); }
.cv-tab {
  border: 0; border-radius: var(--r-4); background: transparent;
  padding: 4px 10px; font: inherit; font-size: var(--fs-11); font-weight: 600;
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.cv-tab:hover { color: var(--text-1); }
.cv-tab.on { background: var(--bg-panel); color: var(--accent-text); box-shadow: var(--sh-1); }
.cv-tab .n { font-size: 9.5px; font-weight: 700; opacity: .65; margin-left: 3px; font-variant-numeric: tabular-nums; }

.cv-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: var(--fs-11); color: var(--text-3); min-width: 0; }
.cv-meta b { font-size: var(--fs-12); font-weight: 650; color: var(--text-1); }
.cv-rt { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ============================================================
   토스트 · 모달
   ============================================================ */

.toasts {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 400;
  display: flex; flex-direction: column; gap: 7px; align-items: center; pointer-events: none;
}
.toast {
  padding: 8px 15px; border-radius: 20px;
  background: rgba(24, 24, 27, .92); color: #fff;
  font-size: var(--fs-12); font-weight: 500;
  box-shadow: var(--sh-2); animation: tin .18s ease;
}
@keyframes tin { from { opacity: 0; transform: translateY(6px) } }

#overlay:empty { display: none; }
.mask { position: fixed; inset: 0; z-index: 500; background: rgba(24, 24, 27, .44); display: grid; place-items: center; padding: 24px; }
.modal {
  width: min(760px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg-panel); border-radius: var(--r-14); box-shadow: var(--sh-3); overflow: hidden;
}
.modal-h { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border-1); }
.modal-h h3 { font-size: var(--fs-15); font-weight: 650; }
.modal-h .d { font-size: var(--fs-11); color: var(--text-3); min-width: 0; }
.modal-h .x {
  margin-left: auto; flex-shrink: 0; border: 0; background: transparent; color: var(--text-3);
  font: inherit; font-size: var(--fs-12); cursor: pointer; padding: 4px 6px; border-radius: var(--r-6);
}
.modal-h .x:hover { background: var(--bg-hover); color: var(--text-1); }
.modal-b { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.modal-f { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 7px; padding: 12px 18px; border-top: 1px solid var(--border-1); background: var(--bg-sidebar); }

/* ============================================================
   반응형 — 접는 순서는 genffice-docs(1240) · ksp(1400) 와 같은 장치다.
   ① 메뉴를 아이콘 레일로 ② 대화창을 지면 위로 쌓기 ③ 2열 접기
   ============================================================ */

@media (max-width: 1440px) {
  .app {
    grid-template-columns: 52px var(--split-w) minmax(210px, var(--work-w)) var(--split-w) minmax(0, 1fr);
    grid-template-rows: minmax(272px, 2fr) minmax(0, 3fr);
  }
  .menu { padding: 12px 8px; align-items: center; }
  .menu, .work { grid-row: 1 / -1; }
  .splitter[data-split="menu"], .splitter[data-split="work"] { grid-row: 1 / -1; }
  .splitter[data-split="stream"] { display: none; }
  .stream { grid-column: 5; grid-row: 1; }
  .canvas { grid-column: 5; grid-row: 2; border-top: 1px solid var(--border-2); }

  .brand { padding: 4px 0 14px; }
  .brand .txt, .nav-label, .menu-foot { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item .lbl, .nav-item .kb { display: none; }
  .splitter[data-split="menu"] { pointer-events: none; }
}

@media (max-width: 1000px) {
  .app {
    grid-template-columns: 52px var(--split-w) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .menu, .splitter[data-split="menu"] { grid-row: 1 / -1; }
  .work, .splitter[data-split="work"] { display: none; }
  .stream { grid-column: 3; grid-row: 1; }
  .canvas { grid-column: 3; grid-row: 2; border-top: 1px solid var(--border-2); }
}
