/* ===== RESET & VARIABLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-body: #0e0d0d;
  --bg-card: #000;
  --bg-input: #776d6d50;
  --bg-secondary: #000000;
  --border-color: #810505;
  --border-light: #000000;
  --text-primary: #f8f8f7;
  --text-secondary: #e0dddc;
  --text-muted: #e0e0e0;
  --accent-red: #b90404;
  --accent-red-light: #b30505;
  --accent-red-dark: #a82828;
  --accent-red-glow: rgba(212, 58, 58, 0.15);
  --accent-gold: #eea301;
  --shadow: 0 2px 20px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 8px 40px rgba(212, 58, 58, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --font:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 28px 24px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: var(--bg-input);
}
::-webkit-scrollbar-thumb {
  background: var(--accent-red);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-red-light);
}

.app {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===== CARD ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  padding: 22px 26px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-red);
}

.card-padding {
  padding: 22px 26px;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-title h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text-primary);
}

.header-title .badge-version {
  font-size: 10px;
  font-weight: 500;
  background: var(--bg-secondary);
  color: var(--accent-red-light);
  padding: 2px 12px;
  border-radius: 20px;
  margin-left: 6px;
  border: 1px solid var(--accent-red);
  letter-spacing: 0.3px;
}

.header-title p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
  font-weight: 400;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 5px 16px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background: #5a9a5a;
  box-shadow: 0 0 10px rgba(90, 154, 90, 0.3);
}

.status-dot.offline {
  background: var(--accent-red);
  box-shadow: 0 0 10px rgba(212, 58, 58, 0.3);
}

/* ===== LABEL ===== */
.card-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-label i {
  color: var(--accent-red);
  font-size: 13px;
}

/* ===== GRID ===== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .card-padding {
    padding: 16px 14px;
  }
  body {
    padding: 14px 10px;
  }
}

/* ===== INPUT ===== */
.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.input-row .input-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.input-row .input-wrap i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
}

.input-row input,
.input-row textarea {
  width: 100%;
  padding: 11px 16px 11px 40px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition);
  font-family: inherit;
}

.input-row input:focus,
.input-row textarea:focus {
  outline: none;
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px var(--accent-red-glow);
  background: #1f1818;
}

.input-row input::placeholder,
.input-row textarea::placeholder {
  color: var(--text-muted);
}

/* ===== BUTTONS ===== */
.btn {
  padding: 11px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-red);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-red-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(212, 58, 58, 0.3);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--accent-red);
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.btn-red-soft {
  background: var(--accent-red);
  color: #fff;
}

.btn-red-soft:hover {
  background: var(--accent-red-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(212, 58, 58, 0.3);
}

.btn-sm {
  padding: 4px 12px;
  font-size: 11px;
  border-radius: 6px;
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover {
  border-color: var(--accent-red);
  color: var(--text-primary);
}

/* ===== OPTIONS ===== */
.options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 0 2px 0;
  border-top: 1px solid var(--border-light);
  margin-top: 14px;
}

.options-bar .option-group {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.options-bar .option-group:hover {
  color: var(--text-primary);
}

.options-bar .option-group input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent-red);
  cursor: pointer;
}

.options-bar .option-group input[type="number"] {
  width: 56px;
  height: 28px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 0 6px;
  font-size: 12px;
  font-family: inherit;
}

.options-bar .option-group select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.url-history {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.url-history .history-tag {
  font-size: 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-light);
  cursor: pointer;
  transition: var(--transition);
}

.url-history .history-tag:hover {
  border-color: var(--accent-red);
  color: var(--text-primary);
  background: #2a1e1e;
}

/* ===== STATUS ===== */
#status {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: none;
  margin-top: 12px;
  align-items: center;
  gap: 8px;
}

#status.show {
  display: flex;
}

#status.loading {
  background: rgba(212, 58, 58, 0.08);
  color: var(--accent-red-light);
  border: 1px solid rgba(212, 58, 58, 0.15);
}

#status.success {
  background: rgba(90, 154, 90, 0.08);
  color: #7aaa7a;
  border: 1px solid rgba(90, 154, 90, 0.15);
}

#status.error {
  background: rgba(212, 58, 58, 0.12);
  color: var(--accent-red-light);
  border: 1px solid rgba(212, 58, 58, 0.2);
}

#status i {
  font-size: 16px;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 3px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 12px;
  border: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  padding: 7px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 60px;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent-red-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--accent-red);
}

/* ===== OUTPUT ===== */
.output-wrapper {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-input);
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 5px;
}

.output-header .left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}

.output-header .left .lang {
  background: var(--bg-card);
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-red-light);
  border: 1px solid var(--border-color);
}

.output-header .right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.output-header .right .stats {
  font-size: 11px;
  color: var(--text-muted);
}

.output-body {
  padding: 14px 18px;
  font-family: "SF Mono", "JetBrains Mono", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-card);
  color: var(--text-primary);
  min-height: 100px;
}

.output-body:empty::before {
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
}

/* ===== PREVIEW ===== */
.preview-container {
  display: none;
  background: var(--bg-card);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow: hidden;
}

.preview-container.active {
  display: block;
}

.preview-container iframe {
  width: 100%;
  height: 460px;
  border: none;
  background: #fff;
}

.preview-container .preview-info {
  padding: 6px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 3px;
}

