/**
 * Audit Dashboard - Custom Styles
 * 支援 PC 和手機的 RWD 設計
 */

/* ===== 基礎設定 ===== */
:root {
    --sidebar-width: 260px;
    --navbar-height: 56px;
    --primary-color: #0d6efd;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --secondary-color: #6c757d;
    --dark-color: #343a40;
    --light-bg: #f8f9fa;
    --card-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --card-hover-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Microsoft JhengHei', sans-serif;
    background-color: var(--light-bg);
    margin: 0;
    padding: 0;
    padding-top: var(--navbar-height);
}

/* ===== Navbar ===== */
.navbar {
    z-index: 1030;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--navbar-height));
    background-color: #fff;
    border-right: 1px solid #dee2e6;
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
    z-index: 1020;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    font-weight: 600;
    color: var(--dark-color);
}

.sidebar-menu {
    padding: 0.5rem 0;
}

.sidebar-menu-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: #495057;
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.sidebar-menu-item:hover {
    background-color: var(--light-bg);
    color: var(--primary-color);
}

.sidebar-menu-item.active {
    background-color: rgba(13, 110, 253, 0.1);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.sidebar-menu-item i {
    width: 24px;
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.sidebar-menu-item .badge {
    margin-left: auto;
}

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: calc(100vh - var(--navbar-height));
    transition: margin-left 0.3s ease-in-out;
}

.content-page {
    display: none;
}

.content-page.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-header {
    margin-bottom: 2rem;
}

.content-header h2 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

/* ===== Stats Cards ===== */
.stat-card {
    background: #fff;
    border-radius: 0.5rem;
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    transition: all 0.3s;
    height: 100%;
}

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

.stat-card.clickable {
    cursor: pointer;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #fff;
    margin-right: 1rem;
    flex-shrink: 0;
}

.stat-content {
    flex-grow: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #212529;
}

/* ===== Cards ===== */
.card {
    border: none;
    box-shadow: var(--card-shadow);
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.card:hover {
    box-shadow: var(--card-hover-shadow);
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* ===== Client Cards ===== */
.client-card {
    background: #fff;
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: var(--card-shadow);
    transition: all 0.3s;
    cursor: pointer;
    height: 100%;
}

.client-card:hover {
    box-shadow: var(--card-hover-shadow);
    transform: translateY(-3px);
}

.client-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.client-hostname {
    font-weight: 600;
    font-size: 1.1rem;
    color: #212529;
}

.client-status-badge {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.client-status-badge.online {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.client-status-badge.offline {
    background-color: var(--secondary-color);
}

.client-card-info {
    font-size: 0.875rem;
    color: #6c757d;
}

.client-card-info i {
    margin-right: 0.25rem;
}

/* ===== Anomaly Cards ===== */
.anomaly-card {
    background: #fff;
    border-left: 4px solid;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--card-shadow);
    transition: all 0.2s;
    cursor: pointer;
}

.anomaly-card:hover {
    box-shadow: var(--card-hover-shadow);
    transform: translateX(3px);
}

.anomaly-card.severity-critical {
    border-left-color: var(--danger-color);
}

.anomaly-card.severity-high {
    border-left-color: var(--warning-color);
}

.anomaly-card.severity-medium {
    border-left-color: var(--info-color);
}

.anomaly-card.severity-low {
    border-left-color: var(--secondary-color);
}

.anomaly-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.anomaly-card-title {
    font-weight: 600;
    font-size: 1rem;
    color: #212529;
    margin-bottom: 0.25rem;
}

.anomaly-card-meta {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

.anomaly-card-details {
    font-size: 0.875rem;
    color: #495057;
    background-color: var(--light-bg);
    padding: 0.5rem;
    border-radius: 0.25rem;
    margin-top: 0.5rem;
}

/* ===== Security Score Circle ===== */
.security-score-circle {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    position: relative;
    background: conic-gradient(
        var(--success-color) 0deg,
        var(--success-color) calc(3.6deg * var(--score, 0)),
        #e9ecef calc(3.6deg * var(--score, 0)),
        #e9ecef 360deg
    );
}

.security-score-circle::before {
    content: '';
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background-color: #fff;
}

.score-value {
    position: relative;
    z-index: 1;
    font-size: 2.5rem;
    font-weight: 700;
    color: #212529;
}

.score-label {
    position: relative;
    z-index: 1;
    font-size: 0.875rem;
    color: #6c757d;
}

.security-score-circle.score-excellent {
    background: conic-gradient(
        var(--success-color) 0deg,
        var(--success-color) calc(3.6deg * var(--score, 0)),
        #e9ecef calc(3.6deg * var(--score, 0)),
        #e9ecef 360deg
    );
}

.security-score-circle.score-good {
    background: conic-gradient(
        var(--info-color) 0deg,
        var(--info-color) calc(3.6deg * var(--score, 0)),
        #e9ecef calc(3.6deg * var(--score, 0)),
        #e9ecef 360deg
    );
}

.security-score-circle.score-warning {
    background: conic-gradient(
        var(--warning-color) 0deg,
        var(--warning-color) calc(3.6deg * var(--score, 0)),
        #e9ecef calc(3.6deg * var(--score, 0)),
        #e9ecef 360deg
    );
}

.security-score-circle.score-danger {
    background: conic-gradient(
        var(--danger-color) 0deg,
        var(--danger-color) calc(3.6deg * var(--score, 0)),
        #e9ecef calc(3.6deg * var(--score, 0)),
        #e9ecef 360deg
    );
}

/* ===== Security List Item ===== */
.security-list-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    transition: background-color 0.2s;
}

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

.security-list-item:hover {
    background-color: var(--light-bg);
}

.security-list-score {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-right: 1rem;
    flex-shrink: 0;
    font-weight: 700;
    font-size: 1.5rem;
}

.security-list-score.excellent {
    background-color: rgba(40, 167, 69, 0.1);
    color: var(--success-color);
}

.security-list-score.good {
    background-color: rgba(23, 162, 184, 0.1);
    color: var(--info-color);
}

.security-list-score.warning {
    background-color: rgba(255, 193, 7, 0.1);
    color: var(--warning-color);
}

.security-list-score.danger {
    background-color: rgba(220, 53, 69, 0.1);
    color: var(--danger-color);
}

.security-list-content {
    flex-grow: 1;
}

.security-list-hostname {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.security-list-issues {
    font-size: 0.875rem;
    color: #6c757d;
}

.security-issue-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    margin-right: 0.25rem;
    margin-bottom: 0.25rem;
}

/* ===== Organization Cards ===== */
.org-card {
    background: #fff;
    border-radius: 0.5rem;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    transition: all 0.3s;
    height: 100%;
}

.org-card:hover {
    box-shadow: var(--card-hover-shadow);
    transform: translateY(-3px);
}

.org-card-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 1rem;
}

.org-card-name {
    font-weight: 600;
    font-size: 1.25rem;
    color: #212529;
    margin-bottom: 0.5rem;
}

.org-card-description {
    font-size: 0.875rem;
    color: #6c757d;
    margin-bottom: 1rem;
}

.org-card-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.org-stat {
    text-align: center;
    padding: 0.5rem;
    background-color: var(--light-bg);
    border-radius: 0.25rem;
}

.org-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #212529;
}

.org-stat-label {
    font-size: 0.75rem;
    color: #6c757d;
}

/* ===== Badges ===== */
.badge {
    font-weight: 500;
}

/* ===== Tables ===== */
.table-responsive {
    border-radius: 0.5rem;
    overflow: hidden;
}

.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    background-color: var(--light-bg);
}

/* ===== Pagination ===== */
.pagination {
    margin-bottom: 0;
}

.pagination .page-link {
    color: var(--primary-color);
}

.pagination .page-item.active .page-link {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* ===== Modals ===== */
.modal-header {
    border-bottom: 1px solid #dee2e6;
}

.modal-footer {
    border-top: 1px solid #dee2e6;
}

/* ===== Toast Container ===== */
.toast-container {
    z-index: 1050;
}

/* ===== Loading Spinner ===== */
.spinner-border {
    width: 2rem;
    height: 2rem;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ===== Responsive Design ===== */

/* Tablet (≤992px) */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stat-card {
        margin-bottom: 1rem;
    }
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }
    
    .content-header h2 {
        font-size: 1.5rem;
    }
    
    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    .card-header h5 {
        font-size: 1rem;
    }
    
    /* 手機版：統計卡片 2 欄 */
    .col-6 {
        width: 50%;
    }
    
    /* 手機版：隱藏部分資訊 */
    .d-none.d-md-block {
        display: none !important;
    }
    
    .d-none.d-md-inline {
        display: none !important;
    }
    
    /* 手機版：表格改為卡片 */
    .table-responsive {
        overflow-x: auto;
    }
    
    /* 手機版：Modal 全螢幕 */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
    }
    
    .modal-xl {
        max-width: 100%;
    }
    
    /* 手機版：篩選器垂直排列 */
    .card-body .row.g-2 > div {
        margin-bottom: 0.5rem;
    }
}

