/* DVCS — base styles */
:root {
  --color-bg:         #f0f2f5;
  --color-surface:    #ffffff;
  --color-border:     #e2e8f0;
  --color-primary:    #3b82f6;
  --color-primary-dk: #2563eb;
  --color-danger:     #ef4444;
  --color-danger-dk:  #dc2626;
  --color-success:    #22c55e;
  --color-warning:    #f59e0b;
  --color-text:       #1e293b;
  --color-muted:      #64748b;
  --color-nav:        #0f172a;
  --color-nav-text:   #94a3b8;
  --color-accent:     #6366f1;
  --color-nav-hover:  #e2e8f0;
  --radius:           8px;
  --radius-lg:        12px;
  --shadow:           0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:        0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --transition:       0.2s ease;
}

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

html {
  overflow-x: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100%;
}

#app { min-height: 100vh; max-width: 100%; }

/* ── Navigation ── */
.nav {
  background: var(--color-nav);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.nav__brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: #ffffff;
  letter-spacing: -0.02em;
  margin-right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav__logo {
  height: 1.7em;
  width: auto;
  border-radius: 4px;
  vertical-align: middle;
}

.nav__link {
  color: var(--color-nav-text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.nav__link:hover {
  color: var(--color-nav-hover);
  background: rgba(255,255,255,0.08);
}

.nav__link--active {
  color: #ffffff;
  background: rgba(255,255,255,0.12);
}

.nav__right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav__team {
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 999px;
  white-space: nowrap;
}

/* ── Page ── */
.page {
  padding: 1.5rem 2rem;
  width: 100%;
}

.page__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: -0.02em;
}

/* ── Card ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card__title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text);
}

/* ── Table ── */
.table-scroll {
  width: 100%;
  /* Horizontal scroll is not needed (cells wrap); hiding it avoids phantom
     scrollbars from off-screen tooltip nodes. Vertical scroll drives
     infinite-scroll pagination via scrollTop / scrollHeight. */
  overflow-x: hidden;
  /* Vertical scroll container: enables infinite-scroll auto-loading.
     The list widgets listen for this element's `scroll` event and grow
     the visible window as the user nears the bottom. */
  overflow-y: auto;
  /* Cap the height so the table itself scrolls (rather than the whole page)
     and so a full page of rows always overflows — otherwise the inner
     `scroll` event never fires and infinite-scroll can't trigger. */
  max-height: min(calc(100vh - 220px), 620px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  background: var(--color-surface);
}

/* List pages (`page page--fill`) fill the viewport below the 56px nav and
   lay out as a column, so the table-scroll grows to reach the bottom of the
   screen instead of overflowing the page. Only the table scrolls. */
/* Inline yellow badge — kept for the "Bindings: 0" marker on the bundle page. */
.badge--warn {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  cursor: help;
  font-weight: 600;
}

/* Plain warning glyph (no fill) for table rows. `cursor:help` hints the native
   `title` tooltip; the surrounding row stays clickable. */
.warn-icon {
  color: #dc2626;
  cursor: help;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1;
  margin-left: 0.45rem;
}

.page--fill {
  height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
}

/* Don't grow (flex-grow 0) so a short list stays its natural height instead
   of stretching the last row; but allow shrinking (flex-shrink 1) with
   min-height 0 so a long list is capped to the remaining space and scrolls. */
.page--fill .table-scroll {
  flex: 0 1 auto;
  min-height: 0;
  max-height: none;
}

.table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  table-layout: auto;
}

.table-scroll .table {
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.table th,
.table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
  word-break: break-all;
}

.table th {
  font-weight: 600;
  background: #f8fafc;
  color: var(--color-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--color-border);
  position: sticky;
  top: 0;
}

.table td {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.78rem;
  color: var(--color-text);
}

.table-col--icon {
  width: 2.5rem;
  min-width: 2.5rem;
  max-width: 2.5rem;
  text-align: center;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
  overflow: hidden;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:nth-child(even) td {
  background: #fafbfc;
}

.table--clickable tbody tr {
  cursor: pointer;
  transition: background var(--transition);
}

.table--clickable tbody tr:hover td {
  background: #eff6ff !important;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--color-primary);
  color: #fff;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:hover {
  background: var(--color-primary-dk);
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

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

.btn--danger:hover {
  background: var(--color-danger-dk);
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

.btn--secondary {
  background: var(--color-accent);
  opacity: 0.8;
}

.btn--secondary:hover {
  opacity: 1;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}

.btn--ghost {
  background: transparent;
  color: var(--color-nav-text);
  border: 1px solid rgba(255,255,255,0.2);
}

.btn--ghost:hover {
  background: rgba(255,255,255,0.1);
  color: #ffffff;
  box-shadow: none;
  transform: none;
}

.btn--sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Role-selector buttons */
.btn--role {
  background: transparent;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn--role:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #eff6ff;
  box-shadow: none;
  transform: none;
}

.btn--role-active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn--role-active:hover {
  background: var(--color-primary-dk);
  color: #fff;
}

/* ── Forms ── */
.form__group {
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

.form__label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}

.form__hint {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 0.25rem;
}

.form__input,
.form__select,
.form__textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.55rem 0.85rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form__input::placeholder {
  color: #94a3b8;
}

/* Unify all native dropdowns: hide the OS arrow and draw our own, so the
   gitea / org / repo / bundle pickers all share one look. */
.form__select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 0.7rem;
  cursor: pointer;
}

.form__input:focus,
.form__select:focus,
.form__textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Login ── */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.login__box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 380px;
}

.login__title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
  letter-spacing: -0.02em;
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #e0e7ff;
  color: #3730a3;
}

.badge--green  { background: #dcfce7; color: #166534; }
.badge--red    { background: #fee2e2; color: #991b1b; }
.badge--yellow { background: #fef3c7; color: #92400e; }

/* ── Alert / Message ── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.alert--info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.alert--success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

/* ── Utility ── */
.text-muted { color: var(--color-muted); font-size: 0.875rem; }
.text-sm    { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex--between { justify-content: space-between; align-items: center; }
.flex--wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-half { gap: 0.35rem; }

/* ── Table toolbar (search + pagination) ── */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.table-toolbar__search {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
}

.table-toolbar__pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.table-toolbar__info {
  font-size: 0.85rem;
  color: var(--color-muted);
  white-space: nowrap;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .nav {
    padding: 0 1rem;
    gap: 0.15rem;
    overflow-x: auto;
  }
  .nav__link {
    font-size: 0.78rem;
    padding: 0.4rem 0.6rem;
  }
  .page {
    padding: 1.25rem 1rem;
  }
  .form__row {
    grid-template-columns: 1fr;
  }
  .table th,
  .table td {
    padding: 0.5rem 0.6rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .nav {
    height: auto;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.25rem;
  }
  .nav__brand {
    width: 100%;
    margin-bottom: 0.25rem;
  }
  .login__box {
    width: calc(100% - 2rem);
    padding: 1.5rem;
  }
}

/* ── Hover tooltips (instant, no native title delay) ── */
.has-tip {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}

.has-tip__text {
  position: fixed;
  left: -9999px;
  top: 0;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  background: rgba(38, 38, 42, 0.62);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  color: #f4f4f5;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  text-align: center;
  border: 1px solid rgba(212, 212, 216, 0.85);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 300;
}

.has-tip__text.has-tip__text--visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  z-index: 500;
}

/* Styled combobox popup (gitea / org / repo / compiler / bundle pickers).
   Same minimalist look as the tooltip: translucent dark gray + thin light-gray
   opaque border. */
.picker-suggest {
  position: fixed;
  z-index: 650;
  display: none;
  max-height: 260px;
  overflow-y: auto;
  padding: 0.3rem;
  border-radius: 10px;
  background: rgba(38, 38, 42, 0.62);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  border: 1px solid rgba(212, 212, 216, 0.85);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}

.picker-suggest__option {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: #f4f4f5;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-suggest__option:hover,
.picker-suggest__option:focus {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

/* ── User guide (floating ? + modal) ── */
.user-guide-fab-wrap {
  position: fixed;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 250;
}

.user-guide-fab {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  border: none;
  background: var(--color-accent);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
  transition: transform var(--transition), box-shadow var(--transition);
  line-height: 1;
}

.user-guide-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.55);
}

.user-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.user-guide-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
  padding: 0;
}

.user-guide-panel {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: min(85vh, 720px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-guide-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.user-guide-panel__title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.user-guide-panel__close {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.user-guide-panel__close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.user-guide-panel__body {
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.user-guide-panel__footer {
  padding: 0.75rem 1.5rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
}

.user-guide-section {
  margin-bottom: 1.25rem;
}

.user-guide-section__title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--color-text);
}

.user-guide-section__text {
  font-size: 0.875rem;
  color: var(--color-muted);
  margin-bottom: 0.5rem;
  line-height: 1.55;
}

.user-guide-list {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--color-muted);
  line-height: 1.55;
}

.user-guide-list__item {
  margin-bottom: 0.35rem;
}

/* Inline explanatory callout (e.g. the "what is a binding?" hint on the
   binding-create form). Light info box with an accent left border. */
.callout {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--color-primary);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.75rem;
}

.callout__title {
  font-weight: 700;
  font-size: 0.875rem;
  margin: 0 0 0.25rem;
  color: var(--color-primary-dk);
}

.callout__text {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text);
}

.callout__text code {
  background: #dbeafe;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-size: 0.8rem;
}

/* Gitea / org / repo row (bindings create + dependency form). */
.gitea-picker-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.gitea-picker-row__gitea {
  flex: 1.2 1 160px;
  min-width: 0;
}

.gitea-picker-row__key {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 2 1 200px;
  min-width: 0;
}

.gitea-picker-row__key .form__input {
  flex: 1 1 0;
  min-width: 0;
}

.gitea-picker-row__slash {
  color: var(--color-muted);
  flex-shrink: 0;
}

.gitea-picker-row__bundle {
  flex: 1 1 160px;
  min-width: 0;
  padding-left: 0.75rem;
}

/* Full-screen Gitea-unavailable notice */
.gitea-down-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

.gitea-down-card {
  width: min(520px, 100%);
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
}

.gitea-down-card__icon {
  font-size: 2.5rem;
  line-height: 1;
  color: var(--color-warning);
  margin-bottom: 1rem;
}

.gitea-down-card__title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.gitea-down-card__text {
  color: var(--color-muted);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.gitea-down-card__label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 0.25rem;
}

.gitea-down-card__list {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-danger);
  word-break: break-all;
  margin-bottom: 1.5rem;
}

.gitea-down-card__retry {
  min-width: 140px;
}
