/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--radius-sm);
}
textarea, input { font-family: inherit; }

/* ===== App Shell ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  flex-shrink: 0;
  position: relative;
}

.header-brand {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.header-actions { display: flex; gap: var(--space-1); align-items: center; }

/* Header progress bar (during ping) */
.header-progress {
  position: absolute;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0;
  transition: width 200ms ease;
  z-index: 5;
}
.header-progress.indeterminate {
  width: 30%;
  animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes indeterminate {
  0%   { left: -30%; width: 30%; }
  60%  { left: 100%; width: 30%; }
  100% { left: 100%; width: 30%; }
}

/* ===== Workspace ===== */
.workspace {
  display: grid;
  grid-template-columns: 250px 1fr;
  flex: 1;
  min-height: 0;
}
@media (min-width: 1600px) {
  .workspace { grid-template-columns: 290px 1fr; }
}

.left-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-base);
}

.right-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-base);
}

/* ===== Paste textarea ===== */
.paste-area {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.paste-area textarea {
  width: 100%;
  min-height: 200px;
  max-height: 360px;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.55;
  resize: vertical;
  outline: none;
}
.paste-area textarea::placeholder { color: var(--text-muted); }
.paste-area textarea::-webkit-scrollbar { width: 6px; }
.paste-area textarea::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.paste-area.collapsed textarea {
  min-height: 40px;
  max-height: 40px;
  font-size: var(--text-xs);
}

/* ===== Toolbar (ping/clear/filters) =====
   Two-row layout by design: action buttons on top row, filter chips below.
   Keeps the toolbar readable in the slim sidebar (320px). */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.toolbar-actions {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  justify-content: flex-start;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Filter chips =====
   3-column grid: clean 2x3 layout at narrow sidebar widths (250px),
   each chip stretches to fill its cell so the rows line up perfectly. */
.filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  align-items: stretch;
}
@media (min-width: 1600px) {
  /* Wider sidebar — let chips line up in one row when there's room */
  .filters { grid-template-columns: repeat(6, auto); justify-content: start; }
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: all var(--transition);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-primary);
}

.chip-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--status-pending);
}
.chip[data-filter="alive"] .chip-dot { background: var(--status-alive); }
.chip[data-filter="dead"] .chip-dot { background: var(--status-dead); }
.chip[data-filter="not_found"] .chip-dot { background: var(--status-notfound); }
.chip[data-filter="error"] .chip-dot { background: var(--status-error); }
.chip[data-filter="saved"] .chip-dot {
  background: transparent;
  width: auto; height: auto;
  font-size: 11px; line-height: 1;
  color: var(--accent);
}

/* ===== URL List ===== */
.url-list-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-1) 0;
}
.url-list-wrapper::-webkit-scrollbar { width: 6px; }
.url-list-wrapper::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.url-list-wrapper::-webkit-scrollbar-track { background: transparent; }

.url-list {
  list-style: none;
}

.empty-state {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* Row */
.row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-4);
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.row:hover { background: var(--bg-hover); }
.row.active {
  background: var(--bg-active);
  border-left-color: var(--accent);
}
.row.row-flash { animation: row-flash 600ms ease-out; }
@keyframes row-flash {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}
.row.active.row-flash {
  animation-fill-mode: forwards;
}
.row.active.row-flash {
  animation: none;
  background: var(--bg-active);
}

.row-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--status-pending);
  flex-shrink: 0;
}
.row[data-status="alive"] .row-dot { background: var(--status-alive); }
.row[data-status="dead"] .row-dot { background: var(--status-dead); }
.row[data-status="not_found"] .row-dot { background: var(--status-notfound); }
.row[data-status="error"] .row-dot { background: var(--status-error); }
.row[data-status="pending"] .row-dot {
  background: var(--status-pending);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.row-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.row-url {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row.active .row-url { color: var(--text-primary); font-weight: 500; }
.row[data-status="dead"]:not(.active) .row-url,
.row[data-status="not_found"]:not(.active) .row-url {
  color: var(--text-secondary);
}

.row-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta .meta-pending {
  font-style: italic;
  color: var(--text-muted);
}
.row-meta .meta-error { color: var(--status-dead); }

.row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}
.row:hover .row-actions,
.row.active .row-actions { opacity: 1; }

.row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}
.row-btn:hover { background: var(--border); color: var(--text-primary); }
.row-btn.saved { color: var(--accent); }

