/* ============================================================
   앱 셸 — 사이드바 / 헤더 / 본문
   모바일 우선: 좁은 화면에서는 사이드바가 서랍(drawer)으로 열린다
   ============================================================ */

/* 레이아웃: 사이드바(전체 높이) + 오른쪽 본문(얇은 상단 바 + 내용) */
.app { height: 100dvh; display: flex; overflow: hidden; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: none;
  border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--ink-2);
  cursor: pointer; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- 사이드바 ---------- */
.side {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: width .18s ease;
}
.side-top {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  padding: 0 var(--s-3) 0 var(--s-5);
}
.side-brand .brand-mark { display: block; width: 32px; height: 32px; border-radius: 8px; }
.side-brand {
  font-size: var(--fs-sm); font-weight: 800; letter-spacing: .06em;
  color: var(--ink); white-space: nowrap; overflow: hidden;
}

/* 메뉴 — 이 부분만 스크롤된다 */
.side-nav { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-1) var(--s-3) var(--s-4); }

/* 하단 고정 — 관리·화면 밝기·내 계정 */
.side-bottom {
  flex: none;
  padding: var(--s-2) var(--s-3) var(--s-3);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.side-bottom .side-group { margin-bottom: 0; }
.side-bottom .side-group > .gh { padding-top: var(--s-2); }

.side-group { margin-bottom: var(--s-2); }
.side-group > .gh {
  padding: var(--s-4) var(--s-3) var(--s-1);
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
  color: var(--ink-3); white-space: nowrap; overflow: hidden;
}

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 34px;
  padding: 0 var(--s-3);
  border: 0; border-radius: var(--r);
  background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  text-align: left; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="page"] { background: var(--point-soft); color: var(--point); }
