/* CSS 변수 - 라이트 테마 (기본) */
:root,
:root[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #fff;
  --bg-tertiary: #fafafa;
  --bg-hover: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #333;
  --text-muted: #666;
  --text-dim: #999;
  --border-color: #ddd;
  --border-light: #eee;
  
  /* 상태 색상 */
  --success-bg: linear-gradient(135deg, #e8f5e8 0%, #fff 100%);
  --success-header: #d4edda;
  --success-border: #28a745;
  --success-text: #155724;
  
  --fail-bg: linear-gradient(135deg, #f5e8e8 0%, #fff 100%);
  --fail-header: #f8d7da;
  --fail-border: #dc3545;
  --fail-text: #721c24;
  
  /* 버튼 */
  --btn-active-bg: #555;
  --btn-active-border: #444;
  --btn-primary-bg: #555;
  --btn-primary-border: #444;
  --btn-primary-hover: #444;
  --btn-auto-active-bg: #1a1a1a;
  --btn-auto-active-border: #1a1a1a;
  --btn-auto-active-text: #fff;
  
  /* 사이드바 */
  --sidebar-bg: #fff;
  --sidebar-active-bg: #e8e8e8;
  --sidebar-active-border: #4a90d9;
  
  /* 액센트 색상 */
  --accent-color: #3b82f6;
  --accent-bg: #eff6ff;
  
  /* 기타 */
  --link-color: #4a90d9;
  --time-color: #4a90d9;
  --input-bg: #fff;
  
  /* 테마 토글 버튼 */
  --theme-toggle-bg: #1a1a1a;
  --theme-toggle-text: #fff;
  --theme-toggle-border: #1a1a1a;
}

/* 다크 테마 */
:root[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #252525;
  --bg-hover: #3a3a3a;
  --text-primary: #fff;
  --text-secondary: #e0e0e0;
  --text-muted: #b0b0b0;
  --text-dim: #909090;
  --border-color: #444;
  --border-light: #3a3a3a;
  
  /* 상태 색상 */
  --success-bg: linear-gradient(135deg, #1a3d1a 0%, #2d2d2d 100%);
  --success-header: #2a4d2a;
  --success-border: #4ade80;
  --success-text: #86efac;
  
  --fail-bg: linear-gradient(135deg, #3d1a1a 0%, #2d2d2d 100%);
  --fail-header: #4d2a2a;
  --fail-border: #f87171;
  --fail-text: #fca5a5;
  
  /* 컨테이너 카드 색상 */
  --container-normal-bg: #1a3d1a;
  --container-normal-border: #2d5a2d;
  --container-warning-bg: #3d3a1a;
  --container-warning-border: #5a5a2d;
  --container-critical-bg: #3d2a1a;
  --container-critical-border: #5a3d2d;
  --container-danger-bg: #3d1a1a;
  --container-danger-border: #5a2d2d;
  
  /* 로그 색상 */
  --log-warning-bg: #3d3a1a;
  --log-warning-text: #fbbf24;
  --log-danger-bg: #3d1a1a;
  --log-danger-text: #f87171;
  
  /* 컨테이너 상태 텍스트 */
  --container-status-running: #86efac;
  --container-status-exited: #fca5a5;
  --container-status-paused: #fcd34d;
  --container-status-restarting: #fdba74;
  
  /* 버튼 */
  --btn-active-bg: #555;
  --btn-active-border: #666;
  --btn-primary-bg: #555;
  --btn-primary-border: #666;
  --btn-primary-hover: #666;
  --btn-auto-active-bg: #fff;
  --btn-auto-active-border: #fff;
  --btn-auto-active-text: #1a1a1a;
  
  /* 사이드바 */
  --sidebar-bg: #2d2d2d;
  --sidebar-active-bg: #3a3a3a;
  --sidebar-active-border: #6b9dc4;
  
  /* 액센트 색상 */
  --accent-color: #60a5fa;
  --accent-bg: #1e3a5f;
  
  /* 기타 */
  --link-color: #6b9dc4;
  --time-color: #6b9dc4;
  --input-bg: #1a1a1a;
  
  /* 테마 토글 버튼 */
  --theme-toggle-bg: #fff;
  --theme-toggle-text: #1a1a1a;
  --theme-toggle-border: #fff;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--bg-primary);
  transition: background 0.3s, color 0.3s;
}

a {
  color: var(--link-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* 레이아웃 */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* 사이드바 */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: background 0.3s;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo .logo-icon {
  font-size: 24px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 14px;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--text-primary);
  border-left: 3px solid var(--sidebar-active-border);
}

.nav-item .icon {
  margin-right: 10px;
}

.nav-group-title {
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-sub-item {
  padding-left: 40px;
  font-size: 13px;
}

/* 메인 컨텐츠 */
.main-content {
  flex: 1;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  transition: background 0.3s;
}

.main-header {
  background: var(--bg-secondary);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.3s;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-info {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.current-time {
  font-family: 'Rajdhani', sans-serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.theme-toggle {
  padding: 6px 12px;
  border: 1px solid var(--theme-toggle-border);
  background: var(--theme-toggle-bg);
  color: var(--theme-toggle-text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s;
}

.theme-toggle:hover {
  opacity: 0.8;
}

.main-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* 컨트롤 영역 */
.control-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
  transition: background 0.3s;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.control-row + .control-row {
  margin-top: 12px;
}

.control-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 4px;
}

.interval-buttons {
  display: flex;
  gap: 4px;
}

.interval-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.interval-btn:hover {
  background: var(--bg-hover);
}

.interval-btn.active {
  background: var(--btn-active-bg);
  color: #fff;
  border-color: var(--btn-active-border);
}

.control-divider {
  width: 1px;
  height: 24px;
  background: var(--border-color);
}

.refresh-btn {
  padding: 6px 16px;
  border: 1px solid var(--btn-primary-border);
  background: var(--btn-primary-bg);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.refresh-btn:hover {
  background: var(--btn-primary-hover);
}

.auto-refresh-btn {
  padding: 6px 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.auto-refresh-btn:hover {
  background: var(--bg-hover);
}

.auto-refresh-btn.active {
  background: var(--btn-auto-active-bg);
  color: var(--btn-auto-active-text);
  border-color: var(--btn-auto-active-border);
}

.datetime-input {
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-secondary);
  border-radius: 4px;
  font-size: 13px;
  transition: background 0.3s, border 0.3s;
}

.datetime-input:focus {
  outline: none;
  border-color: var(--link-color);
}

.fetch-btn {
  padding: 6px 16px;
  border: 1px solid var(--btn-primary-border);
  background: var(--btn-primary-bg);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.fetch-btn:hover {
  background: var(--btn-primary-hover);
}

.last-fetch-info {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
}

.last-fetch-time {
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

/* 포틀릿 그리드 */
.portlet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  align-items: start;
}

/* 포틀릿 */
.portlet {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s;
}

.portlet.status-success {
  border-color: var(--success-border);
  background: var(--success-bg);
}

.portlet.status-success .portlet-header {
  background: var(--success-header);
  border-bottom-color: var(--success-border);
}

.portlet.status-fail {
  border-color: var(--fail-border);
  background: var(--fail-bg);
}

.portlet.status-fail .portlet-header {
  background: var(--fail-header);
  border-bottom-color: var(--fail-border);
}

.portlet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  transition: background 0.3s;
}

.portlet-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-primary);
}

.portlet-title .icon {
  font-size: 18px;
}

.portlet-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.portlet-body {
  padding: 16px;
}

.main-status {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.main-status .datetime {
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 13px;
}

.main-status .status-icon {
  font-size: 20px;
}

.main-status .target-name {
  color: var(--text-secondary);
  font-weight: 500;
}

.no-data {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

.divider {
  height: 1px;
  background: var(--border-color);
  margin: 16px 0;
}

.log-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}

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

.log-item .datetime {
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 12px;
}

.log-item .status-icon {
  font-size: 14px;
}

.log-item .target-name {
  color: var(--text-muted);
  font-size: 12px;
}

/* 연결 상태 */
.connection-status {
  position: fixed;
  bottom: 16px;
  right: 16px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 12px;
  color: var(--fail-text);
  transition: background 0.3s;
}

.connection-status.connected {
  color: var(--success-text);
  border-color: var(--success-border);
}

/* 목록 페이지 */
.list-page {
  min-height: 100vh;
  background: var(--bg-primary);
}

.page-header {
  background: var(--bg-secondary);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 20px;
}

.back-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.back-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.page-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  transition: background 0.3s;
}

.section h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.status-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-item .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.status-item .value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-item .value.active { color: var(--success-text); }
.status-item .value.inactive { color: var(--fail-text); }
.status-item .value.healthy { color: var(--success-text); }
.status-item .value.unhealthy { color: var(--fail-text); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.url-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
}

.error-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fail-text);
  font-size: 12px;
}

/* 반응형 */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  
  .sidebar-logo span,
  .nav-item span:not(.icon),
  .nav-group-title {
    display: none;
  }
  
  .nav-item {
    padding: 12px;
    text-align: center;
  }
  
  .nav-item .icon {
    margin-right: 0;
    font-size: 18px;
  }
  
  .portlet-grid {
    grid-template-columns: 1fr;
    align-items: start;
  }
}
