:root {
  --bg: #070809;
  --surface: #0d0f12;
  --surface-2: #12151a;
  --surface-3: #171b21;
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.16);
  --text: #f2f4f7;
  --muted: #8d96a3;
  --muted-2: #626b78;
  --accent: #e8eaed;
  --danger: #ff5d69;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  letter-spacing: 0;
}

body.welcome-mode {
  display: block;
}

body.welcome-mode .sidebar,
body.welcome-mode .app {
  display: none;
}

body.app-mode .welcome-screen {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #090a0c;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #111419;
  color: var(--text);
  font-weight: 900;
  overflow: hidden;
}

.brand-mark img,
.brand-mark span {
  width: 100%;
  height: 100%;
}

.brand-mark img {
  display: block;
  object-fit: cover;
}

.brand-mark span {
  display: none;
  place-items: center;
}

.brand-mark.large {
  width: 58px;
  height: 58px;
  border-radius: 16px;
}

.brand strong {
  display: block;
  font-size: 14px;
}

.brand span {
  display: block;
  color: var(--muted-2);
  font-size: 12px;
  margin-top: 2px;
}

.welcome-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.08), transparent 30%),
    linear-gradient(135deg, #050607 0%, #0b0d10 48%, #11141a 100%);
  padding: 42px;
}

.welcome-shell {
  width: min(960px, 100%);
  margin: auto;
  display: grid;
  gap: 34px;
}

.welcome-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.eyebrow {
  display: block;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.welcome-brand h1 {
  max-width: 720px;
  font-size: clamp(38px, 7vw, 74px);
}

.welcome-brand p {
  max-width: 580px;
  margin-top: 12px;
  font-size: 15px;
}

.welcome-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.welcome-card {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
  color: var(--text);
  cursor: pointer;
  padding: 24px;
  text-align: left;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.welcome-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,.26);
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
}

.welcome-card span {
  display: inline-flex;
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: 36px;
}

.welcome-card strong {
  display: block;
  font-size: 28px;
  line-height: 1.08;
}

.welcome-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-top: 10px;
}

.welcome-screen footer {
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  padding-top: 24px;
}

nav {
  display: grid;
  gap: 6px;
}

.nav-btn,
.btn,
.icon-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
}

.nav-btn:hover,
.nav-btn.active {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--text);
}

.btn {
  min-height: 38px;
  padding: 9px 13px;
}

.btn:hover,
.icon-btn:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.btn.primary {
  background: var(--text);
  color: #08090b;
  border-color: var(--text);
}

.btn.primary:hover {
  background: #ffffff;
}

.btn.loading,
.btn:disabled {
  cursor: wait;
  opacity: .68;
}

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

.btn.danger {
  color: #ffd9dd;
  border-color: rgba(255,93,105,.35);
  background: rgba(255,93,105,.08);
}

.app {
  min-width: 0;
  padding: 30px;
}

.topbar,
.library-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.launcher-switcher {
  display: grid;
  gap: 5px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.launcher-switcher select {
  min-width: 180px;
  height: 38px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.08;
}

h2 {
  font-size: 20px;
  line-height: 1.18;
}

h3 {
  font-size: 16px;
  line-height: 1.2;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.tab { display: none; }
.tab.active { display: grid; gap: 18px; }

.disabled-panel {
  display: none;
}

.panel,
.modal {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.36);
}

.panel {
  padding: 18px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.add-instance-card {
  min-height: 164px;
  border: 1px dashed rgba(255,255,255,.28);
  border-radius: 14px;
  background: rgba(255,255,255,.015);
  color: var(--text);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 22px;
  cursor: pointer;
  text-align: center;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}

.add-instance-card:hover {
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.46);
  transform: translateY(-2px);
}

.add-instance-card .plus {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 30px;
  line-height: 1;
}

.add-instance-card small {
  max-width: 190px;
  color: var(--muted-2);
  line-height: 1.4;
}

.card,
.instance-card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  min-width: 0;
}

.card {
  padding: 14px;
}

.news-admin-card {
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.news-admin-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.news-admin-image {
  height: 128px;
  margin: -14px -14px 12px;
  border-bottom: 1px solid var(--line);
  background-size: cover;
  background-position: center;
}

.instance-card {
  min-height: 164px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  align-items: center;
  gap: 12px;
  padding: 18px;
  background-size: cover;
  background-position: center;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.instance-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.instance-card.empty::before {
  content: "Bridge";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.14);
  font-size: 26px;
  font-weight: 900;
}

.status-dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #8d96a3;
  box-shadow: 0 0 0 4px rgba(0,0,0,.34);
  z-index: 3;
}

