/* ── Root Variables ───────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 240px;
  --topbar-h:  60px;

  --bg:        #f0f4f8;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;

  --sidebar-bg:     #1e293b;
  --sidebar-hover:  #273549;
  --sidebar-active: #3b82f6;
  --sidebar-text:   #94a3b8;
  --sidebar-text-a: #ffffff;

  --primary:        #3b82f6;
  --primary-dark:   #2563eb;
  --primary-light:  #eff6ff;
  --success:        #22c55e;
  --success-light:  #f0fdf4;
  --danger:         #ef4444;
  --danger-light:   #fef2f2;
  --warning:        #f59e0b;
  --warning-light:  #fffbeb;
  --info:           #06b6d4;
  --info-light:     #ecfeff;

  --text:      #1e293b;
  --text2:     #475569;
  --muted:     #94a3b8;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', system-ui, -apple-system, sans-serif; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }
input, select, textarea, button { font: inherit; }
img { max-width: 100%; }

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

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.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;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo .brand {
  display: flex; align-items: center; gap: 10px;
  color: #ffffff; font-size: 16px; font-weight: 700;
  text-decoration: none;
}
.sidebar-logo .brand:hover { text-decoration: none; }
.sidebar-logo .brand-icon {
  width: 34px; height: 34px; background: var(--primary);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.sidebar-logo .version {
  font-size: 10px; color: var(--muted); margin-top: 2px; display: block;
}

.sidebar-section {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.sidebar-section-label {
  padding: 4px 20px 6px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: #475569;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: 13.5px; font-weight: 500;
  border-radius: 0;
  transition: background .15s, color .15s;
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); color: #e2e8f0; text-decoration: none; }
.nav-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-a);
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: #93c5fd;
  border-radius: 0 2px 2px 0;
}
.nav-item .nav-icon { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 6px;
  border-radius: 10px;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 12px 20px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user-avatar {
  width: 32px; height: 32px; background: var(--primary);
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: #fff; font-weight: 700;
  font-size: 13px; flex-shrink: 0;
}
.sidebar-user-name { color: #e2e8f0; font-size: 13px; font-weight: 500; }
.sidebar-user-role { color: var(--muted); font-size: 11px; }
.sidebar-logout {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; color: #94a3b8; font-size: 12px;
  padding: 6px 0; cursor: pointer; width: 100%;
  background: none; border: none;
}
.sidebar-logout:hover { color: var(--danger); }

/* ── Main wrapper ─────────────────────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }
.topbar-subtitle { color: var(--muted); font-size: 13px; }
.breadcrumb { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.breadcrumb a { color: var(--primary); }
.breadcrumb-sep { color: var(--border2); }

.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 12px; color: var(--text2);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); flex-shrink: 0;
}
.status-dot.inactive { background: var(--danger); }

/* ── Content area ─────────────────────────────────────────────────────────── */
.content { padding: 24px; flex: 1; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  margin-bottom: 20px; font-size: 13.5px; font-weight: 500;
  border-left: 4px solid;
}
.flash.success { background: var(--success-light); border-color: var(--success); color: #166534; }
.flash.error   { background: var(--danger-light);  border-color: var(--danger);  color: #991b1b; }
.flash.warning { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.flash.info    { background: var(--info-light);    border-color: var(--info);    color: #164e63; }
.flash-close { margin-left: auto; cursor: pointer; opacity: .6; background: none; border: none; font-size: 16px; }
.flash-close:hover { opacity: 1; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.page-header p  { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.card-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 18px 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.stat-icon.blue    { background: var(--primary-light); color: var(--primary); }
.stat-icon.green   { background: var(--success-light); color: var(--success); }
.stat-icon.yellow  { background: var(--warning-light); color: var(--warning); }
.stat-icon.red     { background: var(--danger-light);  color: var(--danger);  }
.stat-icon.cyan    { background: var(--info-light);    color: var(--info);    }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--muted); }

/* Progress bar */
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar {
  height: 100%; border-radius: 99px; background: var(--primary);
  transition: width .4s ease;
}
.progress-bar.green  { background: var(--success); }
.progress-bar.yellow { background: var(--warning); }
.progress-bar.red    { background: var(--danger); }

/* ── Grid layouts ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 12px 14px; font-size: 13.5px; vertical-align: middle; }
.td-mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12.5px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-green   { background: var(--success-light); color: #15803d; }
.badge-red     { background: var(--danger-light);  color: #b91c1c; }
.badge-blue    { background: var(--primary-light); color: var(--primary-dark); }
.badge-yellow  { background: var(--warning-light); color: #b45309; }
.badge-gray    { background: #f1f5f9; color: var(--text2); }
.badge-cyan    { background: var(--info-light);    color: #0e7490; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; transition: all .15s; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #16a34a; }
.btn-danger  { background: var(--danger);  color: #fff; border-color: var(--danger);  }
.btn-danger:hover  { background: #dc2626; }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover { background: #d97706; }
.btn-outline {
  background: transparent; color: var(--text2);
  border-color: var(--border2);
}
.btn-outline:hover { background: var(--surface2); border-color: var(--primary); color: var(--primary); }
.btn-ghost {
  background: transparent; color: var(--text2); border-color: transparent;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 11px; border-radius: 4px; }
.btn-icon {
  width: 30px; height: 30px; padding: 0; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.form-control {
  display: block; width: 100%;
  padding: 8px 11px; font-size: 13.5px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border2); border-radius: 6px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.12); background: #fff; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.form-inline { display: flex; gap: 8px; align-items: flex-end; }
.form-inline .form-group { flex: 1; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.4); z-index: 200;
  align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 24px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal.modal-lg { max-width: 640px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--muted); width: 28px; height: 28px; display: flex;
  align-items: center; justify-content: center; border-radius: 4px;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ── Toast notifications ──────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--text); color: #fff; padding: 12px 16px;
  border-radius: 8px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md); min-width: 260px; max-width: 380px;
  animation: toastIn .2s ease; cursor: pointer;
}
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
.toast.warning { background: #92400e; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Service status grid ──────────────────────────────────────────────────── */
.service-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.service-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.service-info { display: flex; flex-direction: column; }
.service-name { font-size: 13px; font-weight: 600; color: var(--text); }
.service-status { font-size: 11.5px; margin-top: 2px; }
.service-actions { display: flex; gap: 4px; }

/* ── File manager ─────────────────────────────────────────────────────────── */
.file-path-bar {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px;
}
.file-path-bar a { color: var(--primary); }
.file-item { display: flex; align-items: center; gap: 10px; }
.file-icon { font-size: 16px; flex-shrink: 0; }

/* ── Code editor ──────────────────────────────────────────────────────────── */
.code-editor {
  width: 100%; background: #1e293b; color: #e2e8f0;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px; line-height: 1.7; resize: vertical;
  min-height: 400px; outline: none;
}
.code-editor:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 18px; font-size: 13.5px; font-weight: 500;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon {
  width: 56px; height: 56px; background: var(--primary);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 12px;
}
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.login-logo p  { font-size: 13px; color: var(--muted); }
.login-card .form-control { padding: 10px 13px; }
.login-card .btn { width: 100%; padding: 10px; font-size: 14px; }

/* ── Confirm dialog ───────────────────────────────────────────────────────── */
.confirm-modal { text-align: center; }
.confirm-modal .confirm-icon { font-size: 48px; margin-bottom: 12px; }
.confirm-modal p { color: var(--text2); font-size: 14px; }

/* ── Responsive tweaks ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .main-wrap { margin-left: 0; }
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Utility classes ──────────────────────────────────────────────────────── */
.text-muted  { color: var(--muted); }
.text-small  { font-size: 12px; }
.text-bold   { font-weight: 600; }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-primary{ color: var(--primary); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 20px; }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ── Redis / stat-mini ──────────────────────────────────────── */
.stat-mini { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.stat-mini-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.stat-mini-value { font-size: 18px; font-weight: 700; color: var(--text); }
