/* 앱 셸(사이드바+상단바+콘텐츠) — 로그인 화면을 뺀 모든 화면이 공유한다. */

.app-shell { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- 사이드바 */
.sidebar {
  width: var(--sidebar-width); flex: 0 0 auto; background: var(--sidebar-bg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem; padding: 1.3rem 1.2rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand img { width: 32px; height: 32px; border-radius: 8px; flex: 0 0 auto; }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-text .name { color: var(--sidebar-text-active); font-weight: 700; font-size: .86rem; line-height: 1.25; }
.sidebar-brand-text .sub { color: var(--sidebar-text); font-size: .68rem; letter-spacing: .03em; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: .9rem .7rem; }
.nav-section-label {
  color: var(--sidebar-text); opacity: .6; font-size: .66rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; padding: .8rem .6rem .35rem;
}
.nav-item {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-size: .86rem; font-weight: 500; margin-bottom: .15rem; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.nav-item .icon { width: 18px; text-align: center; flex: 0 0 auto; font-size: 1rem; }
.nav-item:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-active); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item.disabled {
  opacity: .45; cursor: default; pointer-events: none;
}
.nav-item .soon-tag {
  margin-left: auto; font-size: .6rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  background: var(--sidebar-bg-hover); color: var(--sidebar-text); padding: .1rem .4rem; border-radius: 4px;
}

/* 하위 메뉴가 있는 항목("NullSsay Overwatch" 등) — 펼치면 그 밑에 실제 페이지 링크가 나온다. */
.nav-group-toggle {
  width: 100%; background: none; border: none; font-family: inherit; text-align: left;
}
.nav-group-toggle .chevron { margin-left: auto; font-size: .65rem; transition: transform .15s ease; flex: 0 0 auto; }
.nav-group-toggle.expanded .chevron { transform: rotate(180deg); }
.nav-subitems { overflow: hidden; max-height: 0; transition: max-height .18s ease; }
.nav-subitems.expanded { max-height: 320px; }
.nav-subitem { padding-left: 1.8rem; font-size: .8rem; }
.nav-subitem .icon { display: none; }
.nav-subitem .soon-tag { font-size: .58rem; }

.sidebar-backdrop { display: none; }

/* ---------------------------------------------------------------- 메인 영역 */
.main-area { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height); flex: 0 0 auto; background: var(--bg-panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem; padding: 0 1.4rem; position: sticky; top: 0; z-index: 30;
}
.topbar-menu-btn {
  display: none; background: none; border: none; font-size: 1.2rem; color: var(--text-secondary); cursor: pointer;
  padding: .3rem;
}
.topbar-search {
  flex: 1 1 auto; max-width: 360px; display: flex; align-items: center; gap: .5rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: .5rem .9rem; color: var(--text-tertiary); font-size: .84rem;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-secondary);
  font-size: 1rem; position: relative;
}
.icon-btn .dot {
  position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger);
}
.user-chip { display: flex; align-items: center; gap: .6rem; padding: .3rem .5rem .3rem .3rem; border-radius: var(--radius-md); }
.user-chip img { width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto; background: var(--bg); }
.user-chip-text { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip-text .name { font-size: .82rem; font-weight: 600; }
.user-chip-text .logout-link { font-size: .7rem; color: var(--text-tertiary); cursor: pointer; }
.user-chip-text .logout-link:hover { color: var(--danger); }

.content { flex: 1 1 auto; padding: 1.6rem 2rem; max-width: 1800px; width: 100%; margin: 0 auto; }

.page-title { font-size: 1.3rem; font-weight: 700; margin: 0 0 .6rem; }
.page-subtitle { color: var(--text-tertiary); font-size: .86rem; margin: 0 0 1.4rem; }

/* ---------------------------------------------------------------- 카드/그리드 */
.card {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.4rem; }
.stat-card { padding: 1.2rem; display: flex; flex-direction: column; gap: .7rem; }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon-chip {
  width: 42px; height: 42px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; flex: 0 0 auto;
}
.stat-trend { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; }
.stat-trend.up { color: var(--success); background: var(--success-fill); }
.stat-trend.down { color: var(--danger); background: var(--danger-fill); }
.stat-value { font-size: 1.55rem; font-weight: 700; }
.stat-label { font-size: .8rem; color: var(--text-tertiary); }
.stat-placeholder-tag {
  font-size: .64rem; color: var(--text-tertiary); background: var(--bg); border: 1px dashed var(--border-strong);
  border-radius: 999px; padding: .12rem .5rem; align-self: flex-start;
}

.widget-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
.widget-card { padding: 1.3rem; }
.widget-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.widget-head h3 { font-size: .94rem; margin: 0; }
.widget-head .placeholder-tag {
  font-size: .68rem; color: var(--text-tertiary); background: var(--bg); border: 1px dashed var(--border-strong);
  border-radius: 999px; padding: .15rem .55rem;
}

.empty-note { color: var(--text-tertiary); font-size: .82rem; padding: 1.5rem 0; text-align: center; }

/* ---------------------------------------------------------------- 페이지 헤더 행 + 버튼 */
.page-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 600;
  font-size: .84rem; padding: .6rem 1.1rem; cursor: pointer; white-space: nowrap; transition: background .12s ease;
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost {
  background: none; border: 1px solid var(--border-strong); color: var(--text-secondary); border-radius: var(--radius-sm);
  font-size: .82rem; padding: .55rem 1rem; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }
.btn-danger-text { color: var(--danger); background: none; border: none; cursor: pointer; font-size: .8rem; font-weight: 600; }
.btn-danger {
  background: var(--danger); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 600;
  font-size: .84rem; padding: .6rem 1.1rem; cursor: pointer; white-space: nowrap; transition: background .12s ease;
}
.btn-danger:hover { background: #c93d41; }
.btn-danger:disabled, .btn-primary:disabled { opacity: .6; cursor: not-allowed; }

/* ---------------------------------------------------------------- 테이블 */
.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.data-table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-tertiary);
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
}
.data-table td { padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.token-pill { font-family: ui-monospace, monospace; background: var(--bg); border-radius: 6px; padding: .15rem .5rem; font-size: .78rem; }
/* 보조 얼라이언스를 메인 바로 밑에 살짝 들여써서 트리 구조처럼 보이게 한다. */
.data-table tr.sub-row td { background: var(--bg-panel-hover); }
.entity-cell-indent { padding-left: 1.6rem; position: relative; }
.entity-cell-indent::before { content: "↳"; margin-right: .4rem; color: var(--text-tertiary); }
.entity-cell-indent-2 { padding-left: 3.2rem; }
.entity-kind-tag {
  font-size: .62rem; font-weight: 700; color: var(--text-tertiary); border: 1px solid var(--border-strong);
  border-radius: 4px; padding: .05rem .4rem; margin-left: .5rem; white-space: nowrap;
}

/* 팝업 안 탭(얼라이언스 추가 / 코퍼레이션 추가) */
.tab-row { display: flex; gap: .3rem; margin-bottom: 1.2rem; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; padding: .55rem .85rem; font-size: .84rem; font-weight: 600;
  color: var(--text-tertiary); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
  font-family: inherit;
}
.tab-btn.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text-secondary); }
.status-pill { font-size: .7rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; }
.status-pill.on { color: var(--success); background: var(--success-fill); }
.status-pill.off { color: var(--text-tertiary); background: var(--bg); }
.status-pill.danger { color: var(--danger); background: var(--danger-fill); }