.status-dot.published { background: #7ee787; }
.status-dot.draft { background: #f2cc60; }
.status-dot.archived { background: #8d96a3; }

.instance-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(8,9,11,.9), rgba(8,9,11,.62) 58%, rgba(8,9,11,.2)),
    linear-gradient(180deg, rgba(8,9,11,.24), rgba(8,9,11,.78));
  z-index: 1;
}

.instance-body {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 10px;
  align-content: center;
  min-width: 0;
}

.instance-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.instance-title-row h3,
.card h3 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instance-body p,
.card p {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.instance-avatar {
  position: relative;
  z-index: 2;
  width: 118px;
  height: 118px;
  justify-self: end;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  background-color: rgba(255,255,255,.06);
  box-shadow: 0 16px 34px rgba(0,0,0,.28);
}

.instance-avatar.empty::before {
  content: "";
  position: absolute;
  inset: 34px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 50%;
}

.meta {
  color: var(--muted-2);
  font-size: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: #cfd5dd;
  background: rgba(255,255,255,.035);
  font-size: 12px;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #c9d0d8;
  font-size: 13px;
  font-weight: 700;
}

.wide { grid-column: 1 / -1; }

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  background: #090b0e;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(255,255,255,.3);
}

textarea { resize: vertical; }

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.section-head h3 {
  margin-bottom: 4px;
}

.file-manager {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  padding: 14px;
}

.file-upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
}

.update-panel {
  display: grid;
  gap: 16px;
}

.update-drop {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px) auto;
  gap: 12px;
  align-items: end;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  padding: 16px;
  background: rgba(255,255,255,.025);
}

.update-url-box {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-2);
}

.update-url-box span {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.update-url-box code,
.update-file-row code {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.update-file-row > div {
  display: grid;
  gap: 4px;
}

.file-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 250px;
  overflow: auto;
  padding-right: 4px;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0,0,0,.18);
  padding: 10px;
}

.file-row strong,
.file-row span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row span {
  color: var(--muted-2);
  font-size: 12px;
  margin-top: 3px;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted-2);
  padding: 14px;
  text-align: center;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.spacer { flex: 1; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: min(1220px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  padding: 18px;
}

.access-modal {
  width: min(430px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0,0,0,.58);
  padding: 18px;
}

.access-modal > p {
  margin-bottom: 16px;
}

.access-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
  margin-top: 8px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  display: block;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.editor-hero {
  position: relative;
  min-height: 138px;
  display: flex;
  align-items: end;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: #111419;
  background-size: cover;
  background-position: center;
  overflow: hidden;
  padding: 18px;
  margin-bottom: 14px;
}

.editor-hero.empty::before {
  content: "Bridge Admin";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.1);
  font-weight: 900;
  font-size: 32px;
}

.editor-hero-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.08), rgba(0,0,0,.82));
  z-index: 1;
}

.editor-avatar {
  position: relative;
  z-index: 2;
  width: 58px;
  height: 58px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background-color: rgba(255,255,255,.07);
  background-size: cover;
  background-position: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  flex: 0 0 auto;
}

.editor-avatar.empty::before {
  content: "";
  position: absolute;
  inset: 17px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 50%;
}

.editor-hero-copy {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.editor-hero-copy h2 {
  font-size: 22px;
  margin-bottom: 4px;
}

.editor-layout {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr) 180px;
  gap: 14px;
  align-items: start;
}

.editor-nav {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.editor-nav-btn {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  padding: 10px;
  text-align: left;
}

.editor-nav-btn:hover,
.editor-nav-btn.active {
  background: var(--surface-3);
  color: var(--text);
}

.editor-main {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.editor-section {
  display: none;
}

.editor-section.active {
  display: block;
}

.editor-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  padding: 14px;
}

.form-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.media-list {
  display: grid;
  gap: 12px;
}

.media-row {
  display: grid;
  grid-template-columns: 120px 58px auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.media-row:last-child {
  border-bottom: 0;
}

.media-row > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.media-preview {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background-color: rgba(255,255,255,.06);
  background-size: cover;
  background-position: center;
  position: relative;
}

.media-preview.wide-preview {
  width: 58px;
}

.media-preview.empty::before {
  content: "";
  position: absolute;
  inset: 13px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 50%;
}

.hidden-file {
  display: none;
}

.editor-stats {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  padding: 14px;
  display: grid;
  gap: 18px;
}

.editor-stats span {
  display: block;
  color: var(--muted-2);
  font-size: 12px;
  margin-bottom: 4px;
}

.editor-stats strong {
  display: block;
  color: var(--text);
  font-size: 15px;
}

.editor-actions {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  background: #111419;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .2s ease;
  z-index: 30;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-btn {
    text-align: center;
  }

  .app {
    padding: 20px;
  }

  .topbar,
  .library-head {
    align-items: stretch;
    flex-direction: column;
  }

  .welcome-screen {
    padding: 24px;
  }

  .welcome-brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .welcome-options {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .file-upload-row {
    grid-template-columns: 1fr;
  }

  .update-drop {
    grid-template-columns: 1fr;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .editor-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .editor-nav-btn {
    text-align: center;
  }

  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .media-row {
    grid-template-columns: 1fr 58px auto auto;
  }
}

@media (max-width: 520px) {
  nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .instance-card {
    grid-template-columns: 1fr;
  }

  .instance-avatar {
    justify-self: start;
    width: 86px;
    height: 86px;
  }

  .modal-backdrop {
    padding: 12px;
  }
}