.nav-item .ico { width: 17px; height: 17px; flex: none; opacity: .75; display: inline-flex; }
.nav-item .ico svg { width: 17px; height: 17px; }
.nav-item[aria-current="page"] .ico { opacity: 1; }
.nav-item .lb { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 사이드바 배지 — 확인할 항목 수 */
.nav-badge {
  flex: none; min-width: 19px; height: 19px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px;
  border-radius: var(--r-full);
  /* 오류가 아니라 "확인해 볼 개수"라서 빨강 대신 차분한 회색 */
  background: var(--surface-3); color: var(--ink-2);
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* 일반 직원처럼 하단 메뉴가 없으면 하단 영역을 감춘다 */
.side-bottom:has(.side-bottom-menu:empty) { display: none; }

/* ---------- 접힌 사이드바 — 아이콘만 ---------- */
.app.side-collapsed .side { width: 64px; }
.app.side-collapsed .side-top { flex-direction: column; justify-content: center; gap: 2px; padding: var(--s-2) 0; height: auto; min-height: var(--header-h); }
.app.side-collapsed .side-nav,
.app.side-collapsed .side-bottom { padding-left: var(--s-2); padding-right: var(--s-2); }
.app.side-collapsed .side-group > .gh { font-size: 0; padding: var(--s-2) 0; }
.app.side-collapsed .side-group > .gh::before {
  content: ''; display: block; height: 1px; margin: 0 var(--s-2); background: var(--line);
}
.app.side-collapsed .nav-item { justify-content: center; padding: 0; min-height: 38px; }
.app.side-collapsed .nav-item .lb { display: none; }
.nav-item[aria-current="page"] .nav-badge { background: var(--surface); color: var(--point); }
.app.side-collapsed .nav-badge {
  position: absolute; top: 4px; right: 6px;
  box-shadow: 0 0 0 2px var(--surface);
  min-width: 16px; height: 16px; padding: 0 4px; font-size: 10px;
}

/* ---------- 본문 위 얇은 바 ---------- */
.topbar {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-5);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tb-spacer { flex: 1; }
.crumb { display: flex; align-items: center; gap: var(--s-1); min-width: 0; font-size: var(--fs-sm); white-space: nowrap; }
.crumb .c-p { color: var(--ink-3); }
.crumb .c-s { display: inline-flex; color: var(--ink-3); }
.crumb .c-n { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.ai-btn { gap: 6px; white-space: nowrap; }

/* 내 계정 — "○○님 ▾" */
.tb-user {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 34px; padding: 0 var(--s-2) 0 4px;
  border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.tb-user:hover, .tb-user[aria-expanded="true"] { background: var(--surface-2); border-color: var(--line); }
.tb-user .av {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--point-soft); color: var(--point);
  font-size: 12px; font-weight: 800;
}
.tb-user svg { color: var(--ink-3); transition: transform .15s; }
.tb-user[aria-expanded="true"] svg { transform: rotate(180deg); }
.ai-btn svg { color: var(--point); }

/* 통합 검색 */
.gs { position: relative; width: min(420px, 42vw); }
.gs-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); display: inline-flex; pointer-events: none; }
.gs-input {
  width: 100%; min-height: 34px !important;
  padding: 0 60px 0 34px !important;
  border-radius: var(--r) !important;
  background: var(--surface) !important;
  font-size: var(--fs-sm) !important;
}
.gs-input::-webkit-search-cancel-button { display: none; }
.gs-kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  padding: 1px 6px; border: 1px solid var(--line-2); border-radius: 5px;
  font: 600 11px var(--font-num, inherit); color: var(--ink-3); background: var(--surface-2);
  pointer-events: none;
}
.gs.open .gs-kbd { display: none; }
.gs-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 90;
  max-height: min(440px, 70vh); overflow-y: auto;
  padding: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-lg, 12px);
  box-shadow: var(--shadow-3);
}
.gs-gt { padding: var(--s-2) var(--s-3) var(--s-1); font-size: 11px; font-weight: 700; color: var(--ink-3); }
.gs-item {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 36px; padding: 0 var(--s-3);
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font: inherit; font-size: var(--fs-sm); text-align: left; cursor: pointer;
}
.gs-item.on { background: var(--point-soft); color: var(--point); }
.gs-item .gs-i { display: inline-flex; color: var(--ink-3); }
.gs-item.on .gs-i, .gs-item.ai .gs-i { color: var(--point); }
.gs-item .gs-l { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs-item .gs-s { flex: none; font-size: var(--fs-xs); color: var(--ink-3); }
.gs-empty { padding: var(--s-4) var(--s-3); font-size: var(--fs-sm); color: var(--ink-3); }

/* ---------- AI 비서 패널 (오른쪽) ---------- */
.ai-panel {
  display: none;
  width: 400px; flex: none;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.app.ai-open .ai-panel { display: flex; }
.ai-head {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: var(--s-2);
  padding: 0 var(--s-3) 0 var(--s-4);
  border-bottom: 1px solid var(--line);
}
.ai-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: var(--fs-sm); }
.ai-title svg { color: var(--point); }
.ai-list { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.ai-empty { padding: var(--s-4) var(--s-2); }
.ai-empty p { margin: var(--s-2) 0 var(--s-4); line-height: 1.6; }
.ai-examples { display: flex; flex-direction: column; gap: var(--s-2); align-items: flex-start; }
.ai-examples .btn { text-align: left; white-space: normal; height: auto; min-height: 32px; padding: 6px var(--s-3); }
.ai-msg { max-width: 92%; padding: var(--s-3) var(--s-4); border-radius: 14px; font-size: var(--fs-sm); line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere; }
.ai-msg.me { align-self: flex-end; background: var(--point); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.ai-msg.bot { align-self: flex-start; background: var(--surface-2); color: var(--ink); border-bottom-left-radius: 4px; }
.ai-msg.typing .ai-dots { color: var(--ink-3); font-size: var(--fs-xs); }
.ai-md p { margin: 0 0 var(--s-2); }
.ai-md p:last-child { margin-bottom: 0; }
.ai-md ul, .ai-md ol { margin: 0 0 var(--s-2); padding-left: 1.2em; }
.ai-md .table-wrap { margin: var(--s-2) 0; background: var(--surface); border-radius: var(--r-sm); }
.ai-md table.tbl { font-size: var(--fs-xs); min-width: 0 !important; }
.ai-foot { display: flex; gap: var(--s-2); align-items: flex-end; padding: var(--s-3); border-top: 1px solid var(--line); }
.ai-input { flex: 1; resize: none; min-height: 40px; max-height: 160px; font: inherit; font-size: var(--fs-sm); line-height: 1.5; padding: 9px var(--s-3); }
.ai-send { width: 40px; height: 40px; padding: 0; flex: none; }
.ai-note { padding: 0 var(--s-4) var(--s-3); font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.app.ai-open .ai-btn { background: var(--point-soft); color: var(--point); border-color: var(--point); }

/* ---------- 본문 ---------- */
.main { flex: 1; min-height: 0; overflow-y: auto; }
.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-5) var(--s-5) var(--s-16);
}
.page-h { margin-bottom: var(--s-5); }
.page-h h1 { font-size: var(--fs-lg); letter-spacing: -.015em; }
.page-h .desc { margin-top: var(--s-2); color: var(--ink-2); font-size: var(--fs-sm); }
.page-h .row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }

.stack   { display: flex; flex-direction: column; gap: var(--s-5); }
.stack-4 { display: flex; flex-direction: column; gap: var(--s-4); }
.row-4   { display: flex; gap: var(--s-4); flex-wrap: wrap; align-items: center; }
.grid    { display: grid; gap: var(--s-4); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }

/* ---------- 서랍 열기 버튼(좁은 화면 전용) ---------- */
.side-toggle { display: none; }
.scrim { display: none; }

/* ============================================================
   좁은 화면 — 사이드바를 서랍으로
   ============================================================ */
@media (max-width: 900px) {
  .side-toggle { display: inline-flex; }
  .side-collapse { display: none; }

  .side,
  .app.side-collapsed .side {
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 80;
    width: min(300px, 84vw);
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-3);
  }
  /* 서랍에서는 접힘 상태를 무시하고 글자까지 보인다 */
  .app.side-collapsed .side-top { flex-direction: row; justify-content: space-between; padding: 0 var(--s-3) 0 var(--s-5); height: var(--header-h); }
  .app.side-collapsed .nav-item { justify-content: flex-start; padding: 0 var(--s-3); }
  .app.side-collapsed .nav-item .lb { display: block; }
  .app.side-collapsed .side-group > .gh { font-size: 11px; padding: var(--s-4) var(--s-3) var(--s-1); }
  .app.side-collapsed .side-group > .gh::before { display: none; }
  .app.side-collapsed .nav-badge { position: static; }

  .app.side-open .side { transform: translateX(0); }

  .scrim {
    display: block; position: fixed; inset: 0;
    z-index: 70; background: rgba(20,18,17,.4);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .app.side-open .scrim { opacity: 1; pointer-events: auto; }

  .topbar { padding: 0 var(--s-3); gap: var(--s-2); }
  .crumb .c-p, .crumb .c-s { display: none; }
  .gs { width: auto; flex: 1; }
  .gs-kbd { display: none; }
  .ai-btn span { display: none; }
  .ai-panel { position: fixed; inset: 0; z-index: 90; width: auto; border-left: 0; }
  .ai-head { padding-top: env(safe-area-inset-top, 0px); }
  .tb-user .nm { display: none; }

  .page { padding: var(--s-5) var(--s-4) var(--s-16); }
  .page-h h1 { font-size: var(--fs-lg); }

  /* 표는 칸이 눌리지 않게 최소 폭을 두고 가로로 밀어 본다 */
  .table-wrap > table.tbl { min-width: 640px; }
}

/* ============================================================
   로그인 화면
   ============================================================ */
.auth-wrap {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--s-6);
  background: var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
  padding: var(--s-10) var(--s-8) var(--s-8);
}
.auth-card .brand {
  text-align: center; margin-bottom: var(--s-8);
  font-size: var(--fs-lg); font-weight: 800; letter-spacing: .06em;
}
.auth-err {
  margin-bottom: var(--s-5);
  padding: var(--s-4);
  border-radius: var(--r);
  background: var(--bad-bg); color: var(--bad);
  font-size: var(--fs-sm); font-weight: 600;
}
.auth-note {
  margin-top: var(--s-6); text-align: center;
  font-size: var(--fs-xs); color: var(--ink-3); line-height: 1.6;
}

/* 초기 비밀번호 1회 표시용 */
.pw-reveal {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4);
  margin: var(--s-4) 0;
  padding: var(--s-5);
  border: 1px dashed var(--point);
  border-radius: var(--r);
  background: var(--point-soft);
}
.pw-reveal code {
  font-family: var(--font-num); font-size: var(--fs-lg); font-weight: 700;
  color: var(--ink); letter-spacing: .04em; user-select: all;
}

/* 대시보드 — 왼쪽 차트, 오른쪽 확인 필요 (좁으면 위아래) */
.dash-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: var(--s-5); align-items: start; }
@media (max-width: 1100px) { .dash-main { grid-template-columns: 1fr; } .dash-main > :last-child { order: -1; } }