/* ===== Right pane: Preview ===== */
.preview-bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--header-height);
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--bg-base);
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.url-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
}
.url-bar-text {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: text;
}
.url-bar.has-url .url-bar-text { color: var(--text-primary); }
.url-bar[data-status="alive"] { border-color: var(--status-alive); }
.url-bar[data-status="dead"],
.url-bar[data-status="not_found"] { border-color: var(--status-dead); }
.url-bar[data-status="error"] { border-color: var(--status-error); }

.nav-counter {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding: 0 var(--space-2);
  min-width: 50px;
  text-align: right;
}

/* ===== Preview area ===== */
.preview-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* Always white behind the iframe — user explicitly does not want our
     dark theme bleeding into the previewed site. */
  background: #ffffff;
}

.preview-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 10;
  width: 0;
  opacity: 0;
  transition: opacity var(--transition);
}
.preview-progress.loading {
  opacity: 1;
  animation: preview-load 6s linear forwards;
}
@keyframes preview-load {
  0%   { width: 5%; }
  20%  { width: 35%; }
  60%  { width: 75%; }
  90%  { width: 92%; }
  100% { width: 95%; }
}

#preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  /* Force the iframe to inherit the LIGHT UA color-scheme regardless of
     our app theme. Without this, dark-mode users get inverted scrollbars,
     form controls, and Canvas-color backgrounds inside previewed sites. */
  color-scheme: light;
}
#preview-frame.hidden { display: none; }

.preview-empty,
.preview-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-6);
  background: var(--bg-elevated);
  z-index: 5;
  pointer-events: none;
}
.preview-empty.hidden,
.preview-error.hidden { display: none; }

.preview-empty * { pointer-events: auto; }
.preview-error * { pointer-events: auto; }

.preview-empty-icon {
  font-size: 28px;
  color: var(--text-muted);
  opacity: 0.6;
}
.preview-empty-text,
.preview-error-text {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}
.preview-error-text { color: var(--text-primary); }
.preview-error-sub {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  max-width: 480px;
  word-break: break-all;
}
.preview-empty-hint {
  margin-top: var(--space-3);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* ===== Notifications ===== */
.notifications {
  position: fixed;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  max-width: 320px;
}
.notification {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: slide-in 180ms ease;
}
.notification.fade-out { animation: slide-out 180ms ease forwards; }
.notification-info    { border-left: 3px solid var(--accent); }
.notification-success { border-left: 3px solid var(--status-alive); }
.notification-warning { border-left: 3px solid var(--status-error); }
.notification-error   { border-left: 3px solid var(--status-dead); }
@keyframes slide-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes slide-out {
  to { transform: translateX(110%); opacity: 0; }
}

/* ===== Mobile Tabs ===== */
.mobile-tabs { display: none; }

@media (max-width: 1023px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  .left-pane, .right-pane {
    border-right: none;
  }
  .left-pane { display: none; }
  .right-pane { display: none; }
  .app[data-mobile-view="urls"] .left-pane { display: flex; }
  .app[data-mobile-view="preview"] .right-pane { display: flex; }

  .mobile-tabs {
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
    flex-shrink: 0;
  }
  .mobile-tab {
    flex: 1;
    padding: 10px var(--space-2);
    background: transparent;
    border: none;
    border-top: 2px solid transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: color var(--transition), border-color var(--transition);
  }
  .mobile-tab.active {
    color: var(--accent);
    border-top-color: var(--accent);
  }
}

@media (max-width: 480px) {
  .toolbar { padding: var(--space-2); gap: var(--space-1); }
  .nav-counter { display: none; }
  .preview-bar { padding: 0 var(--space-2); }
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.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;
}