/* Small Mobile (≤576px) */
@media (max-width: 576px) {
    .navbar-brand {
        font-size: 1rem;
    }
    
    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
        margin-right: 0.5rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    .security-score-circle {
        width: 120px;
        height: 120px;
    }
    
    .security-score-circle::before {
        width: 90px;
        height: 90px;
    }
    
    .score-value {
        font-size: 2rem;
    }
    
    .anomaly-card {
        padding: 0.75rem;
    }
    
    .client-card {
        padding: 0.75rem;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .sidebar,
    .btn,
    .pagination {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #dee2e6;
        page-break-inside: avoid;
    }
}

/* Utility Classes */
.cursor-pointer {
    cursor: pointer;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.text-muted-light {
    color: #adb5bd !important;
}

.border-start-danger {
    border-left: 4px solid var(--danger-color) !important;
}

.border-start-warning {
    border-left: 4px solid var(--warning-color) !important;
}

.border-start-success {
    border-left: 4px solid var(--success-color) !important;
}

.border-start-info {
    border-left: 4px solid var(--info-color) !important;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ===== 異常管理頁面 Badge 樣式修正 ===== */

/* 嚴重性 Badge - 確保文字可見 */
.anomaly-card .badge.severity-critical,
.badge.severity-critical {
    background-color: #dc3545 !important;
    color: #ffffff !important;
    font-weight: 600;
}

.anomaly-card .badge.severity-high,
.badge.severity-high {
    background-color: #fd7e14 !important;
    color: #ffffff !important;
    font-weight: 600;
}

.anomaly-card .badge.severity-medium,
.badge.severity-medium {
    background-color: #ffc107 !important;
    color: #000000 !important;
    font-weight: 600;
}

.anomaly-card .badge.severity-low,
.badge.severity-low {
    background-color: #6c757d !important;
    color: #ffffff !important;
    font-weight: 600;
}

/* 狀態 Badge - 確保文字可見 */
.anomaly-card .badge.status-new,
.badge.status-new {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}

.anomaly-card .badge.status-acknowledged,
.badge.status-acknowledged {
    background-color: #0dcaf0 !important;
    color: #000000 !important;
}

.anomaly-card .badge.status-in_progress,
.badge.status-in_progress {
    background-color: #198754 !important;
    color: #ffffff !important;
}

.anomaly-card .badge.status-resolved,
.badge.status-resolved {
    background-color: #28a745 !important;
    color: #ffffff !important;
}

.anomaly-card .badge.status-false_positive,
.badge.status-false_positive {
    background-color: #6c757d !important;
    color: #ffffff !important;
}

/* Badge 基本樣式增強 */
.anomaly-card .badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.anomaly-card .badge {
    padding: 0.35em 0.65em;
    font-size: 0.875rem;
    border-radius: 0.25rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

/* Card Header 樣式優化 */
.anomaly-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.anomaly-card .detect-time {
    font-size: 0.875rem;
    color: #6c757d;
    white-space: nowrap;
}
/* 組織卡片樣式 */
.org-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  padding: 1rem 0;
}

.org-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
}

.org-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.org-card-disabled {
  opacity: 0.7;
  background: #f5f5f5;
}

.org-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem;
  border-bottom: 1px solid #f0f0f0;
}

.org-card-title {
  flex: 1;
}

.org-card-title h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
  color: #333;
}

