/* ==========================================================================
   Nexus UI — shared stylesheet for Ceban Automation apps.

   Load order (every app):
     1. Bootstrap 5.3.x            bootstrap.min.css
     2. Bootstrap Icons 1.x        bootstrap-icons.min.css
     3. this file                  nexus.css

   Theme: set data-bs-theme="light" or "dark" on <html>. For "follow the
   system", resolve it in a tiny inline script before first paint (see the
   Nexus design system README).

   Every --nx-* value below is a default. They sit inside :where() so a
   later :root block (or a design-system tokens.css) overrides them without
   a specificity fight. Components only read --nx-* and --bs-* variables.
   ========================================================================== */

/* ---- Tokens: light defaults -------------------------------------------- */
:where(:root) {
  /* Brand */
  --nx-primary: #c70b5e;
  --nx-primary-hover: #9f094b;
  --nx-primary-pressed: #950945;
  --nx-primary-pressed-border: #8c0841;
  --nx-primary-text: #500426;
  --nx-primary-subtle: #f4cedf;
  --nx-primary-border-subtle: #e99dbf;
  --nx-on-primary: #ffffff;
  --nx-link-hover: #9f094b;
  --nx-accent: #1da869;
  --nx-accent-hover: #178654;
  --nx-accent-pressed: #167e4f;
  --nx-accent-pressed-border: #14764a;
  --nx-on-accent: #ffffff;

  /* Neutrals (Bootstrap 5.3 values) */
  --nx-surface: #ffffff;
  --nx-surface-muted: #f8f9fa;
  --nx-surface-hover: #e9ecef;
  --nx-ink: #212529;
  --nx-ink-strong: #000000;
  --nx-ink-muted: rgba(33, 37, 41, 0.75);
  --nx-border: #dee2e6;

  /* RGB triples Bootstrap needs for its rgba() utilities.
     Keep these in step with --nx-primary / --nx-accent. */
  --nx-primary-rgb: 199, 11, 94;
  --nx-accent-rgb: 29, 168, 105;

  /* Layout */
  --nx-navbar-height: 3.5rem;
  --nx-sidebar-width: 250px;
  --nx-card-pad: 1.125rem;
  --nx-cell-pad: 0.875rem;

  /* Radii */
  --nx-radius-control: 0.375rem;
  --nx-radius-nav: 0.5rem;
  --nx-radius-icon: 0.625rem;
  --nx-radius-card: 0.75rem;

  /* Shadows */
  --nx-shadow-tile-hover: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

/* ---- Tokens: dark overrides -------------------------------------------- */
:where([data-bs-theme="dark"]) {
  --nx-primary-text: #dd6d9e;
  --nx-primary-subtle: #280213;
  --nx-primary-border-subtle: #770738;
  --nx-link-hover: #dd6d9e;

  --nx-surface: #212529;
  --nx-surface-muted: #2b3035;
  --nx-surface-hover: #343a40;
  --nx-ink: #dee2e6;
  --nx-ink-strong: #ffffff;
  --nx-ink-muted: rgba(222, 226, 230, 0.75);
  --nx-border: #495057;
}

/* ---- Wire the tokens into Bootstrap ------------------------------------- */
:root,
[data-bs-theme] {
  --bs-primary: var(--nx-primary);
  --bs-primary-rgb: var(--nx-primary-rgb);
  --bs-primary-text-emphasis: var(--nx-primary-text);
  --bs-primary-bg-subtle: var(--nx-primary-subtle);
  --bs-primary-border-subtle: var(--nx-primary-border-subtle);
  --bs-link-color: var(--nx-primary);
  --bs-link-color-rgb: var(--nx-primary-rgb);
  --bs-link-hover-color: var(--nx-link-hover);
  --bs-link-hover-color-rgb: 159, 9, 75;

  --bs-body-bg: var(--nx-surface);
  --bs-body-color: var(--nx-ink);
  --bs-emphasis-color: var(--nx-ink-strong);
  --bs-secondary-color: var(--nx-ink-muted);
  --bs-secondary-bg: var(--nx-surface-hover);
  --bs-tertiary-bg: var(--nx-surface-muted);
  --bs-border-color: var(--nx-border);
  --bs-border-radius: var(--nx-radius-control);

  --brand-primary: var(--nx-primary);
  --brand-accent: var(--nx-accent);
}

[data-bs-theme="dark"] {
  --bs-link-hover-color-rgb: 221, 109, 158;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn-primary {
  --bs-btn-color: var(--nx-on-primary);
  --bs-btn-bg: var(--nx-primary);
  --bs-btn-border-color: var(--nx-primary);
  --bs-btn-hover-color: var(--nx-on-primary);
  --bs-btn-hover-bg: var(--nx-primary-hover);
  --bs-btn-hover-border-color: var(--nx-primary-pressed);
  --bs-btn-active-color: var(--nx-on-primary);
  --bs-btn-active-bg: var(--nx-primary-pressed);
  --bs-btn-active-border-color: var(--nx-primary-pressed-border);
  --bs-btn-disabled-color: var(--nx-on-primary);
  --bs-btn-disabled-bg: var(--nx-primary);
  --bs-btn-disabled-border-color: var(--nx-primary);
}

.text-accent {
  color: var(--nx-accent) !important;
}

.btn-accent {
  --bs-btn-color: var(--nx-on-accent);
  --bs-btn-bg: var(--nx-accent);
  --bs-btn-border-color: var(--nx-accent);
  --bs-btn-hover-color: var(--nx-on-accent);
  --bs-btn-hover-bg: var(--nx-accent-hover);
  --bs-btn-hover-border-color: var(--nx-accent-pressed);
  --bs-btn-active-color: var(--nx-on-accent);
  --bs-btn-active-bg: var(--nx-accent-pressed);
  --bs-btn-active-border-color: var(--nx-accent-pressed-border);
  --bs-btn-disabled-color: var(--nx-on-accent);
  --bs-btn-disabled-bg: var(--nx-accent);
  --bs-btn-disabled-border-color: var(--nx-accent);
}

/* ---- Login card + logo ------------------------------------------------- */
.auth-card {
  width: 100%;
  max-width: 360px;
}

.logo {
  display: block;
  max-width: 96px;
  height: auto;
}

/* ---- Dashboard app tiles ----------------------------------------------- */
.app-tile {
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.app-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--nx-shadow-tile-hover) !important;
}

.app-tile__icon {
  width: 44px;
  height: 44px;
  background: var(--nx-primary-subtle);
  color: var(--nx-primary-text);
}

/* ---- App shell: navbar + sidebar + main -------------------------------- */
body.admin-body {
  background: var(--bs-body-bg);
}

.admin-navbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  min-height: var(--nx-navbar-height);
  gap: 0.5rem;
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
}

