:root {
  --bg: #080a0f;
  --sidebar: #0d1017;
  --panel: #111620;
  --panel-2: #151b26;
  --line: #272f3d;
  --line-2: #333c4d;
  --text: #f5f6fa;
  --muted: #939dad;
  --accent: #7c57ff;
  --accent-hover: #906fff;
  --danger: #ff5d78;
  --grid-min: 300px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 70% -20%, rgba(124,87,255,.12), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

.sidebar {
  min-height: 100vh;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 22px 14px;
  border-right: 1px solid var(--line);
  background: rgba(13,16,23,.96);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 2px 8px 27px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, #6741ff, #a86aff);
  box-shadow: 0 8px 25px rgba(124,87,255,.22);
}

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

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

.side-link {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 5px;
  background: transparent;
  color: #b8c0cd;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
}

.side-link:hover,
.side-link.active {
  color: white;
  background: #191e29;
}

.sidebar-bottom {
  margin-top: auto;
}

.sidebar-bottom small {
  color: #687283;
  display: block;
  padding: 8px 10px 0;
  line-height: 1.4;
}

.main {
  min-width: 0;
  padding: 34px clamp(18px, 4vw, 54px) 60px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.top h1 {
  font-size: clamp(28px, 3vw, 38px);
  margin: 0;
  letter-spacing: -.03em;
}

.top p {
  margin: 7px 0 0;
  color: var(--muted);
}

.btn {
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 11px 15px;
  cursor: pointer;
  font-weight: 750;
  color: white;
  transition: background .15s, border .15s, transform .15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: #171d28;
  border-color: var(--line);
}

.btn.secondary:hover {
  border-color: #414b5e;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 11px;
  margin-top: 28px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0e1219;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 12px;
}

.search-wrap span {
  color: #788395;
  font-size: 20px;
}

.search-wrap input {
  width: 100%;
  padding: 12px 0;
  border: 0;
  outline: 0;
  color: white;
  background: transparent;
}

.toolbar select {
  min-width: 145px;
  color: #d7dce5;
  background: #0e1219;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0 12px;
  outline: none;
}

.grid-control {
  display: grid;
  grid-template-columns: 38px 58px 38px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0e1219;
}

.grid-control button {
  align-self: stretch;
  border: 0;
  color: white;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}

.grid-control button:hover {
  background: #1a202b;
}

.grid-control span {
  text-align: center;
  color: #aeb6c4;
  font-size: 12px;
}

.summary {
  display: flex;
  gap: 20px;
  margin: 18px 0 23px;
  color: #8791a1;
  font-size: 13px;
}

.summary strong {
  color: #dce1e9;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--grid-min)), 1fr));
  gap: 17px;
  align-items: start;
}

.card {
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #151b26, #10151e);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 35px rgba(0,0,0,.14);
}

.card-image {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #090c11;
  color: #5e6878;
  cursor: pointer;
}

.card-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.card-body {
  padding: 14px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  justify-content: space-between;
}

.card-title {
  min-width: 0;
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  text-transform: uppercase;
}

.favorite {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #697486;
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
  padding: 0 1px;
}

.favorite.on {
  color: #ffd464;
}

.keyword-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.keyword {
  max-width: 100%;
  border: 1px solid #323a4a;
  background: #0c1017;
  color: #aab3c1;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-preview {
  color: #ccd2dc;
  line-height: 1.48;
  font-size: 13px;
  margin: 8px 0 14px;

  /* Texto normal no card, com reticências. */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;

  min-height: calc(1.48em * 2);
  cursor: pointer;
}

.card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 7px;
}

.card-actions button {
  min-width: 0;
}

.small-btn {
  border: 1px solid var(--line);
  color: #bac2cf;
  background: #121722;
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
}

.small-btn:hover {
  border-color: #414b5e;
}

.delete-btn {
  color: var(--danger);
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  border: 1px dashed #293141;
  border-radius: 16px;
  background: rgba(16,21,30,.45);
}

.empty h3 {
  margin: 0 0 7px;
  color: #cbd1dc;
}

dialog {
  width: min(650px, calc(100vw - 28px));
  max-height: calc(100vh - 30px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: white;
  background: #10151e;
  box-shadow: 0 30px 90px rgba(0,0,0,.6);
}

dialog::backdrop {
  background: rgba(0,0,0,.76);
  backdrop-filter: blur(4px);
}

#promptForm,
.viewer-content {
  padding: 20px;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.modal-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  border: 0;
  color: #8994a4;
  background: transparent;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}

#promptForm label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #cbd1db;
  font-size: 13px;
  font-weight: 700;
}

#promptForm label small {
  color: #758092;
  font-size: 11px;
  font-weight: 500;
}

#promptForm input,
#promptForm textarea {
  width: 100%;
  color: white;
  outline: none;
  border: 1px solid var(--line);
  background: #0a0e14;
  border-radius: 10px;
  padding: 11px 12px;
}

#promptForm input:focus,
#promptForm textarea:focus {
  border-color: var(--accent);
}

#promptForm textarea {
  min-height: 180px;
  resize: vertical;
}

.preview {
  min-height: 150px;
  max-height: 300px;
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: -3px 0 14px;
  border-radius: 11px;
  border: 1px dashed #343d4f;
  background: #0a0e14;
  color: #6f7a8b;
}

.preview img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.modal-actions,
.viewer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 8px;
}