.org-card-id {
  font-size: 0.875rem;
  color: #999;
  font-weight: normal;
}

.org-card-body {
  padding: 1.25rem;
}

.org-card-field {
  margin-bottom: 1rem;
}

.org-card-field label {
  display: block;
  font-size: 0.875rem;
  color: #666;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.org-card-field span,
.org-card-description {
  display: block;
  color: #333;
  line-height: 1.5;
}

.org-card-stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #f0f0f0;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: #999;
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: #333;
}

.org-card-meta {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #f0f0f0;
}

.org-card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid #f0f0f0;
  background: #fafafa;
}

.org-card-actions button {
  flex: 1;
}

/* 手機響應式 */
@media (max-width: 768px) {
  .org-cards-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .org-card-header {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .org-card-stats {
    gap: 1rem;
  }
  
  .stat-value {
    font-size: 1.25rem;
  }
  
  .org-card-actions {
    flex-direction: column;
  }
  
  .org-card-actions button {
    width: 100%;
  }
}

/* 空狀態 */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-state h3 {
  margin: 0 0 0.5rem 0;
  color: #666;
}

.empty-state p {
  color: #999;
  margin-bottom: 1.5rem;
}

/* 組織資訊顯示樣式 */
.org-info-section {
  margin: 1rem 0;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 6px;
}

.org-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #495057;
  margin: 0 0 0.75rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.org-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.org-info-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.org-info-item.full-width {
  grid-column: 1 / -1;
}

.org-info-item label {
  font-size: 0.75rem;
  color: #6c757d;
  font-weight: 500;
}

.org-info-item span,
.org-info-item a {
  font-size: 0.875rem;
  color: #212529;
}

.org-info-item a {
  text-decoration: none;
  color: #0d6efd;
}

.org-info-item a:hover {
  text-decoration: underline;
}

.org-notes {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #495057;
  white-space: pre-wrap;
}

/* 手機響應式 - 組織資訊 */
@media (max-width: 768px) {
  .org-info-grid {
    grid-template-columns: 1fr;
  }
  
  .org-info-section {
    padding: 0.75rem;
  }
}
