@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Dark theme — matches IPManager production (.dark class) */
  --background: hsl(222 30% 8%);
  --foreground: hsl(210 20% 92%);
  --card: hsl(222 25% 11%);
  --card-foreground: hsl(210 20% 92%);
  --popover: hsl(222 25% 11%);
  --popover-foreground: hsl(210 20% 92%);
  --primary: hsl(210 100% 55%);
  --primary-foreground: hsl(0 0% 100%);
  --secondary: hsl(222 20% 16%);
  --secondary-foreground: hsl(210 20% 92%);
  --muted: hsl(222 20% 16%);
  --muted-foreground: hsl(215 15% 55%);
  --accent: hsl(160 60% 45%);
  --accent-foreground: hsl(0 0% 100%);
  --destructive: hsl(0 72% 51%);
  --destructive-foreground: hsl(0 0% 100%);
  --border: hsl(222 20% 18%);
  --input: hsl(222 20% 18%);
  --ring: hsl(210 100% 55%);
  --radius: 0.5rem;

  /* Sidebar — even darker */
  --sidebar-bg: hsl(222 30% 6%);
  --sidebar-fg: hsl(210 15% 75%);
  --sidebar-primary: hsl(210 100% 55%);
  --sidebar-primary-foreground: hsl(0 0% 100%);
  --sidebar-accent: hsl(222 25% 12%);
  --sidebar-accent-foreground: hsl(210 15% 75%);
  --sidebar-border: hsl(222 25% 12%);
  --sidebar-ring: hsl(210 100% 55%);

  /* Semantic */
  --success: hsl(160 60% 45%);
  --success-foreground: hsl(0 0% 100%);
  --warning: hsl(38 92% 50%);
  --warning-foreground: hsl(0 0% 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: hsl(215 15% 55% / 0.25); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: hsl(215 15% 55% / 0.4); }
*::-webkit-scrollbar-corner { background: transparent; }

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

/* ============ SIDEBAR ============ */
/* IPManager: w-64 (256px) */
.sidebar {
  width: 256px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}

/* IPManager: px-6 py-5 gap-3, border-b border-sidebar-border */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--sidebar-border);
}

/* IPManager: h-9 w-9 rounded-lg bg-sidebar-primary/10 */
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  background: hsl(210 100% 55% / 0.1);
  flex-shrink: 0;
}

/* IPManager: h-5 w-5 text-sidebar-primary */
.sidebar-logo svg { color: var(--sidebar-primary); width: 20px; height: 20px; }

/* IPManager: text-lg font-bold text-sidebar-foreground */
.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--sidebar-fg);
}

/* IPManager: px-3 py-4 space-y-1 */
.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(210 15% 45%);
  padding: 16px 12px 4px;
}

/* IPManager: gap-3 px-3 py-2.5 rounded-lg text-sm font-medium
   text-sm = 14px, font-medium = 500
   inactive: text-sidebar-foreground/70
   active: bg-sidebar-accent text-sidebar-primary */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: hsl(210 15% 75% / 0.7);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

/* IPManager: hover:bg-sidebar-accent hover:text-sidebar-foreground */
.nav-item:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-fg);
}

/* IPManager: bg-sidebar-accent text-sidebar-primary */
.nav-item.active {
  background: var(--sidebar-accent);
  color: var(--sidebar-primary);
}

/* IPManager: h-4 w-4 shrink-0 */
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

/* IPManager: px-3 py-4 border-t border-sidebar-border — only logout button, no user info */
.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--sidebar-border);
}

/* IPMapper logout: gap-3 text-sidebar-foreground/70 hover:text-sidebar-foreground */
.btn-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: hsl(210 15% 75% / 0.7);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-logout:hover { background: var(--sidebar-accent); color: var(--sidebar-fg); }
.btn-logout svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  margin-left: 256px;
}

/* IPManager: max-w-5xl mx-auto p-6 — extended for wider tables */
.main-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page-header { margin-bottom: 24px; }

/* IPManager: text-2xl font-bold flex items-center gap-2 */
.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--foreground);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* IPManager: icon h-6 w-6 text-primary */
.page-header h2 svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* IPManager: CardDescription = text-sm text-muted-foreground */
.page-header p {
  font-size: 14px;
  color: var(--muted-foreground);
  margin-top: 4px;
}

/* ============ CARDS ============ */
/* IPManager: rounded-lg border bg-card shadow-sm */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* IPManager: CardHeader = flex flex-col space-y-1.5 p-6 */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

/* IPManager: CardTitle = text-2xl font-semibold (but we use smaller for table headers) */
.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--foreground);
}

/* IPManager: CardContent = p-6 pt-0 */
.card-body { padding: 24px; }

/* ============ TABLES ============ */
/* IPManager: w-full overflow-auto */
.table-container {
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
}

/* IPManager: w-full caption-bottom text-sm */
table { width: 100%; border-collapse: collapse; font-size: 14px; }

thead { position: sticky; top: 0; z-index: 1; }

