/* 由 views/layouts/main.handlebars 內嵌區塊搬出 (每頁共用，可被瀏覽器快取) */
/* 外框主題色 — 對齊 /css/ui.css 的設計 token，全站共用 */
:root {
    --sidebar-bg: #1b2433;
    --sidebar-text-color: #dbe3ee;
    --sidebar-hover-bg: #2a3547;
    --content-bg: var(--c-bg, #f4f6fa);
    --header-bg: #ffffff;
    --text-color: var(--c-text, #1f2733);
}

body {
    font-family: var(--font-sans, 'Helvetica Neue', Arial, sans-serif);
    margin: 0;
    background-color: var(--content-bg);
    color: var(--text-color);
}

.page-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100%;
}

.sidebar-header {
    padding: 14px 16px;
    text-align: center;
    background-color: #141c28;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 20px;
}

.sidebar-nav {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav li {
    margin: 0;
    padding: 0;
}

.sidebar-nav li a {
    display: block;
    padding: 7px 16px;
    margin: 1px 8px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.35;
    color: var(--sidebar-text-color);
    text-decoration: none;
    transition: background-color 0.16s ease, color 0.16s ease;
    border: none;
}

.sidebar-nav li a:hover {
    background-color: var(--sidebar-hover-bg);
    color: #fff;
}

/* Custom scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: #5a6578;
}

.main-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    margin-left: 250px; /* Offset for the sidebar */
}

/* Adjust for login page where there is no sidebar */
body:has(.auth-container) .main-content-wrapper {
    margin-left: 0;
}

.main-header {
    background: var(--header-bg);
    padding: 12px 24px;
    border-bottom: 1px solid var(--c-border, #e3e8ef);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.main-header h1 {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    color: var(--text-color);
}

.search-form {
    display: flex;
    gap: 8px;
}

.search-input {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    width: 250px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.search-btn {
    padding: 8px 20px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.search-btn:hover {
    background: #2980b9;
}

/* Header right section with search and user menu */
.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.user-menu-btn:hover {
    background: #e9ecef;
}

.user-name {
    font-weight: 500;
    color: #333;
}

.user-role {
    color: #666;
    font-size: 12px;
}

.dropdown-arrow {
    font-size: 10px;
    color: #666;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 5px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 160px;
    z-index: 1000;
    overflow: hidden;
}

.user-dropdown.show {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 10px 15px;
    color: #333;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: #f8f9fa;
}

.dropdown-item.logout-item {
    color: #e74c3c;
}

.dropdown-item.logout-item:hover {
    background: #fdf2f2;
}

.language-item {
    padding: 8px 15px;
}

.lang-select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    cursor: pointer;
}

.main-content {
    padding: 5px;
    flex-grow: 1;
}

.main-footer {
    text-align: center;
    padding: 15px;
    background: #fff;
    border-top: 1px solid #ddd;
    color: #777;
}

/* Fallback for browsers that don't support :has() */
@supports not selector(:has(a)) {
  body.login-page .main-content-wrapper {
    margin-left: 0;
  }
}

/* Notification badge */
.notification-badge {
    background: #e74c3c;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    min-width: 18px;
    text-align: center;
}

/* Notification popup */
.notification-popup {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 320px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 10000;
    animation: slideIn 0.3s ease;
    overflow: hidden;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification-fadeout {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.notification-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
}

.notification-popup-header strong {
    color: #2c3e50;
}

.notification-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.notification-close:hover {
    color: #2c3e50;
}

.notification-popup-body {
    padding: 15px;
    color: #555;
    font-size: 14px;
}

.notification-link {
    display: block;
    padding: 10px 15px;
    background: #f8f9fa;
    color: #3498db;
    text-decoration: none;
    font-size: 13px;
    border-top: 1px solid #eee;
}

.notification-link:hover {
    background: #e9ecef;
}

/* Notification types */
.notification-info {
    border-left: 4px solid #3498db;
}

.notification-success {
    border-left: 4px solid #27ae60;
}

.notification-warning {
    border-left: 4px solid #f39c12;
}

.notification-danger {
    border-left: 4px solid #e74c3c;
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.overlay-visible {
    display: block;
}

/* Sidebar close button (hidden on desktop) */
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* Hamburger menu button (hidden on desktop) */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-right: 15px;
}

.hamburger-btn span {
    width: 100%;
    height: 3px;
    background: #2c3e50;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        transition: left 0.3s ease;
        z-index: 1000;
    }

    .sidebar-open {
        left: 0;
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .hamburger-btn {
        display: flex;
    }

    .main-content-wrapper {
        margin-left: 0;
    }

    .main-header {
        padding: 12px 15px;
    }

    .main-header h1 {
        font-size: 18px;
        flex: 1;
    }

    .header-right {
        gap: 8px;
    }

    .search-form {
        display: none;
    }

    .user-menu-btn {
        padding: 5px 10px;
    }

    .user-role {
        display: none;
    }

    .main-content {
        padding: 5px;
    }

    /* Prevent scroll when sidebar is open */
    body.sidebar-active {
        overflow: hidden;
    }

    /* Mobile table styles */
    .data-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Mobile card layout for tables */
    .mobile-cards .data-table {
        display: block;
    }

    .mobile-cards .data-table thead {
        display: none;
    }

    .mobile-cards .data-table tr {
        display: block;
        margin-bottom: 15px;
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: 15px;
    }

    .mobile-cards .data-table td {
        display: block;
        text-align: left;
        padding: 8px 0;
        border-bottom: 1px solid #eee;
    }

    .mobile-cards .data-table td:last-child {
        border-bottom: none;
    }

    .mobile-cards .data-table td::before {
        content: attr(data-label);
        font-weight: bold;
        display: block;
        margin-bottom: 5px;
        color: #7f8c8d;
        font-size: 12px;
    }

    /* Mobile form styles */
    .form-row {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        width: 100%;
        margin-bottom: 10px;
    }

    /* Mobile pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination a {
        padding: 8px 12px;
        font-size: 14px;
    }

    /* Mobile notification popup */
    .notification-popup {
        width: calc(100% - 20px);
        left: 10px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    .main-header h1 {
        font-size: 16px;
    }

    .hamburger-btn {
        width: 25px;
        height: 20px;
    }

    .sidebar-nav li a {
        padding: 6px 14px;
        font-size: 13px;
    }

    .kpi-cards {
        grid-template-columns: 1fr;
    }

    .kpi-value {
        font-size: 24px;
    }

    .stats-card {
        padding: 15px;
    }

    .stats-value {
        font-size: 24px;
    }
}

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    padding: 20px;
    z-index: 10000;
    transition: bottom 0.3s ease;
}

.pwa-banner-visible {
    bottom: 20px;
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.pwa-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
}

.pwa-text strong {
    display: block;
    font-size: 16px;
    color: #333;
    margin-bottom: 4px;
}

.pwa-text p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.pwa-install-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.pwa-install-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.pwa-install-btn:hover {
    background: #2980b9;
}

.pwa-dismiss-btn {
    background: #f0f0f0;
    color: #666;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.pwa-dismiss-btn:hover {
    background: #e0e0e0;
}

/* Network Status Indicator */
#network-status {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 500;
    z-index: 10001;
    display: none;
}

#network-status.online {
    background: #27ae60;
    color: white;
}

#network-status.offline {
    display: block;
    background: #e74c3c;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* === Resizable Table Enhancements === */
.table-enhance-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    flex-wrap: wrap;
    font-size: 13px;
}

.table-enhance-toolbar label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    margin: 0;
    font-weight: normal;
}

