:root {
    --orange: #e67e22;
    --orange-dark: #d35400;
    --sidebar-width: 232px;
    --sidebar-collapsed-width: 68px;
    --footer-height: 48px;
    --sidebar-bg: #1e1e2d;
    --body-bg: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #dee2e6;
}

[data-theme="dark"] {
    --sidebar-bg: #12121a;
    --body-bg: #0f0f14;
    --card-bg: #1a1a24;
    --text-color: #e4e4e7;
    --border-color: #2e2e3a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--body-bg);
    color: var(--text-color);
    min-height: 100vh;
    padding-bottom: var(--footer-height);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
}

.text-orange { color: var(--orange) !important; }
.bg-orange { background-color: var(--orange) !important; }
.btn-orange {
    background: var(--orange);
    border-color: var(--orange);
    color: #fff;
}
.btn-orange:hover {
    background: var(--orange-dark);
    border-color: var(--orange-dark);
    color: #fff;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: #fff;
    z-index: 1040;
    transition: width 0.25s ease, transform 0.25s ease;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}
.sidebar-header {
    min-height: 56px;
    height: auto;
    padding: 0.55rem 0.55rem 0.55rem 0.65rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    gap: 0.25rem;
}
.sidebar.collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: auto;
    min-height: 56px;
    padding: 0.45rem 0 0.35rem;
    gap: 0.15rem;
}
.sidebar-brand {
    font-weight: 700;
    color: var(--orange);
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    max-width: calc(100% - 2.1rem);
    flex: 1;
}
/* 頭像＋姓名列：文字單行省略，不換行 */
.sidebar-brand.sidebar-user {
    white-space: nowrap;
    align-items: center;
}
.sidebar.collapsed .sidebar-brand.sidebar-user {
    white-space: nowrap;
    align-items: center;
}
.sidebar-brand-photo {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.35);
    box-shadow: 0 0 0 1px rgba(230, 126, 34, 0.35);
    background: rgba(255,255,255,0.08);
}
.sidebar-brand-fallback {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(230, 126, 34, 0.22);
    color: var(--orange);
    flex-shrink: 0;
    border: 2px solid rgba(230, 126, 34, 0.35);
    font-size: 1.1rem;
    font-weight: 700;
}
/* 縮起側欄：細頭像 */
.sidebar.collapsed .sidebar-brand-photo,
.sidebar.collapsed .sidebar-brand-fallback {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
}
.sidebar-brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 側欄：同事頭像／姓名／角色 */
.sidebar-user-text{
    display:flex;
    flex-direction:column;
    min-width:0;
    flex:1 1 auto;
    overflow:hidden;
    line-height:1.2;
    gap:0.05rem;
}
.sidebar-user-name{
    font-weight:600;
    color:var(--orange);
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    font-size:0.8rem;
    line-height:1.25;
    max-width:100%;
}
.sidebar-user-full,
.sidebar-user-center{
    font-size:0.68rem;
    font-weight:500;
    color:rgba(255,255,255,0.7);
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    line-height:1.25;
    max-width:100%;
}
.sidebar-user-role{
    font-size:0.62rem;
    font-weight:500;
    color:rgba(255,255,255,0.5);
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    line-height:1.2;
    max-width:100%;
}
.sidebar-user-fallback{
    font-size:0.85rem;
    font-weight:700;
}
.sidebar.collapsed .sidebar-user-text{display:none}

.sidebar.collapsed .sidebar-brand {
    max-width: 100%;
    justify-content: center;
    margin: 0;
}
.sidebar.collapsed .sidebar-brand-fallback {
    margin: 0;
}
.sidebar.collapsed .sidebar-toggle-btn {
    display: inline-flex !important;
    margin: 0;
    padding: 0.2rem;
}
.sidebar-nav {
    padding: 0.55rem 0.5rem 0.75rem;
    flex: 1;
}
.sidebar.collapsed .sidebar-nav {
    padding: 0.75rem 0.5rem;
}
.sidebar-nav .nav-link {
    color: rgba(255,255,255,0.75);
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.sidebar.collapsed .sidebar-nav .nav-link {
    justify-content: center;
    padding: 0.65rem;
}
.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    background: rgba(230, 126, 34, 0.18);
    color: var(--orange);
}
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-section-label {
    display: none;
}
.sidebar .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}
.sidebar-toggle-btn {
    color: #fff;
    background: transparent;
    border: none;
    padding: 0.35rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.sidebar-toggle-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1035;
}
.sidebar-overlay.show { display: block; }

/* Main */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    display: flex;
    flex-direction: column;
}
.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* Topbar */
.topbar {
    height: 56px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar .btn-icon {
    border: none;
    background: transparent;
    color: var(--text-color);
    padding: 0.4rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.topbar .btn-icon:hover {
    background: rgba(0,0,0,0.06);
}
[data-theme="dark"] .topbar .btn-icon:hover {
    background: rgba(255,255,255,0.08);
}

/* Content */
.page-content {
    flex: 1;
    padding: 1.25rem;
}

/* Footer：完整文字，只縮放字級 */
.site-footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--footer-height);
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: left 0.25s ease;
    padding: 0 0.75rem;
    overflow: hidden;
}
body.sidebar-is-collapsed .site-footer {
    left: var(--sidebar-collapsed-width);
}

