/* ============================================================
   Noctem Design System v2
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);

  --transition: 150ms ease;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

/* ---- Light theme ---- */
html[data-theme="light"] {
  --bg: #f7f7f8;
  --bg-elev: #ffffff;
  --topbar: #ffffff;
  --topbar-border: #ebebeb;
  --topbar-text: #111111;
  --card: #ffffff;
  --card-hover: #fafafa;
  --card-soft: #f2f2f3;
  --text: #111111;
  --text-secondary: #525252;
  --muted: #8b8b8b;
  --border: #e5e5e5;
  --border-strong: #d0d0d0;
  --ring: rgba(0, 0, 0, 0.08);
  --input-bg: #ffffff;
  --accent: #18181b;
  --accent-hover: #09090b;
  --accent-soft: rgba(0, 0, 0, 0.04);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, 0.08);
  --warn: #d97706;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.06);
  --selection: rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

/* ---- Dark theme ---- */
html[data-theme="dark"] {
  --bg: #09090b;
  --bg-elev: #111113;
  --topbar: #111113;
  --topbar-border: #1e1e21;
  --topbar-text: #ececef;
  --card: #141416;
  --card-hover: #1a1a1d;
  --card-soft: #1e1e21;
  --text: #ececef;
  --text-secondary: #a0a0a8;
  --muted: #63636e;
  --border: #232326;
  --border-strong: #2e2e33;
  --ring: rgba(255, 255, 255, 0.06);
  --input-bg: #0e0e10;
  --accent: #ececef;
  --accent-hover: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.05);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.1);
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.08);
  --selection: rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

/* ============================================================
   Reset & Base
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--selection);
}

a {
  color: var(--text-secondary);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  transition: color var(--transition);
}
a:hover {
  color: var(--text);
  text-decoration-color: var(--text);
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text);
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }

p { margin: 0; }

pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}

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

/* ============================================================
   Topbar
   ============================================================ */

.nx-topbar {
  height: 52px;
  background: var(--topbar);
  color: var(--topbar-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nx-topbar h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--topbar-text);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nx-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.nx-icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all var(--transition);
}
.nx-icon-btn:hover {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--border-strong);
}

/* ============================================================
   Shell Layout
   ============================================================ */

.nx-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 52px);
}

.nx-sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: var(--sp-5);
  position: sticky;
  top: 52px;
  height: calc(100vh - 52px);
  overflow-y: auto;
}

.nx-content {
  padding: var(--sp-6);
}

.nx-panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: var(--sp-3);
}

/* ============================================================
   Navigation Menu
   ============================================================ */

.nx-menu {
  display: grid;
  gap: 2px;
}

.nx-menu button {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 450;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 7px var(--sp-3);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}

.nx-menu button:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nx-menu button.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 550;
}

/* ============================================================
   Buttons
   ============================================================ */

.nx-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.nx-btn:hover {
  background: var(--card-hover);
  border-color: var(--border-strong);
}

.nx-btn:active {
  transform: scale(0.98);
}

.nx-btn.active {
  background: var(--accent-soft);
  border-color: var(--border-strong);
  font-weight: 600;
}

.nx-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.nx-btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.nx-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.nx-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.nx-btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nx-btn-danger {
  color: var(--danger);
  border-color: currentColor;
  background: var(--danger-soft);
}
.nx-btn-danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ============================================================
   Cards
   ============================================================ */

.nx-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
}

.nx-card + .nx-card {
  margin-top: var(--sp-4);
}

/* Clickable stat cards */
.nx-card[role="button"] {
  cursor: pointer;
  transition: all var(--transition);
}
.nx-card[role="button"]:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

/* ============================================================
   Grid Layouts
   ============================================================ */

.nx-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: var(--sp-4);
}

.nx-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

/* ============================================================
   Stats / KPI labels
   ============================================================ */

.nx-k {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.nx-v {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-top: 6px;
  color: var(--text);
}

/* ============================================================
   Toolbar
   ============================================================ */

.nx-toolbar {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  align-items: center;
}

/* ============================================================
   Form Controls
   ============================================================ */

.nx-input,
.nx-select,
.nx-textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  padding: 9px var(--sp-3);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.nx-input::placeholder,
.nx-textarea::placeholder {
  color: var(--muted);
}

.nx-input:focus,
.nx-select:focus,
.nx-textarea:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--ring);
}

