/* ELIS Server Manager — Custom styles */
:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #242837;
  --border: #2e3347;
  --text: #e4e6f0;
  --text2: #8b8fa8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-header .subtitle { font-size: 11px; color: var(--text2); margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 12px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text2);
  font-size: 14px;
  transition: all .15s;
  margin-bottom: 2px;
}
.sidebar-nav a:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.sidebar-nav a .icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
}
.sidebar-footer a { color: var(--text2); }
.sidebar-footer a:hover { color: var(--red); }
.sidebar-footer .logout-link { margin-top: 8px; }

/* Mobile logout link — hidden on desktop, shown in mobile bottom bar */
.mobile-logout { display: none !important; }

.main-content { margin-left: 240px; flex: 1; padding: 24px 32px; min-height: 100vh; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 24px; font-weight: 600; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card-label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* Tables */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: 16px; font-weight: 600; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover { background: rgba(99, 102, 241, 0.04); }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: rgba(34, 197, 94, .15); color: var(--green); }
.badge-red { background: rgba(239, 68, 68, .15); color: var(--red); }
.badge-yellow { background: rgba(234, 179, 8, .15); color: var(--yellow); }
.badge-blue { background: rgba(99, 102, 241, .15); color: var(--accent2); }
.badge-gray { background: rgba(139, 143, 168, .15); color: var(--text2); }
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); background: var(--bg2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn-group { display: flex; gap: 4px; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 480px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.form-control:focus { border-color: var(--accent); }
select.form-control { appearance: auto; }

/* Progress bars */
.progress { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; border-radius: 3px; transition: width .3s; }
.progress-bar-blue { background: var(--accent); }
.progress-bar-green { background: var(--green); }
.progress-bar-yellow { background: var(--yellow); }
.progress-bar-red { background: var(--red); }

/* Logs viewer */
.logs-viewer {
  background: #000;
  color: #aaa;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.6;
  padding: 16px;
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  animation: slideIn .3s ease-out;
  min-width: 250px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* Ping status */
.ping-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.ping-dot.online { background: var(--green); box-shadow: 0 0 8px rgba(34, 197, 94, .5); }
.ping-dot.offline { background: var(--red); }
.ping-dot.checking { background: var(--yellow); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* Section info boxes */
.info-box {
  background: rgba(99, 102, 241, .08);
  border: 1px solid rgba(99, 102, 241, .2);
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 20px;
}
.info-box strong { color: var(--text); }

/* Utility classes replacing inline styles */
.mt-12 { margin-top: 12px; }
.mt-8 { margin-top: 8px; }
.d-flex-center { display: flex; align-items: center; gap: 8px; }
.w-full-center { width: 100%; justify-content: center; margin-top: 8px; }
.modal-wide { width: 800px; max-width: 95vw; }

/* Login */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
}
.login-box h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-box .subtitle { color: var(--text2); font-size: 13px; margin-bottom: 28px; }
.login-box .error { background: rgba(239,68,68,.1); color: var(--red); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }

/* ═══════════════════════════════════════════════════
   MOBILE-FIRST RESPONSIVE
   ═══════════════════════════════════════════════════ */

/* Mobile: bottom navigation bar */
@media (max-width: 768px) {
  .layout { flex-direction: column; }

  /* Sidebar → bottom tab bar */
  .sidebar {
    position: fixed;
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 200;
    background: var(--bg2);
  }
  .sidebar-header { display: none; }
  .sidebar-footer { display: none; }
  .sidebar-nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    width: 100%;
    padding: 0;
    gap: 0;
  }
  .sidebar-nav a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    border-radius: 0;
    margin: 0;
    font-size: 10px;
    min-height: 60px;
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar-nav a .icon { font-size: 20px; width: auto; }
  .sidebar-nav a span:not(.icon) { font-size: 10px; display: block; }
  .sidebar-nav a.active { background: rgba(99, 102, 241, .15); color: #fff; }
  .mobile-logout { display: flex !important; }

  /* Main content */
  .main-content {
    margin-left: 0;
    padding: 16px 12px 76px 12px; /* 76px bottom for tab bar */
    min-height: calc(100vh - 60px);
  }

  /* Page header */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
  }
  .page-header h2 { font-size: 20px; }
  .page-header .btn-group { width: 100%; }
  .page-header .btn-group .btn { flex: 1; justify-content: center; font-size: 12px; padding: 10px 8px; }

  /* Cards grid */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .card { padding: 14px; border-radius: 10px; }
  .card-value { font-size: 22px; }
  .card-label { font-size: 11px; }

  /* Tables → horizontal scroll */
  .table-wrap { border-radius: 10px; margin-bottom: 16px; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 540px; }
  th { padding: 8px 10px; font-size: 10px; white-space: nowrap; }
  td { padding: 10px; font-size: 12px; }
  .table-header { padding: 12px 14px; }
  .table-header h3 { font-size: 14px; }

  /* Buttons — bigger touch targets */
  .btn { padding: 10px 14px; font-size: 13px; min-height: 40px; }
  .btn-sm { padding: 8px 12px; font-size: 12px; min-height: 36px; }
  .btn-group { flex-wrap: wrap; }

  /* Modals — full width on mobile */
  .modal {
    width: 100%;
    max-width: 100vw;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
    margin-top: auto;
  }
  .modal-overlay.active { align-items: flex-end; }
  .modal-header { padding: 16px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-footer .btn { flex: 1; justify-content: center; }

  /* Forms */
  .form-control { padding: 12px; font-size: 16px; /* prevent iOS zoom */ }

  /* Info box */
  .info-box { padding: 12px 14px; font-size: 12px; border-radius: 8px; }

  /* Logs */
  .logs-viewer { font-size: 10px; padding: 12px; max-height: 300px; }

  /* Toast */
  .toast-container { top: auto; bottom: 72px; right: 12px; left: 12px; }
  .toast { min-width: auto; font-size: 13px; text-align: center; }

  /* Login */
  .login-box { width: 100%; max-width: 380px; padding: 28px 20px; margin: 0 12px; border-radius: 14px; }

  /* Server cards — ping area */
  .server-ping { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
  .server-actions { margin-top: 10px; }

  /* Badge */
  .badge { font-size: 10px; padding: 2px 8px; }

  /* Progress bar */
  .progress { height: 5px; }
}

/* Small phones (≤ 380px) */
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .card-value { font-size: 20px; }
  .main-content { padding: 12px 8px 76px 8px; }
  .page-header h2 { font-size: 18px; }
  .sidebar-nav a { font-size: 9px; }
  .sidebar-nav a .icon { font-size: 18px; }
}

/* Tablet (769–1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 72px; }
  .sidebar-header h1 { font-size: 14px; text-align: center; }
  .sidebar-header .subtitle { display: none; }
  .sidebar-nav a span:not(.icon) { display: none; }
  .sidebar-nav a { justify-content: center; padding: 12px 8px; }
  .sidebar-footer { font-size: 0; } /* hide text, keep logout link */
  .sidebar-footer a { font-size: 11px; }
  .main-content { margin-left: 72px; padding: 20px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* Wide modal on larger mobile (logs) */
@media (max-width: 768px) {
  .modal-wide { width: 100%; border-radius: 16px 16px 0 0; }
}

/* ── LLM / Chat ── */
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; font-weight: 600; font-size: 15px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.header-actions { display: flex; align-items: center; gap: 10px; }
.mb-16 { margin-bottom: 16px; }

/* Stats row (GPU/CPU) */
.stats-row { display: flex; flex-wrap: wrap; gap: 16px; padding: 14px 16px; }
.stat-item { min-width: 100px; }
.stat-label { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px; }
.stat-value { font-size: 18px; font-weight: 600; color: #e6edf3; }

/* Badges */
.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 10px; font-size: 12px; font-weight: 500;
}
.badge-ok  { background: rgba(63,185,80,.15); color: #3fb950; }
.badge-err { background: rgba(248,81,73,.15); color: #f85149; }
.badge-warn { background: rgba(210,153,34,.15); color: #d29922; }

/* Small buttons */
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn-warn { background: #d29922; color: #0d1117; }
.btn-warn:hover { background: #e3b341; }

/* Select sm (model picker in chat header) */
.select-sm {
  padding: 4px 8px; font-size: 13px; border-radius: 6px;
  background: #161b22; color: #c9d1d9; border: 1px solid #30363d;
  outline: none; cursor: pointer;
}
.select-sm:focus { border-color: #58a6ff; }

/* Chat messages */
.chat-messages {
  height: 400px; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  background: #0d1117;
}
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; line-height: 1.5; font-size: 14px; }
.chat-user {
  align-self: flex-end;
  background: #1f6feb; color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-assistant {
  align-self: flex-start;
  background: #21262d; color: #c9d1d9;
  border-bottom-left-radius: 4px;
}
.chat-role { font-size: 11px; font-weight: 600; color: #8b949e; margin-bottom: 4px; }
.chat-text { white-space: pre-wrap; word-break: break-word; }
.chat-text code { background: rgba(110,118,129,.2); padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.chat-text pre { background: rgba(0,0,0,.3); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.chat-text pre code { background: none; padding: 0; }
.chat-empty { text-align: center; color: #484f58; padding: 60px 0; font-size: 14px; }

/* Chat input */
.chat-input-wrap {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  background: #161b22;
}
.chat-input-wrap textarea {
  flex: 1; resize: none;
  background: #0d1117; color: #c9d1d9; border: 1px solid #30363d;
  border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
.chat-input-wrap textarea:focus { border-color: #58a6ff; }

/* Tags (pull modal) */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag {
  padding: 4px 10px; border-radius: 14px; font-size: 12px;
  background: #21262d; color: #c9d1d9; cursor: pointer;
  border: 1px solid #30363d; transition: all .15s;
}
.tag:hover { background: #30363d; border-color: #58a6ff; color: #fff; }

/* Pull progress */
.pull-progress { margin-top: 12px; }
.pull-status { font-weight: 600; font-size: 14px; margin-bottom: 6px; color: #c9d1d9; }
.pull-detail { font-size: 12px; color: #8b949e; margin-top: 4px; }

/* Utility */
.text-muted { color: #484f58; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions-cell { display: flex; gap: 6px; }

/* Safe area for iOS notch / home indicator */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .sidebar {
      height: calc(60px + env(safe-area-inset-bottom));
      padding-bottom: env(safe-area-inset-bottom);
    }
    .main-content {
      padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }
  }
}
