/* ---------- Theme Variables ---------- */
:root {
  --bg1: #0b1f3a;
  --bg2: #0b2c5a;
  --card: #0f2748;
  --card-soft: #12284a;
  --text: #e6eefc;
  --muted: #9fb3d9;
  --accent: #6aa0ff;
  --accent-soft: rgba(106, 160, 255, 0.2);
  --danger: #ff6b6b;
  --ok: #55d48a;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.15);

  --rail-w: 260px;
  --rail-size: var(--rail-w); /* overridden when collapsed */
}

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

html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top left, #172a46 0, var(--bg1) 40%, var(--bg2) 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;

  display: grid;
  grid-template-columns: var(--rail-size) 1fr;
  grid-template-rows: auto 1fr;
  transition: grid-template-columns 0.25s ease;
}

/* Global links */
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Utility classes */
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
  font-size: 12px;
}
.row {
  margin: 10px 0;
}

/* ---------- Header ---------- */
header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(9px);
  background: linear-gradient(135deg, rgba(11, 31, 58, 0.96), rgba(11, 44, 90, 0.96));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* Brand (logo) */
header .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
header .brand img {
  display: block;
  height: 46px;
  width: auto;
}

/* Menu toggle */
#menuToggle.icon {
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#menuToggle.icon:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Account Area (top-right) ---------- */
.account-area {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 12px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  box-shadow: none;
}
.account-btn i.fa-user-circle {
  font-size: 16px;
}
.account-btn .acct-name {
  max-width: 140px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.account-btn .caret {
  font-size: 10px;
  opacity: 0.7;
}

/* Dropdown menu */
.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #06132a;
  border-radius: 10px;
  min-width: 180px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 100;
}
.account-menu .menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border-radius: 8px;
  border: 0;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  box-shadow: none;
}
.account-menu .menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Buttons ---------- */
button {
  background: var(--accent);
  color: #061229;
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.08s ease, box-shadow 0.2s ease;
}
button:hover {
  opacity: 0.96;
  transform: translateY(-1px);
}
button:active {
  transform: translateY(0);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0.3);
}
button.secondary {
  background: #1f3e73;
  color: #dfe9ff;
}
button.danger {
  background: var(--danger);
  color: #fff;
}
button.small {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: none;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Inputs ---------- */
input {
  background: #0b1f3a;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  font-size: 13px;
}
input::placeholder {
  color: rgba(159, 179, 217, 0.8);
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(106, 160, 255, 0.7);
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.chk input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* ---------- Cards & Panels ---------- */
.panel {
  padding: 18px 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* Generic card media */
.card img {
  width: 100%;
  height: auto;
  display: block;
}

/* Upload panel tweaks when centered */
.panel form#uploadForm {
  background: rgba(6, 15, 32, 0.7);
  border-radius: 18px;
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------- Auth Gate ---------- */
#auth {
  padding: 28px 18px;
}
#auth .card {
  background: rgba(10, 24, 52, 0.96);
}
#auth h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

/* ---------- Grid / Library Layout ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 18px 22px;
}

/* Uniform card layout for banners */
.grid.uniform {
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.grid.uniform .card {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.grid.uniform .card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: radial-gradient(circle at top, #1f3e73 0, #0b1f3a 60%, #020617 100%);
  display: block;
  position: relative;
}
.grid.uniform .card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Meta + actions inside card */
.card .meta {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
}
.card .url {
  margin: 6px 0 4px;
  word-break: break-all;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #153766;
  color: #dbe7ff;
  padding: 4px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-right: 6px;
}
.badge + .badge {
  margin-top: 2px;
}

/* Action row (buttons) */
.actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
}

/* ---------- Sidebar / Rail ---------- */
.rail {
  grid-row: 2;
  overflow: auto;
  padding: 16px;
  background: radial-gradient(circle at top left, #102347 0, #081324 55%, #020617 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  height: calc(100vh - 52px);
  will-change: transform, opacity;
  transition: transform 0.25s ease, opacity 0.25s ease;
  min-width: 0;
}

/* Rail header & sections */
.rail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.rail-header i {
  color: var(--accent);
}

.rail-section + .rail-section {
  margin-top: 18px;
}

.rail-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.rail-title i {
  font-size: 12px;
}

/* List items (projects, categories) */
.rail-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rail-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease;
}
.rail-list li i {
  font-size: 13px;
  opacity: 0.85;
}
.rail-list li:hover {
  background: rgba(15, 39, 72, 0.95);
}

/* Full-width buttons in rail */
.rail-btn {
  width: 100%;
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 600;
  margin-top: 6px;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.rail-btn i {
  font-size: 13px;
}
.rail-btn:hover {
  background: rgba(106, 160, 255, 0.32);
}

/* Collapsed sidebar */
body.rail-collapsed {
  --rail-size: 0px;
}
body.rail-collapsed .rail {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* ---------- Main content ---------- */
#main {
  grid-row: 2;
  overflow: auto;
  padding: 16px 14px 20px;
  min-width: 0;
}

/* Filters strip */
.filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 22px 4px;
}
.filters span#activeFilter {
  font-size: 12px;
}

/* ---------- Detail View ---------- */
#detail {
  padding: 10px 18px 20px;
}
#detail h2 {
  font-size: 18px;
  margin: 0 0 10px;
}
#detail .grid {
  padding: 0;
  gap: 18px;
}

/* Make the right-hand detail card slightly softer */
#detail .card:nth-child(2) {
  background: var(--card-soft);
}

/* ---------- Dialog / Embed Modal ---------- */
dialog {
  border: 0;
  border-radius: 18px;
  padding: 18px 20px 16px;
  background: #020617;
  color: var(--text);
  max-width: 720px;
  width: min(720px, 100% - 32px);
}
dialog h3 {
  margin-top: 0;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

pre.code {
  background: #020617;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 10px;
  overflow: auto;
  max-height: 40vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

/* ---------- Responsive Tweaks ---------- */
@media (max-width: 960px) {
  body {
    --rail-size: 0px;
  }
  body:not(.rail-collapsed) {
    --rail-size: var(--rail-w);
  }

  header {
    padding-inline: 12px;
  }

  #main {
    padding-inline: 10px;
  }

  .panel form#uploadForm {
    margin-inline: 6px;
  }
}

@media (max-width: 640px) {
  .panel form#uploadForm {
    padding: 12px 10px;
    border-radius: 14px;
  }

  .filters {
    margin-inline: 14px;
    flex-direction: column;
    align-items: flex-start;
  }

  dialog {
    width: calc(100% - 24px);
    padding-inline: 14px;
  }
}