:root {
  --bg: #04070a;
  --bg-soft: #0a0f16;
  --card: #0c1119;
  --card-hover: #101826;
  --border: #1c2b2a;
  --text: #d8f5e8;
  --muted: #6f8a86;
  --accent: #00e58e;
  --accent-2: #00c2ff;
  --accent-3: #ff2bd6;
  --danger: #ef4444;
  --warn: #f5a524;
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html { background: var(--bg); overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--mono);
  background:
    radial-gradient(900px 500px at 15% 110%, rgba(0,194,255,.05) 0%, transparent 60%),
    radial-gradient(1200px 600px at 70% -10%, #0d1a1c 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  position: relative;
}

/* ---------- Matrix rain background ---------- */
#matrix-rain {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: .22;
  pointer-events: none;
}

/* Faint CRT scanline overlay */
.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,255,170,.025) 3px,
    rgba(0,0,0,0) 4px
  );
  mix-blend-mode: overlay;
}

.muted { color: var(--muted); }

/* ---------- Window chrome (shared: shell + login card) ---------- */
.chrome-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.chrome-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chrome-dot.r { background: #ef4444; }
.chrome-dot.y { background: #f59e0b; }
.chrome-dot.g { background: #10b981; }
.chrome-label {
  margin-left: 8px;
  font-size: .75rem;
  color: var(--muted);
  letter-spacing: .02em;
}
.chrome-right {
  margin-left: auto;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- Page shell (whole app rendered as one terminal window) ---------- */
.term-shell {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: clamp(14px, 4vw, 36px) auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(9, 13, 19, .82);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  box-shadow:
    0 0 0 1px rgba(0,229,142,.07),
    0 40px 90px rgba(0,0,0,.6),
    0 0 70px rgba(0,229,142,.05);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 30px clamp(20px, 5vw, 56px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.prompt-line { margin: 0 0 6px; font-size: .8rem; }
.prompt-cmd { color: var(--accent-2); }

.topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: .01em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(0,229,142,.35));
}
.cursor {
  display: inline-block;
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Occasional RGB-split glitch flicker on the title */
.glitch { position: relative; display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  -webkit-text-fill-color: currentColor;
  background: none;
  overflow: hidden;
  opacity: 0;
}
.glitch::before { color: var(--accent-2); clip-path: inset(0 0 55% 0); animation: glitchTop 7s infinite linear; }
.glitch::after  { color: var(--accent-3); clip-path: inset(55% 0 0 0); animation: glitchBottom 7s infinite linear; }
@keyframes glitchTop {
  0%, 92%, 100% { opacity: 0; transform: translate(0, 0); }
  93% { opacity: .8; transform: translate(-3px, -1px); }
  95% { opacity: .5; transform: translate(2px, 1px); }
  96% { opacity: 0; }
}
@keyframes glitchBottom {
  0%, 93%, 100% { opacity: 0; transform: translate(0, 0); }
  94% { opacity: .7; transform: translate(3px, 1px); }
  96% { opacity: .4; transform: translate(-2px, 0); }
  97% { opacity: 0; }
}

.topbar p:not(.prompt-line) { margin: 8px 0 0; font-size: .9rem; }

.badges { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.badge {
  font-size: .66rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,.02);
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-green { color: var(--accent); border-color: rgba(0,229,142,.35); box-shadow: 0 0 10px rgba(0,229,142,.12); }
.badge-cyan  { color: var(--accent-2); border-color: rgba(0,194,255,.35); }

.topnav { display: flex; align-items: center; gap: 12px; }

.navlink, .logout {
  color: var(--text);
  text-decoration: none;
  font-size: .85rem;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.navlink:hover, .logout:hover { background: var(--bg-soft); border-color: var(--accent); box-shadow: 0 0 12px rgba(0,229,142,.25); }
.navlink { color: var(--accent-2); font-weight: 600; }

/* ---------- Flash alert ---------- */
.flash { margin: 20px clamp(20px, 5vw, 56px) 0; }

/* ---------- Grid ---------- */
.board { padding: clamp(24px, 5vw, 48px); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 26px;
}
.section-label {
  display: flex; align-items: center; gap: 10px;
  margin: 0 2px 16px;
  font-family: var(--mono);
  font-size: .72rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted);
}
.grid + .section-label { margin-top: 34px; }
.section-label::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--border), transparent); }
.section-label .sec-count {
  color: var(--accent); background: rgba(0,229,142,.1);
  border: 1px solid rgba(0,229,142,.3); border-radius: 20px;
  padding: 1px 8px; font-size: .68rem; letter-spacing: .04em;
}
.section-label.fav { color: #ffd24a; }
.section-label.fav .sec-star { color: #ffd24a; text-shadow: 0 0 8px rgba(255,210,74,.5); }
.section-label.fav .sec-count { color: #ffd24a; background: rgba(255,210,74,.1); border-color: rgba(255,210,74,.35); }

.card-wrap { position: relative; }

.card {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  text-decoration: none;
  color: inherit;
  transition: transform .15s ease, border-color .15s, background .15s, box-shadow .15s;
}
.card::before, .card::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  opacity: .45;
  transition: opacity .15s;
  pointer-events: none;
}
.card::before { top: 6px; left: 6px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.card::after  { bottom: 6px; right: 6px; border-bottom: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.card:hover::before, .card:hover::after { opacity: 1; }

.card:hover {
  transform: translateY(-4px);
  background: var(--card-hover);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(0,229,142,.3), 0 18px 38px rgba(0,0,0,.55), 0 0 30px rgba(0,229,142,.12);
}

.sweep {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 42%, rgba(0,229,142,.14) 50%, transparent 58%);
  transform: translateX(-130%);
  transition: transform .7s ease;
}
.card:hover .sweep { transform: translateX(130%); }

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

.tag-online {
  position: absolute;
  top: 8px; right: 8px;
  font-size: .6rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: rgba(4,7,10,.75);
  border: 1px solid rgba(0,229,142,.4);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.avatar {
  width: 64px; height: 64px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700; color: #04070a;
}

.card-body { padding: 16px 18px 18px; }
.card-body h2 { margin: 0 0 6px; font-size: 1rem; }
.card-body p  { margin: 0 0 12px; font-size: .85rem; line-height: 1.4; }

.link-host {
  font-size: .78rem;
  color: var(--accent-2);
  font-weight: 600;
  display: block;
}
.link-host::before { content: '$ open '; color: var(--muted); font-weight: 400; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px 1px rgba(0,229,142,.8);
  flex: none;
  display: inline-block;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ---------- Live status states ---------- */
.tag-online[data-status="warn"] { color: var(--warn); border-color: rgba(245,165,36,.5); }
.tag-online[data-status="warn"] .status-dot { background: var(--warn); box-shadow: 0 0 6px 1px rgba(245,165,36,.8); }
.tag-online[data-status="down"] { color: var(--danger); border-color: rgba(239,68,68,.5); }
.tag-online[data-status="down"] .status-dot { background: var(--danger); box-shadow: 0 0 6px 1px rgba(239,68,68,.8); animation: none; }
.tag-online[data-status="unknown"] { color: var(--muted); border-color: var(--border); }
.tag-online[data-status="unknown"] .status-dot { background: var(--muted); box-shadow: none; animation: none; }
.tag-online[data-status="local"] { color: var(--accent-2); border-color: rgba(0,194,255,.4); }
.tag-online[data-status="local"] .status-dot { background: var(--accent-2); box-shadow: 0 0 6px 1px rgba(0,194,255,.7); animation: none; }

/* ---------- Manage mode: per-card tools ---------- */
.card-tools {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  display: none; gap: 5px; align-items: center;
}
body.managing .card-tools { display: flex; }
.card-tools .tool-form { margin: 0; }
.tool-btn {
  width: 26px; height: 26px; line-height: 1;
  border-radius: 6px; border: 1px solid var(--border);
  background: rgba(4,7,10,.85); color: var(--muted);
  font-size: .95rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s, background .15s;
}
.tool-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: rgba(0,229,142,.12); }
.tool-btn:disabled { opacity: .3; cursor: default; }
.del-btn:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); background: rgba(239,68,68,.12); }

/* While managing, the card itself isn't a navigation target — tools take over. */
body.managing .card { pointer-events: none; }
body.managing .card-tools, body.managing .edit-panel { pointer-events: auto; }

/* ---------- Inline edit panel ---------- */
.edit-panel {
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 10px 10px;
  background: var(--bg-soft);
  margin-top: -6px;
}
.edit-panel .add-form { padding: 16px 16px 18px; }
.edit-actions { display: flex; gap: 8px; }
.edit-actions .btn-secondary {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.edit-actions .btn-secondary:hover { border-color: var(--accent); color: var(--accent); filter: none; }

/* ---------- Favorite star ---------- */
.fav-form { position: absolute; top: 8px; left: 8px; z-index: 3; margin: 0; }
.fav-btn {
  width: 28px; height: 28px; line-height: 1; padding: 0;
  border: none; border-radius: 8px;
  background: rgba(4,7,10,.55);
  color: #c9b45a; font-size: 1.05rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .15s, transform .15s, color .15s, background .15s;
}
.card-wrap:hover .fav-btn, .fav-btn:focus-visible { opacity: 1; }
.fav-btn:hover { transform: scale(1.12); background: rgba(4,7,10,.8); }
.card-wrap.is-fav .fav-btn { opacity: 1; color: #ffd24a; text-shadow: 0 0 10px rgba(255,210,74,.55); }
@media (hover: none) { .fav-btn { opacity: 1; } }

/* Favorited cards get a subtle gold edge so the top row reads as "pinned". */
.card-wrap.is-fav .card { border-color: rgba(255,210,74,.5); box-shadow: 0 0 0 1px rgba(255,210,74,.22), 0 0 22px rgba(255,210,74,.08); }

/* ---------- Add-app card ---------- */
.add-card {
  border: 1px dashed var(--border);
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  background: transparent;
  color: inherit;
}
.add-card summary {
  height: 100%;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  transition: color .15s, border-color .15s;
}
.add-card summary::-webkit-details-marker { display: none; }
.add-card:hover summary, .add-card[open] summary { color: var(--accent); }
.add-card:hover { border-color: var(--accent); }

.add-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.add-form {
  padding: 0 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.add-form label {
  display: block;
  font-size: .78rem;
  color: var(--muted);
}
.add-form input {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: .85rem;
}
.add-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,229,142,.15); }
.add-form button {
  padding: 10px;
  background: var(--accent);
  color: #04070a;
  border: none;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s;
}
.add-form button:hover { filter: brightness(1.1); }
.add-form .field-hint {
  display: block;
  margin-top: 6px;
  font-size: .68rem;
  color: var(--muted);
  font-family: var(--mono);
  line-height: 1.4;
}
.add-form input[type="file"] { padding: 7px 8px; cursor: pointer; }
.add-form input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: var(--mono);
  font-size: .78rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.add-form input[type="file"]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }

.foot {
  text-align: center;
  padding: 18px;
  font-size: .78rem;
  letter-spacing: .03em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.foot-sep { color: var(--border); }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: rgba(12,17,25,.9);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  text-align: left;
  box-shadow: 0 0 0 1px rgba(0,229,142,.08), 0 20px 60px rgba(0,0,0,.55), 0 0 60px rgba(0,229,142,.06);
}
.login-inner { padding: 30px 28px 34px; }
.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: .02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-card .muted { margin: 0 0 22px; font-size: .85rem; }
.login-card .prompt-line { font-size: .82rem; margin: 0 0 20px; }

.login-card label {
  display: block;
  text-align: left;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 14px;
}
.login-card input {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: .92rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,229,142,.15); }

.login-card button {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  background: var(--accent);
  color: #04070a;
  border: none;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: filter .15s;
}
.login-card button:hover { filter: brightness(1.1); }

.alert {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.4);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: .85rem;
  margin-bottom: 18px;
}

/* ---------- Fallback: solid title where background-clip:text is unsupported ---------- */
/* Without this, the transparent-filled gradient title renders invisible on
   browsers that don't support `background-clip: text` (some mobile engines). */
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .topbar h1, .login-card h1 {
    background: none;
    color: var(--accent);
    -webkit-text-fill-color: var(--accent);
  }
}

/* ---------- Responsive / mobile ---------- */
@media (max-width: 640px) {
  /* Full-bleed the terminal window so no space is wasted on small screens */
  .term-shell {
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Keep the chrome bar on one line; truncate the long path instead of pushing
     the "secure" badge off-screen */
  .chrome-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }

  /* Stack the header: title block on top, nav below as full-width buttons */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 22px 18px;
  }
  .topbar h1 { font-size: 1.5rem; overflow-wrap: anywhere; }
  .topnav { width: 100%; }
  .navlink, .logout { flex: 1; text-align: center; }

  .flash { margin: 16px 18px 0; }

  /* Single comfortable column of cards */
  .board { padding: 18px; }
  .grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .grid + .section-label { margin-top: 24px; }

  /* Roomier tap targets for the touch-only del/add controls */
  .del-btn { width: 30px; height: 30px; font-size: 1.15rem; }
  .add-card summary { min-height: 96px; }
}
