/* ============================================================
   SWAM CARD LIST + SYSTEM CARD STYLES
   ============================================================ */

:root {
  --list-col-template:
    42px    /* Select */
    200px   /* Company */
    280px   /* Description */
    220px   /* Hostname */
    200px   /* User */
    96px    /* Agent */
    130px   /* Uptime */
    140px;  /* Last Seen */
}


/* Root container for both card view + list view */
.card-list {
  width: 100%;
  height: auto;          /* let content define height */
  overflow-y: visible;  /* desktop: no internal scroll */
  padding-right: 6px;
}

/* ----- CARD VIEW (default) -----
   When NOT in list-view mode, we use a column-first CSS grid.
   JS sets grid-template-columns to repeat(N, 390px).
*/
.card-list:not(.list-view) {
  display: grid;
  grid-auto-flow: column;      /* fill DOWN then ACROSS */
  grid-auto-rows: max-content; /* card height fits content */
  gap: 16px;                   /* spacing both directions */

  align-content: start;
  justify-content: start;
}

/* Scrollbar styling (common) */
.card-list::-webkit-scrollbar { width: 9px; }
.card-list::-webkit-scrollbar-thumb {
  background: rgba(90,106,133,0.4);
  border-radius: 6px;
}
.card-list::-webkit-scrollbar-track { background: transparent; }

/* ========================================================================
   CARD VIEW MODE
   ======================================================================== */