.admin-shell {
  display: flex;
  align-items: flex-start;
}

.admin-sidebar {
  flex: 0 0 var(--nx-sidebar-width);
  width: var(--nx-sidebar-width);
}

@media (min-width: 992px) {
  .admin-sidebar {
    position: sticky;
    top: var(--nx-navbar-height);
    align-self: stretch;
    height: calc(100vh - var(--nx-navbar-height));
    overflow-y: auto;
    border-right: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
  }
}

.admin-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.75rem 1.5rem 4rem;
}

@media (min-width: 1400px) {
  .admin-main {
    padding-left: 2.5rem;
    padding-right: 2.5rem;
  }
}

/* ---- Sidebar nav ------------------------------------------------------- */
.admin-nav {
  padding: 1rem 0.75rem 2rem;
}

.admin-nav__label {
  margin: 1.25rem 0 0.375rem;
  padding: 0 0.75rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
}

.admin-nav__label:first-child {
  margin-top: 0;
}

.admin-nav__link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--nx-radius-nav);
  color: var(--bs-body-color);
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
}

.admin-nav__link i {
  width: 1.15rem;
  font-size: 1.05rem;
  text-align: center;
  color: var(--bs-secondary-color);
}

.admin-nav__link:hover {
  background: var(--bs-secondary-bg);
}

.admin-nav__link.active {
  background: var(--nx-primary);
  color: var(--nx-on-primary);
}

.admin-nav__link.active i {
  color: var(--nx-on-primary);
}

/* ---- Navbar avatar ----------------------------------------------------- */
.admin-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--nx-primary);
  color: var(--nx-on-primary);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---- Page header ------------------------------------------------------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.page-header__title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
}

