body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f4f5f7;
  color: #1a1d23;
  line-height: 1.45;
}

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

a {
  color: #1f4b99;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.85rem 1.25rem;
  background: #1a1d23;
  color: #fff;
}

.topbar a {
  color: #c9d3e5;
}

.topbar a.active,
.topbar a:hover {
  color: #fff;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.topbar nav {
  display: flex;
  gap: 1rem;
  flex: 1;
}

.user {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  font-size: 0.92rem;
}

.user form,
.logout-form {
  display: inline;
  margin: 0;
}

button.linkish {
  border: 0;
  background: transparent;
  color: #d7e4ff;
  padding: 0;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

button.linkish:hover {
  color: #fff;
  text-decoration: underline;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e6e9ef;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 140px;
  flex: 1 1 140px;
  max-width: 240px;
  font-size: 0.8rem;
  color: #667085;
}

.filter-field input[type="text"],
.filter-field input.date-text,
.filter-field select {
  width: 100%;
  min-width: 0;
  max-width: none;
  box-sizing: border-box;
  height: 2.4rem;
  padding: 0.45rem 0.65rem;
  line-height: 1.2;
}

.filter-field input[name="q"] {
  max-width: none;
}

.filter-field input.date-text {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.filter-actions-field {
  flex: 1 1 100%;
  max-width: none;
  min-width: 0;
}

.filter-actions-spacer {
  display: none;
}

.filter-actions {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  align-items: stretch;
  height: 2.4rem;
}

.filter-actions .btn,
.filter-actions a.btn,
.filter-actions button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.4rem;
  min-height: 2.4rem;
  min-width: 5.75rem;
  padding: 0 0.9rem;
  margin: 0;
  line-height: 1;
  font-size: 0.9rem;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.card {
  background: #fff;
  border: 1px solid #dde1e8;
  border-radius: 8px;
  padding: 1.25rem;
}

h1 {
  margin: 0 0 1rem;
  font-size: 1.35rem;
}

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

.muted {
  color: #667085;
  font-size: 0.92rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid #e6e9ef;
  padding: 0.65rem 0.55rem;
  text-align: left;
  vertical-align: middle;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #667085;
  background: #fafbfc;
}

a.sort-link {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

a.sort-link .sort-icon {
  font-size: 0.85em;
  opacity: 0.45;
  line-height: 1;
}

a.sort-link:hover,
a.sort-link.sort-active {
  color: #1f4b99;
  text-decoration: none;
}

a.sort-link:hover .sort-icon,
a.sort-link.sort-active .sort-icon {
  opacity: 1;
}

tr:hover td {
  background: #f8fafc;
}

.url {
  max-width: 280px;
  word-break: break-all;
}

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

.section-actions {
  display: flex;
  margin-bottom: 1rem;
}

.organization-credentials {
  margin-bottom: 1rem;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  vertical-align: middle;
}

.btn,
button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #1f4b99;
  background: #1f4b99;
  color: #fff;
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}

.btn.btn-sm,
button.btn.btn-sm {
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 5px;
  font-weight: 600;
}

.btn.secondary,
button.btn.secondary {
  background: #fff;
  color: #1f4b99;
  border-color: #c5d0e6;
}

.btn.secondary:hover,
button.btn.secondary:hover {
  background: #f3f6fb;
  border-color: #1f4b99;
}

.btn.danger,
button.btn.danger {
  background: #fff;
  border-color: #f0b4ae;
  color: #b42318;
}

.btn.danger:hover,
button.btn.danger:hover {
  background: #fff5f4;
  border-color: #b42318;
}

.btn.success,
button.btn.success {
  background: #fff;
  border-color: #a6d8b5;
  color: #0f7a3a;
}

.btn.success:hover,
button.btn.success:hover {
  background: #f2fbf5;
  border-color: #0f7a3a;
}

.btn:hover,
button.btn:hover {
  opacity: 1;
  text-decoration: none;
}

/* Table row actions: keep after .btn rules so sizing wins */
.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  line-height: 1;
}

.row-actions form {
  display: contents;
}

.row-actions > .btn,
.row-actions form > .btn,
.row-actions button.btn {
  appearance: none;
  -webkit-appearance: none;
  height: 1.85rem;
  min-width: 4.2rem;
  padding: 0 0.65rem;
  margin: 0;
  line-height: 1;
  font-size: 0.8rem;
  border-radius: 5px;
}

/* Keep plain <button> usable in forms outside .btn */
button:not(.btn) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #1f4b99;
  background: #1f4b99;
  color: #fff;
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.flash {
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
}

.flash-ok {
  background: #e8f7ee;
  color: #067647;
}

.flash-error {
  background: #feeceb;
  color: #b42318;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(100%, 380px);
}

.login-alt {
  margin-top: 1rem;
  text-align: center;
}

.card-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.table-card {
  margin-top: 1.25rem;
}

.row-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  white-space: nowrap;
}

