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

:root {
  --list-col-template:
    200px   /* Company */
    280px   /* Description */
    220px   /* Hostname */
    200px   /* User */
    160px   /* Last Seen */
    120px;  /* Status */
}


/* 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(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  cursor: pointer;

  display: flex;
  flex-direction: row;

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

.system-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

.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: 6px 10px;
  background: transparent !important;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  border-radius: 0 !important;
  cursor: pointer;
  font-size: 0.78rem; /* ~80% size */
}

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

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

.system-row.selected {
  background: rgba(34,197,94,0.15) !important;
  border-bottom-color: var(--accent-blue);
}

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

/* 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(0,0,0,0.18);
}

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

/* Status colours */
body.theme-light .system-row.green {
  color: #166534 !important;
  border-left: 4px solid #22c55e;
}

body.theme-light .system-row.amber {
  color: #92400e !important;
  border-left: 4px solid #facc15;
}

body.theme-light .system-row.red {
  color: #991b1b !important;
  border-left: 4px 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; }