.page-header__lead {
  margin: 0.25rem 0 0;
  max-width: 60ch;
  color: var(--bs-secondary-color);
  font-size: 0.9375rem;
}

.page-header__actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-back {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
  text-decoration: none;
}

.admin-back:hover {
  color: var(--bs-body-color);
}

/* ---- Cards ------------------------------------------------------------- */
.admin-card {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--nx-radius-card);
}

.admin-card__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem var(--nx-card-pad);
  border-bottom: 1px solid var(--bs-border-color);
  font-weight: 600;
}

.admin-card__body {
  padding: var(--nx-card-pad);
}

/* ---- Tables ------------------------------------------------------------ */
.admin-table {
  margin: 0;
}

.admin-table thead th {
  padding: 0.75rem var(--nx-cell-pad);
  background: var(--bs-tertiary-bg);
  border-bottom-color: var(--bs-border-color);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  white-space: nowrap;
}

.admin-table tbody td {
  padding: var(--nx-cell-pad);
  vertical-align: middle;
}

.admin-table tbody tr:last-child td {
  border-bottom: 0;
}

.admin-table .row-actions {
  display: inline-flex;
  gap: 0.375rem;
  justify-content: flex-end;
}

/* Drag-to-reorder rows */
.admin-table .drag-handle {
  width: 1%;
  padding-right: 0;
  color: var(--bs-secondary-color);
  cursor: grab;
  user-select: none;
}

.admin-table .drag-handle:active {
  cursor: grabbing;
}

.admin-table tr.is-dragging td {
  opacity: 0.5;
  background: var(--bs-tertiary-bg);
}

/* ---- Icon bubble ------------------------------------------------------- */
.icon-bubble {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--nx-radius-icon);
  background: var(--nx-primary-subtle);
  color: var(--nx-primary-text);
  font-size: 1.1rem;
}

.icon-bubble--sm {
  width: 32px;
  height: 32px;
  font-size: 0.95rem;
}

.icon-bubble--muted {
  background: var(--bs-secondary-bg);
  color: var(--bs-secondary-color);
}

/* ---- Stat cards -------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

a.stat-card:hover {
  border-color: var(--nx-primary);
  transform: translateY(-1px);
}

.stat-card__value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card__value small {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--bs-secondary-color);
}

.stat-card__label {
  margin-top: 0.15rem;
  font-size: 0.875rem;
  color: var(--bs-secondary-color);
}

/* ---- Activity feed ----------------------------------------------------- */
.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed li {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem var(--nx-card-pad);
  border-top: 1px solid var(--bs-border-color);
}

.feed li:first-child {
  border-top: 0;
}

.feed__dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.4rem;
  border-radius: 50%;
  background: var(--nx-primary);
}

.feed__dot--warn { background: var(--bs-warning); }
.feed__dot--error { background: var(--bs-danger); }

.feed__body {
  min-width: 0;
  font-size: 0.9rem;
}

.feed__meta {
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

/* ---- Empty state ------------------------------------------------------- */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--bs-secondary-color);
}

.empty-state i {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 2rem;
  opacity: 0.55;
}

/* ---- Forms ------------------------------------------------------------- */
.form-narrow {
  max-width: 760px;
}

.form-fieldset {
  padding: var(--nx-card-pad);
  border-bottom: 1px solid var(--bs-border-color);
}

.form-fieldset:last-of-type {
  border-bottom: 0;
}

.form-fieldset__title {
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.form-fieldset__hint {
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
}

.form-footer {
  display: flex;
  gap: 0.5rem;
  padding: 1rem var(--nx-card-pad);
  background: var(--bs-tertiary-bg);
  border-top: 1px solid var(--bs-border-color);
  border-radius: 0 0 var(--nx-radius-card) var(--nx-radius-card);
}

/* Selectable list of checkboxes */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}

.check-tile {
  display: block;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--nx-radius-nav);
  cursor: pointer;
}

.check-tile:hover {
  border-color: var(--nx-primary-border-subtle);
}

.check-tile:has(input:checked) {
  border-color: var(--nx-primary);
  background: var(--nx-primary-subtle);
}

.check-tile .form-check {
  margin: 0;
}

/* Read-only keys / secrets */
.mono-field {
  font-family: var(--bs-font-monospace);
  font-size: 0.85rem;
}
