/* ============================================
   GOF Dashboard - Modern UI Stylesheet
   ============================================ */

/* ========== 1. CSS Variables ========== */
:root {
    /* Colors - Primary Palette */
    --primary: #667eea;
    --primary-dark: #5568d3;
    --primary-light: #7c8ef0;
    --accent: #764ba2;
    --accent-dark: #5f3d82;

    /* Colors - Semantic */
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;

    /* Colors - Neutrals */
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Background & Surface */
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --surface: #ffffff;
    --surface-hover: #f8fafc;

    /* Text */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders */
    --border-color: #e2e8f0;
    --border-color-dark: #cbd5e1;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Spacing */
    --space-xs: 0.25rem;
    /* 4px */
    --space-sm: 0.5rem;
    /* 8px */
    --space-md: 1rem;
    /* 16px */
    --space-lg: 1.5rem;
    /* 24px */
    --space-xl: 2rem;
    /* 32px */
    --space-2xl: 3rem;
    /* 48px */
    --space-3xl: 4rem;
    /* 64px */

    /* Border Radius */
    --radius-sm: 0.375rem;
    /* 6px */
    --radius-md: 0.5rem;
    /* 8px */
    --radius-lg: 1rem;
    /* 16px */
    --radius-xl: 1.5rem;
    /* 24px */
    --radius-full: 9999px;

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Layout */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --header-height: 64px;
    --container-max-width: 1400px;

    /* Z-index */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* ========== 2. Base Styles & Reset ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: var(--font-weight-semibold);
    line-height: 1.2;
    color: var(--text-primary);
}

h1 {
    font-size: 2.25rem;
}

h2 {
    font-size: 1.875rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

h5 {
    font-size: 1.125rem;
}

h6 {
    font-size: 1rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

/* ========== 3. Dashboard Layout ========== */
.dashboard-container {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-primary);
}

/* ========== 4. Sidebar ========== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: linear-gradient(180deg, var(--primary) 0%, var(--accent) 100%);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-base);
    z-index: var(--z-fixed);
    box-shadow: var(--shadow-lg);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header */
.sidebar-header {
    padding: var(--space-lg) var(--space-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    color: var(--text-inverse);
    font-size: 1.25rem;
    font-weight: var(--font-weight-bold);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-brand-text {
    display: none;
}

/* 收縮時隱藏整個品牌區域 */
.sidebar.collapsed .sidebar-brand {
    display: none;
}

/* 收縮時 header 只顯示 toggle，居中 */
.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: var(--space-md);
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-inverse);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-md);
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
}

.nav-section-title {
    font-size: 0.75rem;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.6);
    padding: var(--space-md) var(--space-sm);
    margin-top: var(--space-lg);
}

.sidebar.collapsed .nav-section-title {
    display: none;
}

.nav-item {
    margin-bottom: var(--space-xs);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: rgba(255, 255, 255, 0.9);
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.nav-link i {
    font-size: 1.375rem;
    width: 26px;
    min-width: 26px;
    flex-shrink: 0;
    text-align: center;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-inverse);
    transform: translateX(4px);
}

.sidebar.collapsed .nav-link:hover {
    transform: translateX(0);
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-inverse);
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0.875rem 0.5rem;
}

.sidebar.collapsed .nav-link-text {
    display: none;
}

/* ========== Sidebar Footer 部分 ========== */
.sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.15);
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-weight: var(--font-weight-semibold);
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
}

.sidebar.collapsed .sidebar-user-info {
    display: none;
}

/* 收縮時用戶頭像居中 - 修復用戶 icon 歪斜問題 */
.sidebar.collapsed .sidebar-user {
    justify-content: center;
    padding: var(--space-md) var(--space-sm);
}

/* ========== 5. Main Content Area ========== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-base);
}

.sidebar.collapsed~.sidebar-overlay {
    display: none;
}

.sidebar.collapsed~.main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Content Header */
.content-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-md) var(--space-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    box-shadow: var(--shadow-sm);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* 只對非第一個項目添加斜線 - 修復 breadcrumb 多餘斜線問題 */
.breadcrumb-item:not(:first-child)::before {
    content: '/';
    color: var(--text-tertiary);
    margin-right: var(--space-sm);
}

.breadcrumb-item a {
    color: var(--text-secondary);
}

.breadcrumb-item a:hover {
    color: var(--primary);
}

.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* Content Body */
.content-body {
    flex: 1;
    padding: var(--space-xl);
    max-width: var(--container-max-width);
    width: 100%;
    margin: 0 auto;
}

/* Content Footer */
.content-footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: var(--space-lg) var(--space-xl);
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ========== 6. Cards ========== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all var(--transition-base);
}

