:root {
  --bg: #f4f7fb;
  --bg-soft: #eef2f8;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --accent: #e87933;
  --accent-soft: rgba(232, 121, 51, 0.15);
  --shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  --success: #0f9a5d;
  --danger: #dc2626;
  --radius: 16px;
  --term-grid: rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #0f172a;
  --surface: rgba(17, 24, 39, 0.8);
  --surface-strong: #101827;
  --text: #e2e8f0;
  --muted: #9aa9c2;
  --border: rgba(148, 163, 184, 0.24);
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --primary-soft: rgba(96, 165, 250, 0.15);
  --accent: #fb923c;
  --accent-soft: rgba(251, 146, 60, 0.22);
  --shadow: 0 18px 44px rgba(2, 6, 23, 0.55);
  --success: #22c55e;
  --danger: #ef4444;
  --term-grid: rgba(148, 163, 184, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Mono", "SFMono-Regular", "Menlo", "Consolas", "PingFang SC", monospace;
  color: var(--text);
  background:
    repeating-linear-gradient(0deg, transparent 0 25px, var(--term-grid) 25px 26px),
    linear-gradient(160deg, var(--bg), var(--bg-soft));
  padding: 16px;
}

.container {
  width: min(1240px, 100%);
  margin: 0 auto;
}

.top-bar,
.panel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.top-bar::before,
.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  display: block;
  border-bottom: 1px solid var(--border);
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  background: var(--surface-strong);
  pointer-events: none;
}

.top-bar::after,
.panel::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 16px 0 0 #eab308, 32px 0 0 var(--success);
  opacity: 0.9;
  pointer-events: none;
}

.top-bar {
  padding: 40px 16px 16px;
  margin-bottom: 10px;
}

.brand-block {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

.brand h1 {
  margin: 0;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: clamp(1.35rem, 1.1rem + 1vw, 2rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.brand p::before {
  content: "$ ";
  color: var(--primary);
}

.time-box {
  border: 0;
  background: transparent;
  min-width: 156px;
  padding: 0;
  text-align: right;
}

.time {
  font-weight: 600;
  font-size: clamp(1.2rem, 1.04rem + 0.65vw, 1.6rem);
  line-height: 1;
  letter-spacing: 0.02em;
}

.date {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.global-status {
  min-height: 18px;
  margin-top: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 10px;
  align-items: start;
}

main,
aside {
  min-width: 0;
}

.panel {
  padding: 40px 16px 16px;
}

.search-panel {
  z-index: 8;
  overflow: visible;
}

.sites-panel {
  margin-top: 10px;
}

.section-title {
  margin: 0 0 10px;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
  font-size: 0.98rem;
  letter-spacing: 0.01em;
}

.section-title::before {
  content: "> ";
  color: var(--primary);
}

.hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.hint strong {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-weight: 500;
  background: var(--surface-strong);
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
}

input,
button,
select {
  font: inherit;
}

input[type="text"],
input[type="url"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 10px 11px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
.engine-trigger:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.search-form {
  display: grid;
  grid-template-columns: 1fr 210px auto;
  gap: 10px;
  align-items: end;
}

.engine-field {
  position: relative;
  min-width: 0;
}

.engine-trigger {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}

.engine-trigger:hover {
  border-color: var(--primary);
}

.engine-trigger-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.engine-trigger-icon,
.engine-option-icon {
  width: 20px;
  height: 20px;
  border-radius: 2px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
}

.engine-trigger-icon img,
.engine-option-icon img {
  width: 14px;
  height: 14px;
  display: block;
}

.engine-trigger-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.engine-trigger-text::before {
  content: "> ";
  color: var(--primary);
}

.engine-caret {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.engine-trigger.is-open .engine-caret {
  transform: rotate(180deg);
}

.engine-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 220;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 4px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
  max-height: 260px;
  overflow: auto;
}

.engine-option {
  border: 0;
  width: 100%;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 6px;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.engine-option:hover,
.engine-option.is-selected {
  background: var(--primary-soft);
}

.engine-option-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.engine-option-meta {
  min-width: 0;
}

.engine-option-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.engine-option-name::before {
  content: "> ";
  color: var(--primary);
}

.engine-option-check {
  color: var(--primary);
  font-weight: 700;
  opacity: 0;
}

.engine-option.is-selected .engine-option-check {
  opacity: 1;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.btn-danger {
  border-color: rgba(220, 38, 38, 0.32);
  color: var(--danger);
}

.btn-danger:hover {
  border-color: rgba(220, 38, 38, 0.48);
  background: rgba(220, 38, 38, 0.1);
}

.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.status {
  min-height: 20px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.sites-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.sites-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.live-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 0.76rem;
  white-space: nowrap;
}

.badge span {
  color: var(--text);
  font-weight: 600;
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.site-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-strong);
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.site-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.site-card.dragging {
  opacity: 0.55;
}

.site-card.drop-target {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px var(--primary-soft);
}

.site-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  padding: 10px;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--primary-soft);
  display: grid;
  place-items: center;
  color: var(--primary);
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: 600;
  flex: 0 0 auto;
}

.avatar img {
  width: 16px;
  height: 16px;
  display: block;
}

.meta {
  min-width: 0;
}

.site-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-title::before {
  content: "~/";
  color: var(--primary);
}

.site-host {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.side-stack {
  display: grid;
  gap: 10px;
}

.control-panel {
  z-index: 3;
}

.block-title {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
}

.control-block + .control-block {
  margin-top: 12px;
}

.control-divider {
  height: 1px;
  margin-top: 12px;
  background: var(--border);
}

.form-row {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tool-actions {
  margin-top: 0;
}

.tool-actions .btn {
  min-width: 102px;
}

.manager-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 3px;
  margin-bottom: 8px;
}

.mode-btn {
  border: 0;
  border-radius: 6px;
  padding: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.is-active {
  background: var(--primary);
  color: #fff;
}

.manager-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.site-picker-wrap {
  margin-bottom: 10px;
}

.picker-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.site-picker {
  display: grid;
  gap: 6px;
  max-height: 156px;
  overflow: auto;
}

.picker-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  text-align: left;
  padding: 7px 9px;
  display: grid;
  gap: 2px;
  cursor: pointer;
}

.picker-item:hover,
.picker-item.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.picker-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.86rem;
}

.picker-host {
  color: var(--muted);
  font-size: 0.76rem;
  word-break: break-all;
}

.picker-empty {
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--surface-strong);
}

.engine-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

.engine-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 8px 9px;
  font-size: 0.84rem;
}

.engine-item small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  word-break: break-all;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  font: inherit;
}

.link-btn:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    padding: 10px;
  }

  .brand-block {
    flex-direction: column;
    align-items: stretch;
  }

  .time-box {
    width: 100%;
    text-align: left;
    margin-top: 4px;
  }

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

  .site-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  }

  .tool-actions .btn {
    min-width: 0;
    flex: 1 1 calc(50% - 8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