.viewer-image {
  display: none;
  width: 100%;
  max-height: 430px;
  object-fit: contain;
  background: #090c11;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.viewer-prompt {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 12px 0 18px;
  line-height: 1.55;
  color: #d9dee7;
  background: #0b0f15;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 14px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  border: 1px solid var(--line);
  background: #181e29;
  color: white;
  border-radius: 11px;
  padding: 11px 15px;
  box-shadow: 0 12px 45px rgba(0,0,0,.3);
  transition: .18s ease;
}

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

@media (max-width: 800px) {
  body {
    display: block;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-bottom {
    margin-top: 15px;
  }

  .top {
    align-items: stretch;
    flex-direction: column;
  }

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

  .toolbar select {
    min-height: 44px;
  }

  .grid-control {
    width: 134px;
    min-height: 42px;
  }
}

[hidden] { display: none !important; }

.repo-toolbar { grid-template-columns: minmax(220px, 1fr); }

.repo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 17px;
  align-items: start;
}

.repo-card {
  background: linear-gradient(180deg, #151b26, #10151e);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  min-width: 0;
}

.repo-card h3 { margin: 0; font-size: 17px; }

.repo-filename {
  margin-top: 7px;
  color: #7f8a9b;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-description-text {
  margin: 12px 0;
  color: #cbd1db;
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.repo-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #788395;
  font-size: 11px;
  margin: 12px 0;
}

.repo-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.repo-actions a {
  text-align: center;
  text-decoration: none;
}

.file-info {
  border: 1px dashed #343d4f;
  background: #0a0e14;
  color: #8792a3;
  border-radius: 10px;
  padding: 11px 12px;
  margin: -3px 0 14px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.repo-description { min-height: 100px !important; }


/* =========================================
   CORREÇÃO DO FORMULÁRIO DE REPOSITÓRIOS
   ========================================= */

#repoEditor {
  width: min(720px, calc(100vw - 28px));
}

#repoForm {
  padding: 22px;
}

#repoForm .modal-head {
  margin-bottom: 20px;
}

#repoForm label {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: #cbd1db;
  font-size: 13px;
  font-weight: 700;
}

#repoForm label small {
  color: #758092;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
}

#repoForm input,
#repoForm textarea {
  width: 100%;
  min-width: 0;
  color: white;
  outline: none;
  border: 1px solid var(--line);
  background: #0a0e14;
  border-radius: 10px;
  padding: 11px 12px;
}

#repoForm input:focus,
#repoForm textarea:focus {
  border-color: var(--accent);
}

#repoForm input[type="file"] {
  padding: 9px;
  cursor: pointer;
}

#repoForm input[type="file"]::file-selector-button {
  border: 1px solid #343d4f;
  background: #171d28;
  color: white;
  border-radius: 8px;
  padding: 8px 11px;
  margin-right: 10px;
  cursor: pointer;
}

#repoForm input[type="file"]::file-selector-button:hover {
  border-color: #4a556b;
}

#repoForm .repo-description {
  min-height: 120px !important;
  resize: vertical;
}

#repoForm .file-info {
  margin: -3px 0 17px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

#repoForm .modal-actions {
  margin-top: 3px;
}

/* Nome + palavras-chave em duas colunas em telas maiores */
#repoForm {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 14px;
}

#repoForm .modal-head,
#repoForm label:nth-of-type(3),
#repoForm label:nth-of-type(4),
#repoForm .file-info,
#repoForm .modal-actions {
  grid-column: 1 / -1;
}

#repoForm label:nth-of-type(1),
#repoForm label:nth-of-type(2) {
  grid-column: auto;
}

@media (max-width: 620px) {
  #repoEditor {
    width: min(96vw, 720px);
  }

  #repoForm {
    display: block;
    padding: 18px;
  }

  #repoForm .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  #repoForm .modal-actions .btn {
    width: 100%;
  }
}


/* =========================================
   MODO EDIÇÃO / LOGIN
   ========================================= */

.edit-mode-button {
  border: 1px solid #343d4d;
  background: #121722;
  margin-bottom: 7px;
}

.edit-mode-button:hover {
  border-color: #4a566d;
}

.edit-mode-button.unlocked {
  color: #d7fff0;
  border-color: #285c49;
  background: #10251d;
}

.card-actions.view-only,
.repo-actions.view-only {
  grid-template-columns: 1fr;
}

.favorite-readonly {
  cursor: default;
  display: inline-block;
  padding: 0 1px;
}

.login-dialog {
  width: min(430px, calc(100vw - 28px));
}

#loginForm {
  padding: 24px;
}

.login-lock {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin: 2px auto 14px;
  border-radius: 15px;
  background: #171d28;
  border: 1px solid var(--line);
  font-size: 24px;
}

#loginForm h2 {
  text-align: center;
  margin: 0;
  font-size: 23px;
}

#loginForm > p {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin: 7px auto 20px;
  max-width: 320px;
}

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

#loginForm input {
  width: 100%;
  color: white;
  outline: none;
  border: 1px solid var(--line);
  background: #0a0e14;
  border-radius: 10px;
  padding: 12px;
}

#loginForm input:focus {
  border-color: var(--accent);
}

.login-error {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid #5a2833;
  background: #281218;
  color: #ff9bac;
  font-size: 12px;
}

#loginForm .modal-actions {
  margin-top: 17px;
}
