:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e37;
  --text: #e6e8eb;
  --muted: #9aa1ac;
  --accent: #5b8def;
  --danger: #e05561;
  --success: #3ec28f;

  --sidebar-bg: #12141a;
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 68px;
  --hover-bg: rgba(255, 255, 255, 0.04);
  --active-bg: rgba(91, 141, 239, 0.12);
  --active-border: var(--accent);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.app-shell.collapsed .sidebar { width: var(--sidebar-width-collapsed); }
.app-shell.collapsed .nav-label,
.app-shell.collapsed .brand-text { display: none; }
.app-shell.collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); font-weight: 700; margin-right: auto; }
.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--accent);
  background: var(--active-bg);
  border-radius: 8px;
}
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.3rem;
  cursor: pointer;
}
.sidebar-collapse-btn:hover { color: var(--text); border-color: var(--muted); }
.sidebar-collapse-btn svg { transition: transform 0.2s ease; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.75rem; flex: 1; overflow-y: auto; }
.sidebar-footer { padding: 0.75rem; border-top: 1px solid var(--border); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.nav-item:hover { background: var(--hover-bg); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--active-bg); color: var(--text); border-left-color: var(--active-border); }
.nav-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 18px; height: 18px; }
.nav-item-btn {
  width: 100%;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.main-wrap { flex: 1; min-width: 0; }

.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }
  .app-shell.mobile-open .sidebar { transform: translateX(0); }
  .app-shell.collapsed .sidebar { width: var(--sidebar-width); }
  .app-shell.collapsed .nav-label,
  .app-shell.collapsed .brand-text { display: inline; }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .app-shell.mobile-open .sidebar-backdrop { display: block; opacity: 1; pointer-events: auto; }

  .hamburger-btn {
    display: flex;
    position: fixed;
    top: 0.85rem;
    left: 0.85rem;
    z-index: 80;
    padding: 0.5rem;
  }
  .sidebar-collapse-btn { display: none; }
  .container { padding-top: 4rem; }
}

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.stat-grid { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { flex: 1; min-width: 160px; }
.stat .value { font-size: 2rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.75rem; }
.badge.active { background: rgba(62,194,143,0.15); color: var(--success); }
.badge.inactive { background: rgba(224,85,97,0.15); color: var(--danger); }

form.inline { display: inline; }

label { display: block; margin-bottom: 0.3rem; color: var(--muted); font-size: 0.85rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
textarea { min-height: 90px; font-family: ui-monospace, monospace; }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
  transition: filter 0.15s ease;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.secondary, .btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); box-shadow: none; }
button.danger, .btn.danger { background: var(--danger); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.error-box {
  background: rgba(224,85,97,0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 200px; }

.preview-box {
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  margin-bottom: 1rem;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 0%, rgba(91, 141, 239, 0.08), transparent 60%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}
.login-brand .brand-mark {
  width: 36px;
  height: 36px;
}
.login-brand span:last-child {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

/* Modal component (replaces all native confirm/alert dialogs) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 200;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  box-shadow: none;
  padding: 0.25rem;
  font-size: 1.3rem;
  line-height: 1;
}
.modal-close-btn:hover { color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* Card grid (Plans, Server locations) */
.card-grid { display: flex; flex-wrap: wrap; gap: 1rem; }
.card-grid .card { flex: 1 1 260px; margin-bottom: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.card-grid .card h3 { margin: 0 0 0.2rem 0; font-size: 1.05rem; }
.card-grid .card .muted-row { color: var(--muted); font-size: 0.85rem; }
.card-grid .card .badges { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.2rem 0; }
.card-grid .card .card-actions { margin-top: auto; display: flex; gap: 0.5rem; padding-top: 0.75rem; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.toggle-row label { margin-bottom: 0; }

.pagination { display: flex; align-items: center; gap: 0.75rem; justify-content: center; margin-top: 1rem; }
.pagination .page-info { color: var(--muted); font-size: 0.85rem; }

.success-box {
  background: rgba(62, 194, 143, 0.12);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}