.inline-form {
  display: inline;
  margin: 0;
}

.danger-text {
  color: #b42318;
}

label {
  display: block;
  font-size: 0.85rem;
  margin: 0.75rem 0 0.3rem;
  color: #344054;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="email"],
textarea,
select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cfd5e0;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: #fff;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

.email-row-fields {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.email-row-fields input {
  flex: 1;
  min-width: 0;
}

.email-row-fields .email-remove {
  flex: 0 0 auto;
  align-self: stretch;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.6rem;
}

.permission-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.8rem;
}

.permission-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid #d9dee8;
  border-radius: 8px;
  background: #fafbfc;
  cursor: pointer;
}

.permission-option:hover {
  border-color: #9aa9bf;
  background: #f5f7fa;
}

.permission-option input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.15rem 0 0;
  accent-color: #1f4b99;
  flex: 0 0 auto;
}

.permission-option span {
  display: grid;
  gap: 0.15rem;
}

.permission-option small {
  color: #667085;
  font-size: 0.85rem;
  font-weight: 400;
}

.hint {
  margin: 0 0 0.75rem;
  color: #4b5565;
  font-size: 0.95rem;
}

.pager {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 1rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #3538cd;
  font-size: 0.78rem;
}

.badge-on {
  background: #e8f8ee;
  color: #0f7a3a;
}

.badge-off {
  background: #f2f4f7;
  color: #667085;
}

.crawl-status {
  white-space: nowrap;
}

@media (max-width: 900px) {
  .wrap {
    padding: 0.85rem;
  }

  .card {
    padding: 0.9rem;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 0.65rem 1rem;
    padding: 0.75rem 0.9rem;
  }

  .topbar nav {
    order: 3;
    flex: 1 1 100%;
    gap: 0.85rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
  }

  .topbar .brand {
    flex: 1 1 auto;
  }

  .topbar .user {
    margin-left: auto;
  }

  .toolbar {
    align-items: flex-start;
  }

  .toolbar .actions,
  .form-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .toolbar .actions .btn,
  .form-actions .btn,
  .form-actions button {
    flex: 1 1 auto;
  }

  .filter-actions-field {
    flex: 1 1 100%;
    max-width: none;
  }

  .filter-actions .btn,
  .filter-actions a.btn,
  .filter-actions button.btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .filters {
    gap: 0.65rem;
  }

  .filter-field {
    flex: 1 1 calc(50% - 0.65rem);
    max-width: none;
    min-width: 0;
  }

  .filter-field:has(input[name="q"]) {
    flex: 1 1 100%;
  }

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

  table {
    font-size: 0.82rem;
  }

  th,
  td {
    padding: 0.5rem 0.4rem;
  }

  .url {
    max-width: 140px;
  }

  .col-actions {
    white-space: normal;
  }

  .row-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .row-actions > .btn,
  .row-actions form > .btn,
  .row-actions button.btn {
    min-width: 3.6rem;
  }

  .crawl-status {
    white-space: normal;
  }

  .pager {
    flex-wrap: wrap;
  }

  h1 {
    font-size: 1.2rem;
  }
}

@media (max-width: 560px) {
  .filter-field {
    flex: 1 1 100%;
  }

  .login-card {
    width: 100%;
  }

  .user span {
    max-width: 7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
