:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --bg-hover: #f4f4f5;
  --surface: #ffffff;
  --border: #eaeaea;
  --border-strong: #d4d4d8;
  --text: #111111;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --accent: #111111;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.14);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-subtle: #111111;
  --bg-hover: #18181b;
  --surface: #111111;
  --border: #242427;
  --border-strong: #3f3f46;
  --text: #ededed;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #ffffff;
  --accent-fg: #0a0a0a;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.65);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

.muted {
  color: var(--text-muted);
}

.text-xs {
  font-size: 12px;
}

.icon-sm {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.icon-xs {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* Visibility toggle in Drop Bar */
.vis-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.vis-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.vis-toggle[data-visibility="public"] .icon-lock {
  display: none;
}

.vis-toggle[data-visibility="private"] .icon-unlock {
  display: none;
}

.vis-toggle[data-visibility="private"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Scope + Tags Toolbar */
.filter-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0 14px;
}

.scope-segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  flex-shrink: 0;
}

.scope-btn {
  height: 24px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.scope-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}

.filter-toolbar .tags-bar {
  padding: 0;
  flex: 1;
  min-width: 0;
}

/* Private Badge & Owner Handle */
.private-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  flex-shrink: 0;
}

.owner-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.identity-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Theme icons */
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* Topbar (auto-hides smoothly on scroll down, reappears on scroll up) */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
  transform: translateY(0);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.topbar.topbar-hidden {
  transform: translateY(calc(-100% - 2px));
}

/* Twitter-style Dual Feed Tabs */
.feed-tabs-bar {
  border-top: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.feed-tabs-inner {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 42px;
}

.feed-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}

.feed-tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-hover) 55%, transparent);
}

.feed-tab.active {
  color: var(--text);
  font-weight: 650;
}

.feed-tab-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  opacity: 0.78;
}

.feed-tab-indicator {
  position: absolute;
  bottom: 0;
  left: 20px;
  width: calc(50% - 20px);
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.feed-tabs-inner[data-active-feed="public"] .feed-tab-indicator {
  transform: translateX(100%);
}

/* Quick Tag Modal */
.stack-xs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.line-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

.quick-tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.quick-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 12.5px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.quick-tag-chip:hover {
  border-color: var(--border-strong);
}

.quick-tag-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.quick-tag-form {
  display: flex;
  gap: 8px;
}

.quick-tag-form input {
  flex: 1;
  height: 34px;
  padding: 0 11px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 13px;
}

.quick-tag-form input:focus {
  border-color: var(--border-strong);
  background: var(--bg);
}

.topbar-inner {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.brand-logo {
  width: 22px;
  height: 22px;
}

.brand-name {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 34px;
  padding: 0 34px 0 34px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
}

.search-box input:focus {
  border-color: var(--border-strong);
  background: var(--bg);
}

.kbd-hint {
  position: absolute;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 18px;
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}

.seg-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.filter-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text);
}

.icon-btn.active .filter-dot {
  background: var(--accent-fg);
}

/* Quick existing tags row inside Drop Bar */
.drop-quick-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-top: 4px;
  scrollbar-width: none;
}

.drop-quick-tags::-webkit-scrollbar {
  display: none;
}

.drop-tag-chip {
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.drop-tag-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.drop-tag-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Archived state (Personal Feed only) */
.item-card.is-archived,
.item-row.is-archived {
  opacity: 0.56;
  background: var(--bg-subtle);
}

.item-card.is-archived .card-cover,
.item-row.is-archived .row-thumb {
  filter: grayscale(85%);
}

.archived-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Multi-select state */
.select-mode .item-card[data-can-edit="1"],
.select-mode .item-row[data-can-edit="1"] {
  cursor: pointer;
}

.item-card.is-selected,
.item-row.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.select-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.item-row .select-indicator {
  position: static;
  flex-shrink: 0;
  margin-top: 4px;
}

.is-selected .select-indicator {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Floating Batch Action Bar */
.batch-bar {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  transform: translateX(-50%);
  z-index: 55;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}

.batch-bar::-webkit-scrollbar {
  display: none;
}

.batch-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 0 6px;
  white-space: nowrap;
}

.batch-btn {
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent-fg) 22%, transparent);
  background: transparent;
  color: var(--accent-fg);
  font-size: 12px;
  white-space: nowrap;
  transition: background 0.12s;
}