/* IPManager: h-12 px-4 font-medium text-muted-foreground, [&_tr]:border-b */
th {
  height: 48px;
  padding: 0 16px;
  text-align: left;
  vertical-align: middle;
  font-weight: 500;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

/* IPManager: p-4 align-middle */
td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  color: var(--foreground);
  vertical-align: middle;
}

/* IPManager: hover:bg-muted/50 */
tr:hover td { background: hsl(222 20% 16% / 0.5); }

/* ============ BUTTONS ============ */
/* IPManager: h-10 px-4 py-2 text-sm font-medium rounded-md */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 8px 16px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

/* default: bg-primary hover:bg-primary/90 */
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: hsl(210 100% 55% / 0.9); }
/* destructive: bg-destructive hover:bg-destructive/90 */
.btn-danger { background: var(--destructive); color: var(--destructive-foreground); }
.btn-danger:hover { background: hsl(0 72% 51% / 0.9); }
.btn-success { background: var(--success); color: var(--success-foreground); }
.btn-success:hover { background: hsl(160 60% 45% / 0.9); }
/* outline: border-input bg-background hover:bg-secondary */
.btn-outline {
  background: var(--background);
  border: 1px solid var(--input);
  color: var(--foreground);
}
.btn-outline:hover { background: var(--secondary); }
.btn-outline.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}
/* ghost: hover:bg-accent hover:text-accent-foreground */
.btn-ghost {
  background: transparent;
  border: none;
  color: var(--muted-foreground);
}
.btn-ghost:hover { background: var(--accent); color: var(--accent-foreground); }
/* secondary: bg-secondary hover:bg-secondary/80 */
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover { background: hsl(222 20% 16% / 0.8); }
/* IPManager: h-9 rounded-md px-3 */
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 14px; }

/* IPManager: Label = text-sm font-medium */
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--foreground);
  margin-bottom: 6px;
}

/* IPManager: h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm */
.form-control {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  color: var(--foreground);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring);
}

.form-control::placeholder { color: var(--muted-foreground); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a8599' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  padding-right: 32px;
}

.form-hint {
  font-size: 12px;
  color: var(--muted-foreground);
  margin-top: 4px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ============ BADGES ============ */
/* IPManager: rounded-full border px-2.5 py-0.5 text-xs font-semibold */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 9999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}

.badge-success { background: hsl(160 60% 45% / 0.1); color: var(--success); }
.badge-danger { background: hsl(0 72% 51% / 0.1); color: var(--destructive); }
.badge-warning { background: hsl(38 92% 50% / 0.1); color: var(--warning); }
.badge-info { background: hsl(210 100% 55% / 0.1); color: var(--sidebar-primary); }
.badge-muted { background: var(--muted); color: var(--muted-foreground); }

/* ============ MODAL ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted-foreground);
  cursor: pointer;
  font-size: 20px;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover { color: var(--foreground); }

.modal-body { padding: 20px; }

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============ LOGIN ============ */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--background);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.login-card-header {
  padding: 32px 32px 0;
  text-align: center;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  border-radius: 12px;
  background: hsl(210 100% 55% / 0.1);
  margin-bottom: 16px;
}

.login-logo svg { color: var(--primary); }

/* IPManager Auth: text-2xl font-bold */
.login-card-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 4px;
}

/* IPManager: CardDescription */
.login-card-header .subtitle {
  font-size: 14px;
  color: var(--muted-foreground);
  margin-bottom: 24px;
}

.login-card-body { padding: 20px 32px 32px; }

.login-card .form-control { margin-bottom: 12px; }
.login-card .btn { width: 100%; margin-top: 4px; }

.login-error {
  color: var(--destructive);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

.login-footer {
  text-align: center;
  padding-bottom: 24px;
  font-size: 12px;
  color: var(--muted-foreground);
}

/* ============ TABS (operations) ============ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

/* ============ TOAST ============ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.toast-success { background: var(--card); border: 1px solid var(--border); color: var(--success); box-shadow: 0 4px 16px rgba(0,0,0,0.3); border-left: 3px solid var(--success); }
.toast-error { background: var(--card); border: 1px solid var(--border); color: var(--destructive); box-shadow: 0 4px 16px rgba(0,0,0,0.3); border-left: 3px solid var(--destructive); }
.toast-warning { background: var(--card); border: 1px solid var(--border); color: var(--warning); box-shadow: 0 4px 16px rgba(0,0,0,0.3); border-left: 3px solid var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-header { display: flex !important; }
  .main-content { margin-left: 0; margin-top: 56px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* Mobile header (hidden on desktop) */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  padding: 12px 16px;
  align-items: center;
  justify-content: space-between;
}

.mobile-header h1 { color: var(--sidebar-fg); font-size: 16px; font-weight: 700; }

/* Action buttons inline */
.action-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

td:last-child, th:last-child {
  min-width: 180px;
}

/* Admin visibility */
.admin-only { display: none; }
body.is-admin .admin-only { display: initial; }