/* ---------------------------------------------------------------- 사용률 바 (모니터링 페이지) */
.usage-bar { height: 8px; border-radius: 5px; background: var(--bg); overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 5px; background: var(--accent); transition: width .4s ease; }
.usage-bar-fill.warn { background: var(--gold); }
.usage-bar-fill.danger { background: var(--danger); }

/* ---------------------------------------------------------------- 모달 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 30, .45); display: flex; align-items: center;
  justify-content: center; z-index: 100; padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 420px; background: var(--bg-panel); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); padding: 1.6rem; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 1.05rem; margin: 0 0 1.2rem; }
.form-field { margin-bottom: 1rem; }
.form-label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .4rem; }
.form-input, .form-textarea, select.form-input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: .6rem .75rem;
  font-size: .86rem; font-family: inherit; background: var(--bg-panel); color: var(--text);
}
.form-input:focus, .form-textarea:focus { outline: none; border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 64px; }
.form-error { color: var(--danger); font-size: .78rem; margin-top: .5rem; min-height: 1.1em; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; }
.form-checkbox-row { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .86rem; }
.form-checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.selected-chip {
  display: inline-flex; align-items: center; gap: .5rem; margin-top: .6rem; padding: .4rem .7rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .84rem;
}
.selected-chip img { width: 20px; height: 20px; border-radius: 4px; }
.selected-chip .clear-btn { margin-left: .3rem; cursor: pointer; color: var(--text-tertiary); font-weight: 700; }
.type-pill { font-size: .7rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.type-pill.main { color: var(--accent-strong); background: var(--accent-fill); }
.type-pill.secondary { color: var(--gold); background: var(--gold-fill); }

/* ---------------------------------------------------------------- 검색 콤보박스(동맹 얼라이언스 관리 등) */
.search-combo { position: relative; max-width: 420px; }
.search-combo-input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: .65rem .85rem;
  font-size: .88rem; font-family: inherit; background: var(--bg-panel); color: var(--text);
}
.search-combo-input:focus { outline: none; border-color: var(--accent); }
.search-combo-results {
  position: absolute; top: calc(100% + .4rem); left: 0; right: 0; background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  max-height: 320px; overflow-y: auto; z-index: 50;
}
.search-combo-results[hidden] { display: none; }
.search-combo-item {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .85rem; cursor: pointer; font-size: .86rem;
}
.search-combo-item:hover { background: var(--bg-panel-hover); }
.search-combo-item img { width: 26px; height: 26px; border-radius: 5px; flex: 0 0 auto; background: var(--bg); }
.search-combo-item .ticker { color: var(--text-tertiary); font-size: .76rem; margin-left: auto; flex: 0 0 auto; }
.search-combo-empty { padding: .8rem; color: var(--text-tertiary); font-size: .82rem; text-align: center; }
.entity-cell { display: flex; align-items: center; gap: .6rem; }
.entity-cell img { width: 24px; height: 24px; border-radius: 5px; flex: 0 0 auto; background: var(--bg); }
.entity-cell .ticker-tag {
  font-size: .7rem; color: var(--text-tertiary); background: var(--bg); border-radius: 4px; padding: .05rem .35rem;
  margin-left: .4rem;
}

/* 접근 거부 팝업 — 인텔 페이지와 같은 패턴 */
.denied-toast {
  position: fixed; top: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 200;
  background: var(--danger-fill); color: var(--danger); border: 1px solid var(--danger);
  padding: .7rem 1.1rem; border-radius: var(--radius-sm); font-size: .84rem; font-weight: 600;
  box-shadow: var(--shadow-md);
}

/* ---------------------------------------------------------------- 반응형 */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .widget-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(10, 12, 30, .45); z-index: 39;
  }
  .sidebar-backdrop.open { display: block; }
  .topbar-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-search { display: none; }
  .content { padding: 1.1rem; }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .user-chip-text { display: none; }
}
