/* ============================================================
   Layout — App Shell（Dev Bar / Sidebar / Topbar / Content）
   由 shared/js/layout.js 動態注入結構，這裡只定義樣式。

   分隔以背景色差為主：sidebar 白底、內容區灰底，不用分隔線。
   ============================================================ */

/* ── Dev Bar：Demo 用 Persona 切換列 ─────────────── */
.devbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--devbar-h);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: #fdf6e6;
  box-shadow: inset 0 -1px 0 rgba(162, 104, 10, .12);
  font-size: var(--fs-xs);
  color: #8a6d3b;
}
.devbar-tag {
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--warn);
}
/* Persona 切換器：DS 的 .dropdown，配合 devbar 的暖色底調整 */
.devbar .dropdown-trigger {
  min-height: 24px;
  padding: 0 var(--sp-2);
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(162, 104, 10, .22);
  font-size: var(--fs-xs);
  color: #6b5322;
}
.devbar .dropdown-trigger:hover { background: #fff; box-shadow: inset 0 0 0 1px rgba(162, 104, 10, .4); }
.devbar .dropdown-caret { border-color: #a2680a; }
.devbar .dropdown-value { font-weight: 400; }
/* 選單本身回到一般樣式：devbar 的暖色不該蔓延進選單 */
.devbar .dropdown-menu { min-width: 240px; color: var(--text); font-size: var(--fs-base); }
.devbar-actions { margin-left: auto; display: flex; gap: var(--sp-1); }
.devbar-actions a {
  color: #8a6d3b;
  padding: 3px var(--sp-2);
  border-radius: var(--r-sm);
}
.devbar-actions a:hover { background: rgba(162, 104, 10, .1); color: #6b5322; }

body.devbar-on { padding-top: var(--devbar-h); }
body.devbar-hidden .devbar { display: none; }
body.devbar-hidden { padding-top: 0; }

/* ── Shell ─────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* ── Sidebar：白底，靠背景色差與內容區分隔 ──────── */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--devbar-h);
  height: calc(100vh - var(--devbar-h));
}

.sidebar-brand { padding: var(--sp-5) var(--sp-4) var(--sp-4); }
.sidebar-brand-name { font-size: var(--fs-md); font-weight: 600; }
.sidebar-brand-portal {
  font-size: var(--fs-xs);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-top: 2px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 var(--sp-2) var(--sp-3); }

.nav-group-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-base);
}
.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}
/* 母子層級：子項用左側細線串起來，不再縮排一層 icon 的距離
   （側邊欄沒有 icon，靠線與字級區分層級就夠） */
.nav-sub { margin: 2px 0 var(--sp-2) var(--sp-4); border-left: 1px solid var(--border); }
.nav-sub-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.nav-sub-item:hover { color: var(--text); }
.nav-sub-item.is-active {
  border-left-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.nav-sub-item .nav-sub-meta { margin-left: auto; font-size: var(--fs-xs); color: var(--text-subtle); }

.nav-item-count {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  display: grid;
  place-items: center;
}

.sidebar-user {
  padding: var(--sp-3) var(--sp-4);
  margin: 0 var(--sp-2) var(--sp-2);
  border-radius: var(--r);
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.avatar {
  width: 30px; height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: var(--fs-sm);
  font-weight: 600;
}
/* 中間文字區塊需可收縮，否則長職稱會把「登出」擠成兩行 */
.sidebar-user-text { min-width: 0; flex: 1; }
.sidebar-user-name { font-size: var(--fs-base); font-weight: 500; }
.sidebar-user-role {
  font-size: var(--fs-xs); color: var(--text-subtle);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-logout {
  flex: 0 0 auto;
  color: var(--text-subtle); font-size: var(--fs-sm); white-space: nowrap;
}
.sidebar-logout:hover { color: var(--text); }

/* ── Main ──────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  background: var(--bg-base);
  position: sticky;
  top: var(--devbar-h);
  z-index: 20;
}
.topbar-title { font-size: var(--fs-lg); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }

/* 子帳戶切換器：使用 components.css 的 .dropdown，這裡只調寬度上限 */
.topbar .dropdown-trigger { max-width: 260px; }

/* 內容區 */
.content { padding: var(--sp-2) var(--sp-6) var(--sp-10); max-width: 1280px; width: 100%; }
.content-narrow { max-width: 760px; }

/* 麵包屑 */
.breadcrumb {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-subtle);
  margin-bottom: var(--sp-4);
}
.breadcrumb-sep { color: var(--border-strong); }

/* 區塊標題 */
.section { margin-bottom: var(--sp-8); }
.section-head {
  display: flex; align-items: baseline; gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.section-title { font-size: var(--fs-md); font-weight: 600; }
.section-desc { font-size: var(--fs-sm); color: var(--text-subtle); }
.section-actions { margin-left: auto; display: flex; gap: var(--sp-2); }

/* 常用 grid */
.grid   { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 置中頁（登入頁用，無 shell）*/
.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
}
