:root {
  color-scheme: light dark;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f2f5;
  color: #1a1a1a;
}

.layout {
  width: min(1100px, 100%);
  padding: 2rem;
  display: grid;
  grid-template-columns: 300px minmax(0, 540px);
  justify-content: center;
  align-items: stretch;
  gap: 2rem;
}

.layout > .card {
  position: relative;
  width: 100%;
}

/* Stretches to the card's height; contain: size keeps the list from ever
   growing the panel (or the card) - it scrolls instead. */
.history-panel {
  contain: size;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 24px 48px rgba(33, 43, 54, 0.12);
  text-align: left;
  min-width: 0;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.history-header h2 {
  margin: 0;
  font-size: 1rem;
}

.history-count {
  color: #64748b;
  font-weight: 500;
}

.history-action {
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  font-size: 0.75rem;
  background: #e2e8f0;
  color: #1e293b;
}

.history-action:hover,
.history-action:focus-visible {
  box-shadow: none;
  background: #cbd5e1;
}

.history-action-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.history-action-danger:hover,
.history-action-danger:focus-visible {
  background: #fecaca;
}

.history-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.history-toggle {
  width: 100%;
}

.history-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.history-filters[hidden] {
  display: none;
}

.history-filters input,
.history-filters select {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  font: inherit;
  font-size: 0.85rem;
}

.history-filters input:focus,
.history-filters select:focus {
  outline: none;
  border-color: #5c8aff;
  box-shadow: 0 0 0 3px rgba(92, 138, 255, 0.15);
}

.history-notice,
.history-empty {
  margin: 0;
  font-size: 0.85rem;
  color: #64748b;
}

.history-notice {
  color: #b45309;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0 0.25rem 0 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Always-visible scrollbar (Chromium/Edge otherwise hides overlay scrollbars). */
.history-list::-webkit-scrollbar,
.result-list-scroll::-webkit-scrollbar {
  width: 8px;
}

.history-list::-webkit-scrollbar-track,
.result-list-scroll::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 8px;
}

.history-list::-webkit-scrollbar-thumb,
.result-list-scroll::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 8px;
}

.history-item {
  position: relative;
  flex: 0 0 auto;
}

.history-remove {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1;
  text-transform: none;
  letter-spacing: normal;
}

.history-remove:hover,
.history-remove:focus-visible {
  transform: none;
  box-shadow: none;
  background: #fee2e2;
  color: #b91c1c;
}

.history-remove:focus-visible {
  outline: 2px solid #b91c1c;
  outline-offset: 1px;
}

.history-entry {
  width: 100%;
  display: grid;
  gap: 0.2rem;
  padding: 0.65rem 2.4rem 0.65rem 0.8rem;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-left: 4px solid #3f6ee4;
  border-radius: 10px;
}

.history-entry:hover,
.history-entry:focus-visible {
  transform: none;
  box-shadow: none;
  background: #eef2ff;
}

.history-entry:focus-visible,
.history-action:focus-visible {
  outline: 2px solid #3f6ee4;
  outline-offset: 2px;
}

.history-entry-error {
  border-left-color: #e11d48;
}

.history-query {
  font-weight: 600;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.history-meta {
  font-size: 0.8rem;
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  font-size: 0.75rem;
  color: #64748b;
}

@media (max-width: 900px) {
  body {
    align-items: flex-start;
  }

  .layout {
    grid-template-columns: minmax(0, 540px);
    padding: 1rem;
    gap: 1rem;
  }

  .history-panel {
    height: min(360px, 50vh);
  }
}

.card {
  width: min(540px, 94vw);
  padding: 2.5rem;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  box-shadow: 0 24px 48px rgba(33, 43, 54, 0.12);
  text-align: center;
}

.brand {
  display: inline-flex;
  padding: 0.15rem;
  margin-bottom: 0.6rem;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.06);
}

.brand svg {
  width: 42px;
  height: 42px;
  display: block;
}

h1 {
  margin: 0;
  font-size: clamp(1.95rem, 2.3vw, 2.5rem);
}

h2 {
  margin: 0.2rem 0 1.4rem;
  font-weight: 600;
  font-size: clamp(1.2rem, 2vw, 1.4rem);
  color: #334155;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.lead {
  margin: 0.75rem 0 2rem;
  color: #4b5563;
  font-size: 0.95rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

input[type="text"] {
  padding: 1.05rem 1.25rem;
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: #0f172a;
  font-size: 1.05rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  min-height: 3.4rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: #5c8aff;
  background-color: #ffffff;
  box-shadow: 0 0 0 4px rgba(92, 138, 255, 0.15);
}

small {
  color: #64748b;
  font-size: 0.8rem;
}

button {
  padding: 1rem;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #5c8aff, #3f6ee4);
  color: #f8fafc;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-size: 0.9rem;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(63, 110, 228, 0.28);
}

#result {
  margin-top: 1.5rem;
  text-align: left;
  min-height: 3rem;
  font-size: 0.95rem;
  color: #1f2937;
}

.loading {
  opacity: 0.7;
}

.error {
  color: #e11d48;
}

.success h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: #1d4ed8;
}

.result-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.result-list-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.4rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #f1f5f9;
}

.result-item {
  flex: 0 0 auto;
  padding: 1.1rem 1.5rem;
  background: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.result-heading {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  column-gap: 0.65rem;
  row-gap: 0.2rem;
  align-items: baseline;
}

.result-label {
  color: #1d4ed8;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  font-weight: 700;
}

.result-url {
  font-size: 0.95rem;
  font-weight: 600;
  color: #111827;
  word-break: break-word;
}

.result-categories {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.category-line {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  column-gap: 0.65rem;
  row-gap: 0.25rem;
  align-items: baseline;
}

.category-label {
  color: #1d4ed8;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  font-weight: 700;
}

.category-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #111827;
  word-break: break-word;
}

.category-line-empty .category-name {
  color: #475569;
  font-style: italic;
}

.category-description {
  margin: 0.35rem 0 0;
  color: #475569;
  font-size: 0.9rem;
  grid-column: 1 / -1;
}

.footer {
  margin-top: 2.3rem;
  font-size: 0.85rem;
  color: #475569;
}

.footer a {
  color: #1d4ed8;
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover,
.footer a:focus-visible {
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