.nx-input:disabled,
.nx-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nx-input-lg {
  font-size: 18px;
  padding: var(--sp-3) var(--sp-4);
}

.nx-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b8b8b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ============================================================
   Labels (form fields)
   ============================================================ */

.nx-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
  margin-top: var(--sp-4);
}
.nx-label:first-child { margin-top: 0; }

/* ============================================================
   Badge
   ============================================================ */

.nx-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-full);
  padding: 3px 10px;
  border: 1px solid var(--border);
  background: var(--card-soft);
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

/* ============================================================
   List & Items
   ============================================================ */

.nx-list {
  display: grid;
  gap: var(--sp-2);
}

.nx-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  transition: all var(--transition);
}
.nx-item:hover {
  background: var(--card-hover);
  border-color: var(--border-strong);
}

.nx-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ============================================================
   Messages / Feedback
   ============================================================ */

.nx-msg {
  min-height: 18px;
  font-size: 13px;
  color: var(--muted);
  margin-top: var(--sp-2);
}
.nx-msg.ok { color: var(--ok); }
.nx-msg.err { color: var(--danger); }

/* ============================================================
   Tables
   ============================================================ */

.nx-table {
  width: 100%;
  border-collapse: collapse;
}

.nx-table th,
.nx-table td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 10px var(--sp-3);
  font-size: 13px;
}

.nx-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: var(--sp-2);
}

.nx-table tr:last-child td {
  border-bottom: none;
}

.nx-table tr:hover td {
  background: var(--accent-soft);
}

.nx-table th[style*="cursor:pointer"]:hover,
.nx-table th[data-sort-key]:hover {
  color: var(--text);
}

/* ============================================================
   Sections (tabs)
   ============================================================ */

.nx-sections > section {
  display: none;
}
.nx-sections > section.active {
  display: block;
}

/* ============================================================
   Overlay & Modal
   ============================================================ */

.nx-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1200;
  display: none;
}
.nx-overlay.open {
  display: block;
}

.nx-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1300;
  padding: var(--sp-6);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.nx-modal.open {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   Drawer
   ============================================================ */

.nx-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(400px, 100vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 1300;
  transform: translateX(100%);
  transition: transform 200ms ease;
  display: flex;
  flex-direction: column;
}
.nx-drawer.open {
  transform: translateX(0);
}

.nx-drawer-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-height: 52px;
}

.nx-drawer-body {
  padding: var(--sp-5);
  overflow-y: auto;
  display: grid;
  gap: var(--sp-4);
  flex: 1;
}

/* ============================================================
   Auth pages (login, activate, change-password)
   ============================================================ */

.nx-page-center {
  min-height: calc(100vh - 52px);
  display: grid;
  place-items: center;
  padding: var(--sp-6);
}

.nx-auth-card {
  width: 100%;
  max-width: 400px;
}

.nx-auth-card h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* ============================================================
   Form field group
   ============================================================ */

.nx-field {
  margin-top: var(--sp-5);
}
.nx-field:first-child {
  margin-top: 0;
}

.nx-field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

/* ============================================================
   Divider
   ============================================================ */

.nx-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

/* ============================================================
   Utility
   ============================================================ */

.nx-narrow {
  max-width: 960px;
  margin: 0 auto;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 960px) {
  .nx-shell {
    grid-template-columns: 1fr;
  }
  .nx-sidebar {
    position: static;
    top: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nx-grid-4 {
    grid-template-columns: 1fr 1fr;
  }
  .nx-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .nx-topbar {
    height: 48px;
    padding: 0 var(--sp-4);
  }
  .nx-topbar h1 {
    font-size: 14px;
  }
  .nx-content,
  .nx-sidebar {
    padding: var(--sp-4);
  }
  .nx-grid-4 {
    grid-template-columns: 1fr;
  }
  .nx-card {
    padding: var(--sp-4);
    border-radius: var(--radius);
  }
  .nx-name {
    font-size: 15px;
  }
  .nx-modal {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    border-radius: var(--radius);
  }
  .nx-drawer {
    width: 100vw;
  }
  .nx-auth-card {
    max-width: 100%;
  }
  .nx-v {
    font-size: 24px;
  }
}