.card-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1.125rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
}

.card-body {
    padding: var(--space-lg);
}

.card-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* Stat Cards */
.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-base);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    transform: scaleX(0);
    transition: transform var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

.stat-card:hover::before {
    transform: scaleX(1);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: var(--space-md);
}

.stat-value {
    font-size: 2rem;
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: var(--space-sm);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.stat-trend {
    font-size: 0.75rem;
    margin-top: var(--space-sm);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.stat-trend.up {
    color: var(--success);
}

.stat-trend.down {
    color: var(--danger);
}

/* ========== 7. Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-size: 0.875rem;
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Button Variants */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline-primary {
    border-color: var(--primary);
    color: var(--primary);
    background: transparent;
}

.btn-outline-primary:hover {
    background: var(--primary);
    color: var(--text-inverse);
}

.btn-success {
    background: var(--success);
    color: var(--text-inverse);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse);
}

.btn-outline-danger {
    border-color: var(--danger);
    color: var(--danger);
    background: transparent;
}

.btn-outline-danger:hover {
    background: var(--danger);
    color: var(--text-inverse);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

/* ========== 8. Tables ========== */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table th {
    padding: var(--space-md);
    text-align: left;
    font-weight: var(--font-weight-semibold);
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border-bottom: 2px solid var(--border-color);
}

.table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.table tbody tr:nth-child(even) {
    background-color: var(--gray-50);
}

.table tbody tr:hover {
    background-color: var(--surface-hover);
}

.table td {
    padding: var(--space-md);
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* ========== 9. Forms ========== */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-control::placeholder {
    color: var(--text-tertiary);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
}

/* ========== 10. Badges ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25em 0.75em;
    font-size: 0.75rem;
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* ========== 11. Alerts ========== */
.alerts-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-tooltip);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    max-width: 400px;
}

.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.alert-success {
    background: var(--success-light);
    border-left: 4px solid var(--success);
    color: var(--success);
}

.alert-danger {
    background: var(--danger-light);
    border-left: 4px solid var(--danger);
    color: var(--danger);
}

/* ========== 12. Utilities ========== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-secondary);
}

.text-primary {
    color: var(--primary);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.d-none {
    display: none;
}

.d-block {
    display: block;
}

.d-flex {
    display: flex;
}

.d-grid {
    display: grid;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.mb-xl {
    margin-bottom: var(--space-xl);
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.fade-in {
    animation: elevateIn 0.35s ease-out;
    animation-fill-mode: both;
}

@keyframes elevateIn {
    from {
        opacity: 0.92;
        transform: translateY(8px) scale(0.995);
        filter: blur(0.5px);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

/* ========== 13. Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
    }

    .content-body {
        padding: var(--space-md);
    }

    .content-header {
        padding: var(--space-md);
    }
}

/* Mobile Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

@media (max-width: 768px) {
    .sidebar-overlay.active {
        display: block;
    }
}

/* ========== Bootstrap Compatibility Fixes ========== */
/* Ensure Bootstrap grid system works correctly */
.container-main {
    max-width: var(--container-max-width);
    width: 100%;
    padding-right: var(--space-xl);
    padding-left: var(--space-xl);
    margin-right: auto;
    margin-left: auto;
}

/* CRITICAL: Do NOT override Bootstrap's .row class - let Bootstrap handle it */
/* Remove our custom .row definition to avoid conflicts */

/* Ensure form controls inherit our custom styles but work with Bootstrap */
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Fix button styles to work with both our custom styles and Bootstrap */
.btn {
    font-family: var(--font-sans);
}

/* Fix Bootstrap card padding if needed */
.card-body {
    padding: var(--space-lg);
}

/* Ensure proper margins for form elements in Bootstrap grid */
.form-group,
.mb-3,
.mb-2 {
    margin-bottom: 1rem;
}

/* Fix potential text color conflicts */
.text-secondary {
    color: var(--text-secondary) !important;
}

/* Ensure alerts work correctly */
.alert i {
    flex-shrink: 0;
}

/* Fix modal positioning if used */
.modal {
    z-index: var(--z-modal);
}

.modal-backdrop {
    z-index: var(--z-modal-backdrop);
}