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

:root {
  --bg:        #0d0f14;
  --bg2:       #141720;
  --bg3:       #1c2030;
  --border:    #2a2f42;
  --accent:    #7c5cfc;
  --accent2:   #5b9cf6;
  --text:      #e2e8f0;
  --text-muted:#8892a4;
  --green:     #34d399;
  --yellow:    #fbbf24;
  --red:       #f87171;
  --radius:    8px;
  --sidebar-w: 240px;
  --header-h:  52px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent2); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Login page ───────────────────────────────────────────────────────────── */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  font-size: 40px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.login-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 14px;
  transition: border-color 0.15s;
}
.login-card input[type="password"]:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo { font-size: 22px; }
.header-title { font-size: 16px; font-weight: 700; }
.header-spacer { flex: 1; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 13px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--text-muted); }

/* Main layout */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-section {
  padding: 12px 0 4px;
}

.sidebar-label {
  padding: 4px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.bot-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
}
.bot-item:hover { background: var(--bg3); }
.bot-item.active {
  background: var(--bg3);
  border-left-color: var(--accent);
}

.bot-emoji { font-size: 16px; }
.bot-name { font-weight: 500; flex: 1; }
.bot-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  color: #fff;
}
.badge-up    { background: var(--green); }
.badge-down  { background: var(--red); }
.badge-check { background: var(--text-muted); }
.badge-remote { background: var(--border); color: var(--text-muted); }

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

.sidebar-scroll { overflow-y: auto; flex: 1; }

/* Health panel in sidebar */
.health-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s;
  width: 100%;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  color: var(--text);
  font-size: 14px;
}
.health-btn:hover, .health-btn.active { background: var(--bg3); border-left-color: var(--accent2); }

/* Content panel */
.content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* File list panel */
.file-list-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.panel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  flex-shrink: 0;
}

.panel-title { font-size: 15px; font-weight: 600; flex: 1; }

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.1s;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13px;
}
.file-item:hover { background: var(--bg3); }
.file-item.active { background: var(--bg3); color: var(--accent2); }
.file-icon { color: var(--text-muted); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state .es-icon { font-size: 32px; margin-bottom: 8px; }

/* File viewer/editor */
.file-view-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.file-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.file-path {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 5px 14px;
  font-size: 13px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-save {
  background: var(--green);
  border: none;
  color: #0d0f14;
  font-weight: 700;
  border-radius: var(--radius);
  padding: 5px 18px;
  font-size: 13px;
  transition: opacity 0.15s;
}
.btn-save:hover { opacity: 0.85; }
.btn-save:disabled { opacity: 0.4; cursor: default; }

.file-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Markdown render */
.md-render h1, .md-render h2, .md-render h3,
.md-render h4, .md-render h5, .md-render h6 {
  color: var(--text);
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
}
.md-render h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.md-render h2 { font-size: 1.35em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
.md-render h3 { font-size: 1.1em; }
.md-render p  { margin: 0.7em 0; }
.md-render ul, .md-render ol { margin: 0.6em 0 0.6em 1.5em; }
.md-render li { margin: 0.3em 0; }
.md-render code {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.9em;
  color: #f59e0b;
}
.md-render pre {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  overflow-x: auto;
  margin: 1em 0;
}
.md-render pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
}
.md-render blockquote {
  border-left: 3px solid var(--accent);
  margin: 0.8em 0;
  padding: 6px 16px;
  color: var(--text-muted);
  background: var(--bg3);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.md-render table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.md-render th, .md-render td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.md-render th { background: var(--bg3); font-weight: 600; }
.md-render tr:nth-child(even) { background: var(--bg2); }
.md-render a { color: var(--accent2); }
.md-render hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md-render strong { color: var(--text); }

/* Editor textarea */
.md-editor {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13.5px;
  line-height: 1.7;
  resize: none;
  padding: 24px 32px;
}

/* Health panel */
.health-panel {
  padding: 24px 32px;
  overflow-y: auto;
}

.health-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.health-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.health-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.health-card-name { font-weight: 600; font-size: 15px; }
.health-card-status { margin-left: auto; }

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.dot-up     { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-down   { background: var(--red); }
.dot-check  { background: var(--border); }
.dot-remote { background: var(--border); }

.status-label-up     { color: var(--green); font-weight: 600; }
.status-label-down   { color: var(--red); font-weight: 600; }
.status-label-check  { color: var(--text-muted); }

.health-card-url { font-family: monospace; font-size: 12px; color: var(--text-muted); }
.health-card-ms  { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.health-refresh-btn {
  margin-bottom: 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 7px 18px;
  font-size: 13px;
  transition: background 0.15s;
}
.health-refresh-btn:hover { background: var(--border); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notification */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 999;
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--green); color: #0d0f14; }
#toast.error   { background: var(--red);   color: #fff; }

/* ── Split view ────────────────────────────────────────────────────────────── */
.split-view {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.split-files {
  width: 260px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.split-viewer {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 4px 8px;
}

@media (max-width: 768px) {
  .mobile-menu-btn { display: block; }
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-h);
    bottom: 0;
    z-index: 200;
    transition: left 0.25s;
    width: 220px;
  }
  .sidebar.open { left: 0; }
  .split-files { width: 200px; }
  .file-content, .md-editor { padding: 16px; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
