/* ========== Reset & Variables ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active-bg: #1e3a5f;
  --sidebar-active-text: #ffffff;
  --sidebar-hover-bg: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ========== Layout ========== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid #1e293b;
}
.sidebar-logo h1 { font-size: 14px; font-weight: 700; color: #fff; line-height: 1.3; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px 12px;
  overflow-y: auto;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { width: 0; height: 0; }
.nav-section { margin-bottom: 7px; }
.nav-section:last-child { margin-bottom: 0; }
.nav-section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #7f8ea3;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-align: left;
}
.nav-section-toggle:hover { background: rgba(148,163,184,.10); color: #cbd5e1; }
.nav-section-items { display: block; margin-top: 1px; }
.nav-section.collapsed .nav-section-items { display: none; }
.nav-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: #64748b;
  transition: transform .15s ease;
}
.nav-section.collapsed .nav-chevron { transform: rotate(-90deg); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px 8px 12px;
  border-radius: 6px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 1px;
  transition: background .15s, color .15s;
}
.nav-item:hover  { background: var(--sidebar-hover-bg); color: #e2e8f0; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 500; }
.nav-icon { font-size: 15px; width: 19px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #1e293b;
  color: var(--sidebar-text);
  font-size: 12px;
}
.sidebar-footer .username { color: #e2e8f0; font-weight: 500; }
.logout-btn {
  background: none; border: none; color: var(--sidebar-text);
  cursor: pointer; font-size: 12px; padding: 4px 0; text-decoration: underline;
}
.logout-btn:hover { color: #e2e8f0; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header p  { color: var(--text-secondary); margin-top: 4px; font-size: 13px; }

/* ========== Cards ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: #f8fafc; font-weight: 600; color: var(--text-secondary); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: 6px; border: none;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-success      { background: var(--success); color: #fff; }
.btn-green        { background: #16a34a; color: #fff; }
.btn-green:hover:not(:disabled)        { background: #15803d; }
.btn-yellow       { background: #f59e0b; color: #fff; }
.btn-yellow:hover:not(:disabled)       { background: #d97706; }
.btn-yellow-light { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.btn-yellow-light:hover:not(:disabled) { background: #fde68a; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; }
.form-control {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.form-control { resize: vertical; min-height: 120px; font-family: inherit; }
select.form-control { cursor: pointer; }

/* ========== Modal ========== */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius);
  width: 90%; max-width: 580px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title  { font-size: 16px; font-weight: 600; }
.modal-close  { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-secondary); line-height: 1; }
.modal-body   { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ========== Badge ========== */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger  { background: #fee2e2; color: #dc2626; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-gray    { background: #f1f5f9; color: #64748b; }

/* ========== Toggle Switch ========== */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #cbd5e1; border-radius: 22px; cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ========== Stream Output ========== */
.stream-output {
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius); padding: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px;
  line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  min-height: 200px; max-height: 60vh; overflow-y: auto;
}
.stream-status { color: #94a3b8; font-style: italic; font-size: 12px; margin-bottom: 8px; }
.stream-cursor { display: inline-block; width: 8px; height: 14px; background: #e2e8f0; animation: blink 1s step-end infinite; vertical-align: text-bottom; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ========== Login Page ========== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 380px; box-shadow: var(--shadow); }
.login-logo  { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo p  { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.login-error { background: #fee2e2; color: #dc2626; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* ========== Alert Row ========== */
.alert-count-high { color: var(--danger); font-weight: 700; }
.alert-count-med  { color: var(--warning); font-weight: 600; }

/* ========== Markdown Body ========== */
.md-body {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 36px;
  line-height: 1.8; font-size: 14px; color: var(--text);
  max-width: 860px;
}
.md-body h1 { font-size: 22px; font-weight: 700; border-bottom: 2px solid var(--border); padding-bottom: 10px; margin: 0 0 20px; }
.md-body h2 { font-size: 17px; font-weight: 700; margin: 24px 0 10px; color: #1e3a5f; }
.md-body h3 { font-size: 15px; font-weight: 600; margin: 18px 0 8px; }
.md-body h4 { font-size: 14px; font-weight: 600; margin: 14px 0 6px; color: #475569; }
.md-body p  { margin: 0 0 12px; }
.md-body strong { font-weight: 600; }
.md-body em { font-style: italic; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.md-body ul, .md-body ol { padding-left: 22px; margin: 0 0 12px; }
.md-body li { margin-bottom: 4px; }
.md-body blockquote {
  border-left: 3px solid var(--primary);
  background: #f0f6ff; margin: 12px 0;
  padding: 10px 16px; border-radius: 0 6px 6px 0;
  color: #1e3a5f;
}
.md-body code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: 13px; }
.md-body pre { background: #1e293b; color: #e2e8f0; border-radius: 6px; padding: 14px 16px; overflow-x: auto; margin: 12px 0; }
.md-body pre code { background: none; padding: 0; color: inherit; }
.md-body .mermaid { margin: 16px 0; text-align: center; }
.md-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 7px 12px; }
.md-body th { background: #f8fafc; font-weight: 600; }
.md-body .status-line { margin: 4px 0 4px 16px; color: #475569; }
/* 弹窗内的 md-body 去掉外层 border/bg，让弹窗本身承担 */
.modal .md-body { border: none; background: none; padding: 0; max-width: none; }

/* ========== Misc ========== */
.empty-tip { text-align: center; color: var(--text-secondary); padding: 40px; font-size: 13px; }
.loading    { color: var(--text-secondary); font-size: 13px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.cron-expr { font-family: monospace; font-size: 12px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }

/* ========== Download Dropdown ========== */
.dl-wrap { position: relative; display: inline-block; }
.dl-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 300;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.12); min-width: 160px; overflow: hidden;
}
.dl-menu.open { display: block; }
.dl-item {
  display: block; width: 100%; padding: 9px 14px; font-size: 13px; cursor: pointer;
  color: var(--text); text-decoration: none; background: none; border: none; text-align: left;
  white-space: nowrap;
}
.dl-item:hover { background: #f1f5f9; }

@media (max-width: 720px) {
  body[data-role="member"] .app-layout { display:block; }
  body[data-role="member"] .sidebar {
    position:sticky;
    top:0;
    width:100%;
    height:auto;
    flex-direction:row;
    align-items:stretch;
  }
  body[data-role="member"] .sidebar-logo { display:none; }
  body[data-role="member"] .sidebar-nav {
    display:flex;
    min-width:0;
    padding:7px 8px;
    overflow-x:auto;
  }
  body[data-role="member"] .nav-section { margin:0; }
  body[data-role="member"] .nav-section-toggle { display:none; }
  body[data-role="member"] .nav-section-items { display:flex !important; gap:4px; margin:0; }
  body[data-role="member"] .nav-item { min-height:36px; margin:0; padding:7px 10px; white-space:nowrap; }
  body[data-role="member"] .sidebar-footer {
    display:flex;
    align-items:center;
    padding:7px 10px;
    border-top:0;
    border-left:1px solid #1e293b;
  }
  body[data-role="member"] .sidebar-footer .username { display:none; }
  body[data-role="member"] .main-content { margin-left:0; padding:14px 12px 28px; }
}
