:root {
  --bg: #0f1117;
  --bg-elevated: #181b24;
  --bg-card: #1e2230;
  --border: #2a3042;
  --text: #e8eaef;
  --text-muted: #8b93a8;
  --accent: #6c8cff;
  --accent-hover: #849cff;
  --accent-dim: rgba(108, 140, 255, 0.15);
  --danger: #f07178;
  --success: #7fd99a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --sidebar-w: 260px;
  --header-h: 72px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  min-height: var(--header-h);
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header__logo-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.btn--back {
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
}

.btn--back:hover {
  color: var(--text);
}

.btn--panel {
  display: none;
  flex-shrink: 0;
  text-decoration: none;
  white-space: nowrap;
}

.btn--panel.is-visible {
  display: inline-flex;
}

.header__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.search {
  flex: 1;
  max-width: 320px;
  min-width: 120px;
}

.search__input {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.search__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100dvh - var(--header-h));
}

.sidebar {
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100dvh - var(--header-h));
  overflow-y: auto;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sidebar__title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.folder-list,
.user-label-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar__section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.user-label-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.user-label-item:hover {
  background: rgba(127, 217, 154, 0.1);
}

.user-label-item.is-active {
  background: rgba(127, 217, 154, 0.18);
  color: var(--success);
  font-weight: 600;
}

.user-label-item__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--success);
}

.user-label-item__count {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tag--personal {
  background: rgba(127, 217, 154, 0.15);
  color: var(--success);
  border: 1px solid rgba(127, 217, 154, 0.35);
}

.user-label-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1.25rem 1rem;
}

.user-label-chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.user-label-chip.is-on {
  background: rgba(127, 217, 154, 0.2);
  border-color: var(--success);
  color: var(--success);
}

.modal__user-labels {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.modal__user-labels .field__label {
  padding: 0 1.25rem;
  margin-bottom: 0.5rem;
}

.user-logged-name {
  padding: 0 1.25rem;
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.user-registry {
  padding: 0 1.25rem 1rem;
}

.user-registry__list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.user-registry__list button {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.user-registry__list button:hover {
  border-color: var(--accent);
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.folder-item:hover {
  background: var(--accent-dim);
}

.folder-item.is-active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.folder-item__icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.folder-item__count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.main {
  padding: 1.25rem;
  min-width: 0;
}

.main__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.main__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.main__count {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Prompt cards */
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.prompt-card {
  display: flex;
  flex-direction: column;
  padding: 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.prompt-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.prompt-card__title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}

.prompt-card__desc {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.prompt-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.tag {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
}

.prompt-card__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

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

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

.btn--small {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn--danger:hover {
  background: rgba(240, 113, 120, 0.12);
  color: var(--danger);
}

.btn--block {
  width: 100%;
}

.btn__label {
  display: inline;
}

/* Modals */
.modal {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal--small {
  width: min(400px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  margin: 0;
  font-size: 1.1rem;
}

.modal__close {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal__close:hover {
  background: var(--bg-card);
  color: var(--text);
}

.modal__meta {
  padding: 0 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal__body {
  margin: 0;
  padding: 1rem 1.25rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 50vh;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.modal__form {
  display: flex;
  flex-direction: column;
}

.modal__form .field {
  padding: 0 1.25rem;
}

.modal__form .field:first-of-type {
  margin-top: 1rem;
}

.modal__hint {
  margin: 0;
  padding: 0 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.modal__footer--stack {
  flex-direction: column;
}

.modal__footer-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field__label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field input,
.field textarea {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--mono);
  font-size: 0.85rem;
}

.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.75rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 200;
  pointer-events: none;
}

.toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* FAB & mobile sidebar */
.fab {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 90;
}

.badge-public {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 4px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* Tablet */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: min(var(--sidebar-w), 85vw);
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-h);
    background: rgba(0, 0, 0, 0.5);
    z-index: 75;
  }

  .sidebar-overlay.is-visible {
    display: block;
  }

  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .btn__label--hide-mobile {
    display: none;
  }
}

/* Mobile */
@media (max-width: 600px) {
  :root {
    --header-h: auto;
  }

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

  .header__actions {
    flex-direction: column;
    width: 100%;
  }

  .btn--back {
    width: 100%;
    justify-content: center;
  }

  .search {
    max-width: none;
  }

  .header__logo-img {
    width: 40px;
    height: 40px;
  }

  .main {
    padding: 1rem;
  }

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

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

  .modal__footer-right {
    margin-left: 0;
    flex-direction: column;
  }

  .btn__label {
    display: none;
  }

  #btn-admin .btn__label,
  #btn-admin-panel {
    display: inline-flex;
  }

  #btn-admin-panel:not(.is-visible) {
    display: none !important;
  }
}

@media (min-width: 901px) {
  .fab {
    display: none !important;
  }
}