.batch-btn:hover {
  background: color-mix(in srgb, var(--accent-fg) 14%, transparent);
}

.batch-btn.batch-danger {
  border-color: color-mix(in srgb, var(--danger) 65%, transparent);
  color: #fca5a5;
}

/* Main Content */
.main-content {
  padding-top: 20px;
  padding-bottom: 64px;
}

/* Quick Drop Bar */
.drop-section {
  margin-bottom: 16px;
}

.drop-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s;
}

.drop-bar:focus-within {
  border-color: var(--border-strong);
}

.drop-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.drop-icon {
  position: absolute;
  left: 6px;
  color: var(--text-muted);
  pointer-events: none;
}

.drop-input-wrap input {
  width: 100%;
  height: 36px;
  padding: 0 36px 0 30px;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
}

.drop-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.drop-tags-input {
  flex: 1;
  height: 32px;
  padding: 0 8px;
  border: none;
  background: transparent;
  outline: none;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.btn-primary, .btn-secondary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: opacity 0.12s, background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover {
  opacity: 0.88;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: wait;
}

.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

/* Tags Filter Bar */
.tags-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 14px;
  scrollbar-width: none;
}

.tags-bar::-webkit-scrollbar {
  display: none;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.tag-pill:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.tag-pill .pill-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.65;
}

/* Auth Banner */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  border-radius: var(--radius);
}

/* Card Grid View */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.item-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.item-card:hover {
  border-color: var(--border-strong);
}

.card-cover-link {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.item-card:hover .card-cover {
  transform: scale(1.02);
}

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-meta-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
}

.favicon {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--bg-subtle);
}

.domain-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-dot {
  opacity: 0.45;
  flex-shrink: 0;
}

.date-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card-summary {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.mini-tag {
  font-size: 11.5px;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.mini-tag:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
  flex-shrink: 0;
}

.item-card:hover .card-actions,
.item-row:hover .card-actions,
.item-card:focus-within .card-actions,
.item-row:focus-within .card-actions {
  opacity: 1;
}

@media (hover: none) {
  .card-actions {
    opacity: 1;
  }
}

.mini-action {
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.mini-action:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.mini-action.danger:hover {
  color: var(--danger);
}

/* Compact List View (GitHub Issue Style) */
.items-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.item-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.item-row:last-child {
  border-bottom: none;
}

.item-row:hover {
  background: var(--bg-subtle);
}

.row-thumb-link {
  width: 88px;
  height: 54px;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-subtle);
  margin-top: 2px;
}

.row-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.row-title {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row-summary {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-bottom {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 72px 20px;
}

.empty-orbit {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 1.5px dashed var(--border-strong);
  position: relative;
}

.empty-orbit::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--text);
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

/* Sentinel */
.sentinel {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-family: var(--font-mono);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-wide {
  max-width: 720px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}

.spacer { flex: 1; }

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row-end {
  display: flex;
  justify-content: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.field span {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.field input,
.field textarea,
.field select,
.rule-create-grid input,
.rule-create-grid select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 13px;
}

.field input:focus,
.field textarea:focus,
.rule-create-grid input:focus,
.rule-create-grid select:focus {
  border-color: var(--border-strong);
  background: var(--bg);
}

.field-row {
  display: flex;
  gap: 10px;
}

/* Rules UI */
.rule-create-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 1.3fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.rules-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rules-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.rule-item:last-child {
  border-bottom: none;
}

.rule-item.disabled {
  opacity: 0.45;
}

.rule-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.rule-name {
  font-weight: 600;
}

.rule-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.rule-pattern {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  word-break: break-all;
}

/* Settings Helpers */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
}

.guide-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.code-block {
  margin: 0;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow-x: auto;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.shortcut-grid kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text);
  margin-right: 4px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Responsive */
@media (max-width: 720px) {
  .container {
    padding: 0 14px;
  }
  .topbar-inner {
    gap: 8px;
  }
  .brand-count,
  .kbd-hint,
  .btn-label {
    display: none;
  }
  .icon-btn {
    padding: 0 8px;
  }
  .items-grid {
    grid-template-columns: 1fr;
  }
  .row-thumb-link {
    width: 68px;
    height: 44px;
  }
  .rule-create-grid {
    grid-template-columns: 1fr;
  }
  .field-row {
    flex-direction: column;
  }
  .filter-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .scope-segmented {
    align-self: flex-start;
  }
  .drop-meta-row {
    flex-wrap: wrap;
  }
}