.site-footer-inner {
    display: block;
    width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: clamp(0.62rem, 1.55vw, 0.85rem);
    line-height: 1.3;
    color: #6c757d;
}

.site-footer-inner a {
    color: inherit;
    text-decoration: none;
}
.site-footer-inner a:hover {
    color: var(--orange);
}

/* Mobile layout */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .main-content,
    .main-content.sidebar-collapsed {
        margin-left: 0;
    }
    .site-footer {
        left: 0 !important;
    }
    .sidebar.collapsed .nav-label,
    .sidebar.collapsed .sidebar-brand-text,
    .sidebar.collapsed .nav-section-label {
        display: inline;
    }
    .sidebar.collapsed .sidebar-nav .nav-link {
        justify-content: flex-start;
        padding: 0.65rem 0.85rem;
    }
    .sidebar.collapsed .sidebar-header {
        justify-content: space-between;
        padding: 0 1rem;
    }
}


/* ========== 全頁載入轉圈（LOGO） ========== */
.ec-page-loader {
    position: fixed;
    inset: 0;
    z-index: 200000;
    background: rgba(244, 246, 249, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}
.ec-page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.ec-page-loader-inner {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.ec-page-loader-inner img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    position: relative;
    z-index: 1;
}
.ec-page-loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px solid transparent;
    border-top-color: #e74c3c;
    border-right-color: #e74c3c;
    animation: ec-page-spin 0.9s linear infinite;
    box-sizing: border-box;
}
@keyframes ec-page-spin {
    to { transform: rotate(360deg); }
}

/* 共用：頁面工具列固定在 topbar 下方 */
.ec-sticky-toolbar {
  position: sticky;
  top: 56px;
  z-index: 90;
  background: var(--card-bg, #fff);
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
[data-theme="dark"] .ec-sticky-toolbar {
  background: var(--card-bg);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.ec-sticky-toolbar.card,
.ec-sticky-toolbar.card .card-body {
  background: inherit;
}


/* ========== 全站頁面工具列（與時間表總表同一套） ========== */
.page-content { overflow: visible; }

.tt-toolbar,
.tt-toolbar-sticky {
  position: sticky;
  top: 56px;
  z-index: 90;
  background: var(--card-bg, #fff);
  border-radius: 12px !important;
  box-shadow: 0 2px 12px rgba(0,0,0,.1) !important;
}
[data-theme="dark"] .tt-toolbar,
[data-theme="dark"] .tt-toolbar-sticky {
  background: var(--card-bg);
  box-shadow: 0 2px 10px rgba(0,0,0,.35) !important;
}
.tt-toolbar.card,
.tt-toolbar-sticky.card {
  border: 0 !important;
  overflow: hidden;
}
.tt-toolbar > .card-body,
.tt-toolbar-sticky > .card-body {
  background: inherit;
}

/* 相容舊 class 名稱 → 同一套 sticky／圓角 */
.ec-sticky-toolbar,
.duty-nav.ec-sticky-toolbar,
.my-week-bar.ec-sticky-toolbar {
  position: sticky;
  top: 56px;
  z-index: 90;
  background: var(--card-bg, #fff);
  border-radius: 12px !important;
  box-shadow: 0 2px 12px rgba(0,0,0,.1) !important;
}

/* 手機：左右留白最小；工具列 100% 螢幕寬、無圓角 */
@media (max-width: 991.98px) {
  .page-content {
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0.5rem;
    padding-bottom: 0.75rem;
  }
  .page-content > .container-fluid,
  .page-content > .container {
    padding-left: 0.4rem !important;
    padding-right: 0.4rem !important;
  }
  .tt-toolbar,
  .tt-toolbar-sticky,
  .ec-sticky-toolbar,
  .duty-nav.ec-sticky-toolbar,
  .my-week-bar.ec-sticky-toolbar {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    border-radius: 0 !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.06) !important;
  }
  .tt-toolbar > .card-body,
  .tt-toolbar-sticky > .card-body,
  .ec-sticky-toolbar > .card-body {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  .topbar {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}


/* 側欄：姓名下中心名（細字；盡量完整顯示，過長可換行最多兩行） */
.sidebar-user-center {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 0.72rem;
  line-height: 1.25;
  max-width: 100%;
  overflow: hidden;
  word-break: break-word;
  white-space: normal;
  opacity: 0.9;
  color: rgba(255, 255, 255, 0.75) !important;
}
.sidebar.collapsed .sidebar-user-center,
.sidebar.collapsed .sidebar-user-role {
  display: none !important;
}
