:root {
  --sb-sidebar-width: 260px;
  --sb-sidebar-collapsed: 64px;
  --sb-header-height: 64px;
  --sb-blue: #2563eb;
  --sb-green: #16a34a;
  --sb-bg: #f3f6fb;
  --sb-card: #ffffff;
  --sb-text: #0f172a;
  --sb-muted: #64748b;
  --sb-line: #e2e8f0;
}

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

html,
body.sb-body {
  margin: 0;
  min-height: 100%;
  background: var(--sb-bg);
  color: var(--sb-text);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}

.sb-shell {
  min-height: 100vh;
  position: relative;
}

/* Sidebar — fixed 260px */
.sb-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sb-sidebar-width);
  background: var(--sb-card);
  border-right: 1px solid var(--sb-line);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 40;
  transition: width .2s ease, transform .2s ease;
  box-shadow: 2px 0 12px rgba(15, 23, 42, .04);
}

.sb-sidebar__brand {
  position: sticky;
  top: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 12px;
  background: var(--sb-card);
  border-bottom: 1px solid var(--sb-line);
  z-index: 2;
}

.sb-sidebar__toggle {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex: 0 0 auto;
}

.sb-sidebar__title {
  font-weight: 800;
  color: var(--sb-blue);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-sidebar__subtitle,
.sb-sidebar__meta {
  font-size: 12px;
  color: var(--sb-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-sidebar__meta {
  font-size: 11px;
  margin-top: 2px;
}

.sb-sidebar__nav {
  padding: 10px;
}

.sb-sidebar__section {
  margin: 14px 6px 6px;
  padding-bottom: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--sb-blue);
  border-bottom: 1px solid #bfdbfe;
}

.sb-sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin: 4px 0;
  border-radius: 10px;
  color: var(--sb-text);
  text-decoration: none;
  transition: .15s;
}

.sb-sidebar__link:hover {
  background: #eff6ff;
  color: var(--sb-blue);
}

.sb-sidebar__link.is-active {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
}

.sb-sidebar__icon {
  width: 24px;
  text-align: center;
  flex: 0 0 24px;
}

.sb-sidebar__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 15px;
}

/* Main column */
.sb-main {
  margin-left: var(--sb-sidebar-width);
  min-height: 100vh;
  width: calc(100% - var(--sb-sidebar-width));
  transition: margin-left .2s ease, width .2s ease;
  display: flex;
  flex-direction: column;
}

.sb-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--sb-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--sb-line);
}

.sb-header__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sb-header__menu {
  display: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: #e2e8f0;
  cursor: pointer;
}

.sb-header__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.sb-header__crumb {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--sb-muted);
}

.sb-header__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sb-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #eff6ff;
  color: #1d4ed8;
}

.sb-chip--role {
  background: #ecfdf5;
  color: #047857;
}

.sb-header__user {
  font-size: 14px;
  font-weight: 600;
}

.sb-header__logout {
  padding: 6px 12px;
  border-radius: 8px;
  background: #fee2e2;
  color: #b91c1c;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}

.sb-lang {
  margin: 0;
  display: inline-flex;
  align-items: center;
}

.sb-lang__select {
  border: 2px solid #475569;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
  background: #fff;
  color: var(--sb-text);
  max-width: 160px;
  min-height: 40px;
}

.sb-lang__select:focus,
.sb-lang__select:focus-visible {
  border: 2px solid #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
  outline: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sb-content {
  padding: 20px;
  flex: 1;
}

.sb-card {
  background: var(--sb-card);
  border: 1px solid var(--sb-line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}

/* Collapsed desktop */
body.sb-sidebar-collapsed .sb-sidebar {
  width: var(--sb-sidebar-collapsed);
}

body.sb-sidebar-collapsed .sb-main {
  margin-left: var(--sb-sidebar-collapsed);
  width: calc(100% - var(--sb-sidebar-collapsed));
}

body.sb-sidebar-collapsed .sb-sidebar__brand-text,
body.sb-sidebar-collapsed .sb-sidebar__label,
body.sb-sidebar-collapsed .sb-sidebar__section {
  display: none;
}

body.sb-sidebar-collapsed .sb-sidebar__link {
  justify-content: center;
}

body.sb-sidebar-collapsed .sb-sidebar__brand {
  justify-content: center;
}

/* Tablet */
@media (max-width: 1024px) and (min-width: 769px) {
  :root {
    --sb-sidebar-width: 240px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .sb-sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 28px rgba(15, 23, 42, .18);
  }

  .sb-main {
    margin-left: 0;
    width: 100%;
  }

  .sb-header__menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.sb-sidebar-collapsed .sb-sidebar {
    transform: translateX(-100%);
    width: var(--sb-sidebar-width);
  }

  body.sb-sidebar-collapsed .sb-main {
    margin-left: 0;
    width: 100%;
  }

  body.sb-sidebar-collapsed .sb-sidebar__brand-text,
  body.sb-sidebar-collapsed .sb-sidebar__label,
  body.sb-sidebar-collapsed .sb-sidebar__section {
    display: block;
  }

  body:not(.sb-sidebar-collapsed) .sb-main::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 35;
  }

  .sb-content {
    padding: 14px;
  }
}