/* Base system card */
.system-card {
  width: 390px;
  max-width: 390px;
  min-width: 390px;

  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  cursor: pointer;

  display: flex;
  flex-direction: row;

  box-shadow: var(--glass-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  padding: 0;
}

.system-card:hover {
  background: var(--glass-bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
}

.system-card.selected {
  border: 2px solid var(--accent-blue);
}

/* Status strip via border-left */
.system-card.green { border-left: 6px solid #22c55e; }
.system-card.amber { border-left: 6px solid #eab308; }
.system-card.red   { border-left: 6px solid #ef4444; }

/* Card content */
.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  gap: 6px;
}

.hostname {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}

.meta-row {
  display: flex;
  gap: 10px;
  font-size: 0.82rem;
}

.meta-row .label {
  color: var(--text-muted);
  min-width: 80px;
}

.meta-row .meta-value {
  color: var(--text-main);
  font-weight: 500;
  white-space: nowrap;
}

/* MORE tab on the right edge */
.card-more-container {
  width: 20px;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.card-more-tab {
  writing-mode: vertical-rl;
  transform: rotate(180deg);

  width: 20px;
  border-radius: 6px 0 0 6px;
  margin-left: auto;

  display: flex;
  align-items: center;
  justify-content: center;

  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.08em;

  user-select: none;
  cursor: pointer;
  transition: opacity 0.2s;
}

.card-more-tab:hover { opacity: 0.85; }

.card-more-tab.green { background: #22c55e; color: #fff; }
.card-more-tab.amber { background: #eab308; color: #000; }
.card-more-tab.red   { background: #ef4444; color: #fff; }

/* ========================================================================
   LIST VIEW MODE — TABLE STYLE, NO CARD BOXES
   ======================================================================== */

/* Enable list mode parent */
.card-list.list-view {
  display: block !important;
  padding-right: 4px;

  /* ✅ MUST be visible for sticky to work */
  overflow: visible;
}


@media (pointer: coarse) {
  .card-list.list-view {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}


.card-list.list-view .system-row {
    padding: 4px 8px !important;
    margin: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    line-height: 1.2rem !important;
    background: transparent !important;
    display: grid !important;
    align-items: center !important;
}

/* Hide card boxes entirely in list view */
.card-list.list-view .system-card {
  display: none !important;
}

/* Row formatting for table-like appearance */
.system-row {
  display: grid !important;
  grid-template-columns: var(--list-col-template);
  gap: 4px;
  padding: 5px 10px;
  background: transparent !important;
  border-bottom: 1px solid rgba(255,255,255,0.05); /* softer separator */
  border-radius: 0 !important;
  cursor: pointer;
  font-size: 0.78rem;
  position: relative;
  transition: background 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.system-row {
  width: max-content;
}

.system-row:hover {
  background: rgba(255,255,255,0.04) !important;
}

/* =====================================================
   SELECTED ROW — STRONG ACTIVE STATE (DARK + LIGHT)
   4-state system: normal / hover / selected / selected+hover
   ===================================================== */

.system-row.row-selected {
  background: var(--row-selected-bg) !important;
  border-left: 4px solid var(--row-selected-rail) !important;
  border-bottom-color: var(--row-selected-border) !important;
  box-shadow: inset 0 0 0 1px var(--row-selected-border);
}

.system-row.row-selected:hover {
  background: var(--row-selected-bg-hover) !important;
  box-shadow: inset 0 0 0 1px var(--row-selected-border-hover);
}

.system-row.selected {
  background: var(--row-selected-bg) !important;
  border-left: 4px solid var(--row-selected-rail) !important;
  border-bottom-color: var(--row-selected-border) !important;
  box-shadow: var(--row-selected-shadow), inset 0 0 0 1px var(--row-selected-border);
  transform: translateX(2px);
  z-index: 1;
}

.system-row.selected:hover {
  background: var(--row-selected-bg-hover) !important;
  box-shadow: var(--row-selected-shadow-hover), inset 0 0 0 1px var(--row-selected-border-hover);
}

/* Column cells */
.row-col {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-col.host,
.row-col.user {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.row-col.agent {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.74rem;
  color: var(--text-main);
}

.row-col.select {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.service-select-checkbox {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Compact columns for stable widths */
.system-row .seen {
  width: 120px !important;
  min-width: 120px !important;
  text-align: left;
  color: var(--text-main);
}

.system-row .uptime {
  width: 110px !important;
  min-width: 110px !important;
  text-align: left;
  font-weight: 500;
}


/* LIST VIEW HEADER ROW */
/* LIST VIEW HEADER ROW — STICKY */
.header-row {
  position: sticky;
  top: 0;

  z-index: 20; /* stay above rows */
  background: var(--bg-alt);

  font-weight: 700;
  font-size: 0.80rem !important;
  border-bottom: 2px solid rgba(255,255,255,0.3) !important;
  padding: 6px 10px !important;
  margin-bottom: 4px !important;
}
.header-row {
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.header-row .row-col {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: relative;
}

/* Sort indicators ▲ ▼ */
.header-row .row-col.sorted-asc::after {
  content: "▲";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  opacity: 0.7;
}

.header-row .row-col.sorted-desc::after {
  content: "▼";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6rem;
  opacity: 0.7;
}

/* Last seen: don’t truncate internally, JS already trims text */
.system-row .seen {
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
}

/* Empty message style */
.empty-message {
  padding: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* FINAL FIX: enforce vertical-first card stacking */
.card-list {
    display: grid !important;
    grid-auto-flow: row !important;
    grid-auto-rows: max-content !important;
}

/* Status colouring for LIST VIEW */
.row-col.status.status-green {
  color: #22c55e !important; /* green */
  font-weight: 600;
}

.row-col.status.status-amber {
  color: #facc15 !important; /* amber */
  font-weight: 600;
}

.row-col.status.status-red {
  color: #ef4444 !important; /* red */
  font-weight: 600;
}
/* Row-wide status colouring */
.system-row.green {
  color: #38d764;
}

.system-row.amber {
  color: #facc15;
}

.system-row.red {
  color: #ef4444;
}

/* ============================================================
   LIGHT MODE — STATUS COLOURS (FINAL FIX)
   ============================================================ */

/* Base list text */
body.theme-light .system-row {
  color: #0f2a44;
  border-bottom: 1px solid rgba(15, 23, 42, 0.07);
}

body.theme-light .system-row:hover {
  background: rgba(30, 64, 175, 0.05) !important;
}

/* Light mode: selected must beat all status-background overrides.
   The double-selector covers both the base rule and the .card-list.list-view context. */
body.theme-light .system-row.selected,
body.theme-light .card-list.list-view .system-row.selected {
  background: var(--row-selected-bg) !important;
  border-left: 4px solid var(--row-selected-rail) !important;
  border-bottom-color: var(--row-selected-border) !important;
  box-shadow: var(--row-selected-shadow), inset 0 0 0 1px var(--row-selected-border);
  transform: translateX(2px);
  z-index: 1;
}

/* Per-status overrides: these have higher specificity than the rule above,
   so they must be listed explicitly to keep selected state winning. */
body.theme-light .card-list.list-view .system-row.green.selected,
body.theme-light .card-list.list-view .system-row.amber.selected,
body.theme-light .card-list.list-view .system-row.red.selected {
  background: var(--row-selected-bg) !important;
  border-left: 4px solid var(--row-selected-rail) !important;
}

body.theme-light .system-row.selected:hover,
body.theme-light .card-list.list-view .system-row.selected:hover {
  background: var(--row-selected-bg-hover) !important;
  box-shadow: var(--row-selected-shadow-hover), inset 0 0 0 1px var(--row-selected-border-hover);
}

/* Status colours with subtle tinted backgrounds */
body.theme-light .system-row.green {
  color: #166534 !important;
  background: rgba(34, 197, 94, 0.04) !important;
  border-left: 3px solid #22c55e;
}

body.theme-light .system-row.amber {
  color: #92400e !important;
  background: rgba(245, 158, 11, 0.05) !important;
  border-left: 3px solid #facc15;
}

body.theme-light .system-row.red {
  color: #991b1b !important;
  background: rgba(239, 68, 68, 0.05) !important;
  border-left: 3px solid #ef4444;
}

/* Header stays neutral */
body.theme-light .header-row {
  color: #475569 !important;
}

.metric-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

/* ===========================
   Pending Uninstall State
   =========================== */

.system.pending-uninstall,
.system-row.pending-uninstall,
.card.pending-uninstall {
    opacity: 0.65;
    border-left: 6px solid #f59e0b; /* amber */
    position: relative;
}

.system.pending-uninstall::after,
.system-row.pending-uninstall::after,
.card.pending-uninstall::after {
    content: "PENDING UNINSTALL";
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #b45309;
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
}

.system-row.pending-uninstall::after {
    content: attr(data-uninstall);
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 11px;
    font-weight: 700;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 2px 6px;
    border-radius: 4px;
}

.system-row.pending-uninstall[data-uninstall="ready"] {
    border-left-color: #dc2626; /* red */
}

/* =====================================================
   LIGHT MODE — CARD LIST REFINEMENT
   ===================================================== */

body.theme-light .system-row {
    background: #ffffff;
}

body.theme-light .system-row:hover {
    background: rgba(37, 99, 235, 0.06) !important;
}

body.theme-light .card-list.list-view .system-row.amber {
    background: #fffbeb !important; /* amber-50 */
    color: #92400e !important;      /* amber-800 text */
    border-left: 4px solid #f59e0b; /* amber-500 */
}
body.theme-light .card-list.list-view .system-row.red {
    background: #fef2f2 !important; /* red-50 */
    color: #7f1d1d !important;      /* red-800 text */
    border-left: 4px solid #ef4444; /* red-500 */
}
body.theme-light .card-list.list-view .system-row.green {
    background: #f0fdf4 !important; /* green-50 */
    color: #14532d !important;      /* green-900 text */
    border-left: 4px solid #22c55e; /* green-500 */
}
.metric-dot.green { background: #22c55e; }
.metric-dot.amber { background: #f59e0b; }
.metric-dot.red   { background: #ef4444; }

/* ============================================================
   CARD / ROW FADE-IN ON RENDER
   ============================================================ */

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

.system-card {
  animation: cardFadeIn 0.12s ease both;
}

.system-row:not(.header-row) {
  animation: cardFadeIn 0.10s ease both;
}

/* ============================================================
   CRITICAL CARD — SUBTLE PULSE ON LEFT BORDER
   ============================================================ */

@keyframes criticalPulse {
  0%, 100% { border-left-color: #ef4444; }
  50%       { border-left-color: rgba(239, 68, 68, 0.35); }
}

.system-card.red {
  animation: criticalPulse 2.2s ease-in-out infinite, cardFadeIn 0.12s ease both;
}