/* ===== KEYWORD ROW ===== */
.keyword-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.keyword-row .input-wrap {
  flex: 2;
  min-width: 140px;
  position: relative;
}

.keyword-row .input-wrap i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}

.keyword-row input {
  width: 100%;
  padding: 9px 12px 9px 38px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  transition: var(--transition);
  font-family: inherit;
}

.keyword-row input:focus {
  outline: none;
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px var(--accent-red-glow);
  background: #1f1818;
}

.keyword-row input::placeholder {
  color: var(--text-muted);
}

.keyword-row input[type="number"] {
  width: 70px;
  padding: 9px 10px;
  flex: 0 0 auto;
}

/* ===== SEARCH RESULTS ===== */
.top-url-list {
  list-style: none;
  padding: 0;
}

.top-url-list li {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: var(--transition);
  cursor: default;
}

.top-url-list li:last-child {
  border-bottom: none;
}

.top-url-list li:hover {
  background: var(--bg-input);
}

.top-url-list .rank {
  font-size: 15px;
  font-weight: 600;
  min-width: 28px;
  text-align: center;
  color: var(--text-muted);
}

.top-url-list .rank.gold {
  color: var(--accent-gold);
}
.top-url-list .rank.silver {
  color: #8a8a8a;
}
.top-url-list .rank.bronze {
  color: #b8863a;
}

.top-url-list .url-text {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  word-break: break-all;
}

.top-url-list .url-text a {
  color: var(--accent-red-light);
  text-decoration: none;
  transition: var(--transition);
}

.top-url-list .url-text a:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.top-url-list .title-row {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 2px 0 2px 34px;
}

.top-url-list .snippet-row {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 34px;
  line-height: 1.5;
}

.top-url-list .snippet-row .highlight {
  color: var(--accent-red-light);
  font-weight: 500;
  background: rgba(212, 58, 58, 0.1);
  padding: 0 3px;
  border-radius: 3px;
}

/* ===== LIBRARY CARDS ===== */
.library-section {
  margin-top: 24px;
}

.library-section .section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.library-section .section-title i {
  color: var(--accent-red);
}

.library-section .section-title .badge-cache {
  font-size: 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 2px 12px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid var(--border-light);
}

.library-section .section-title .filter-badge {
  font-size: 10px;
  background: rgba(212, 58, 58, 0.1);
  color: var(--accent-red-light);
  padding: 2px 12px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid rgba(212, 58, 58, 0.15);
  margin-left: auto;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

@media (max-width: 1200px) {
  .library-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 992px) {
  .library-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .library-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .library-grid {
    grid-template-columns: 1fr;
  }
}

.library-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.library-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent-red);
}

.library-card .card-thumb {
  width: 100%;
  aspect-ratio: 16/10;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.library-card .card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition);
}

.library-card:hover .card-thumb img {
  transform: scale(1.03);
}

.library-card .card-thumb .fallback-icon {
  font-size: 32px;
  color: var(--text-muted);
  opacity: 0.25;
}

.library-card .card-thumb .rank-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  padding: 2px 10px;
  border-radius: 14px;
  font-size: 9px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.3px;
}

.library-card .card-thumb .rank-badge.gold {
  background: var(--accent-gold);
  color: #1a1414;
}
.library-card .card-thumb .rank-badge.silver {
  background: #8a8a8a;
  color: #1a1414;
}
.library-card .card-thumb .rank-badge.bronze {
  background: #b8863a;
  color: #1a1414;
}

.library-card .card-body {
  padding: 10px 12px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.library-card .card-body .card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-card .card-body .card-domain {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-card .card-body .card-snippet {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
  opacity: 0.8;
}

.library-card .card-body .card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-light);
  font-size: 10px;
  color: var(--text-muted);
}

.library-card .card-body .card-footer .source-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 2px 10px;
  border-radius: 14px;
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.library-card .card-body .card-footer .source-btn:hover {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-color);
}

.library-empty i {
  font-size: 32px;
  display: block;
  margin-bottom: 10px;
  opacity: 0.25;
}

/* ===== FOOTER ===== */
.footer {
  margin-top: 24px;
  padding: 14px 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
}

.footer .tech-stack {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.footer .tech-stack span {
  background: var(--bg-input);
  padding: 2px 12px;
  border-radius: 20px;
  font-size: 9px;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}

.footer .tech-stack span i {
  color: var(--accent-red);
  margin-right: 3px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  body {
    padding: 10px 8px;
  }
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .header-status {
    justify-content: center;
  }
  .card {
    padding: 14px 12px;
  }
  .card-padding {
    padding: 12px 10px;
  }
  .input-row .btn {
    width: 100%;
    justify-content: center;
  }
  .keyword-row .btn {
    width: 100%;
    justify-content: center;
  }
  .keyword-row input[type="number"] {
    width: 100%;
    flex: 1;
  }
  .options-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .output-body {
    font-size: 11px;
    padding: 10px 12px;
    max-height: 240px;
  }
  .output-header {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .tabs {
    flex-direction: column;
  }
  .preview-container iframe {
    height: 260px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .top-url-list li {
    flex-wrap: wrap;
    gap: 3px;
  }
  .top-url-list .title-row {
    margin-left: 0;
  }
  .top-url-list .snippet-row {
    margin-left: 0;
  }
  .library-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .header-title h1 {
    font-size: 17px;
  }
  .library-grid {
    grid-template-columns: 1fr;
  }
}