.table-enhance-toolbar .hidden-cols-toggle {
    margin-left: auto;
    position: relative;
}

.table-enhance-toolbar .hidden-cols-btn {
    background: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 12px;
}

.table-enhance-toolbar .hidden-cols-btn:hover {
    background: #dee2e6;
}

.hidden-cols-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 160px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px 0;
}

.hidden-cols-dropdown.show {
    display: block;
}

.hidden-cols-dropdown label {
    display: flex;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.hidden-cols-dropdown label:hover {
    background: #f0f0f0;
}

.table-enhance-wrapper {
    width: 100%;
    overflow-x: auto;
}

.table-enhance-wrapper table {
    table-layout: fixed;
    max-width: 100%;
    width: 100%;
}

.table-enhance-wrapper table td,
.table-enhance-wrapper table th {
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
}


.table-enhance-wrapper table.no-wrap td,
.table-enhance-wrapper table.no-wrap th {
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: normal;
    overflow-wrap: normal;
    word-break: normal;
}

.table-enhance-wrapper th {
    position: relative;
    user-select: none;
}

.table-enhance-wrapper th .th-content {
    display: flex;
    align-items: center;
    gap: 4px;
}

.table-enhance-wrapper th .col-hide-btn {
    opacity: 0;
    cursor: pointer;
    color: #999;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.table-enhance-wrapper th:hover .col-hide-btn {
    opacity: 1;
}

.table-enhance-wrapper th .col-hide-btn:hover {
    color: #e74c3c;
}

.table-enhance-wrapper th .resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    background: transparent;
}

.table-enhance-wrapper th .resize-handle:hover,
.table-enhance-wrapper th .resize-handle.resizing {
    background: #3498db;
}

.col-hidden {
    display: none !important;
}
