:root {
  /* Dark theme — Catppuccin Macchiato */
  --bg: #24273a;           /* Base */
  --bg-secondary: #1e2030; /* Mantle */
  --bg-tertiary: #2b2f47;  /* between Base and Surface 0 */
  --border: #494d64;       /* Surface 1 */
  --text: #b8c0e0;         /* Subtext 1 (softer than Text) */
  --text-muted: #8087a2;   /* Overlay 1 (softer muted) */
  --accent: #8aadf4;       /* Blue */
  --success: #a6da95;      /* Green */
  --error: #ed8796;        /* Red */
  --font-mono: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  --font-sans: "Source Sans Pro", "Microsoft Yahei", sans-serif;
  --font-heading: "Lato", "Microsoft Yahei", sans-serif;
  --radius: 6px;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Light theme — Catppuccin Latte */
    --bg: #eff1f5;           /* Base */
    --bg-secondary: #e6e9ef; /* Mantle */
    --bg-tertiary: #e6e9ef;  /* Mantle (closer to Base) */
    --border: #bcc0cc;       /* Surface 1 */
    --text: #5c5f77;         /* Subtext 1 (softer than Text) */
    --text-muted: #8c8fa1;   /* Overlay 1 (softer muted) */
    --accent: #1e66f5;       /* Blue */
    --success: #40a02b;      /* Green */
    --error: #d20f39;        /* Red */
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid var(--bg);
  border-radius: 6px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
}

header h1 span {
  color: var(--accent);
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  overflow-y: auto;
  padding: 16px 20px;
}
.panel-left {
  border-right: 1px solid var(--border);
}
.panel-history {
  border-right: 1px solid var(--border);
  background: var(--bg-secondary);
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
}

.history-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.history-empty {
  font-size: 13px;
  color: var(--text-muted);
}
.history-io {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.history-io .btn-add {
  text-align: center;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--bg-tertiary);
}
.history-item:hover,
.history-item.selected {
  border-color: var(--accent);
}
.history-item .history-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-msg {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  min-height: 1em;
}
.save-msg.error {
  color: var(--error);
}
#btn-save {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--bg);
  font-weight: 600;
}
#btn-save:hover:not(:disabled) {
  filter: brightness(1.1);
}
#btn-save:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#btn-copy:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#section-save {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
#save-notes,
#save-response {
  margin-top: 8px;
  min-height: 140px;
  font-size: 14px;
}
#save-name {
  width: 100%;
  font-size: 14px;
}

.section {
  margin-bottom: 14px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.host-port-row {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="search"],
textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

#hostname-input {
  flex: 1;
  min-width: 0;
}

#port-input {
  flex-shrink: 0;
  width: 80px;
}

.credentials-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius);
  flex-shrink: 0;
  transition:
    color 0.15s,
    background 0.15s;
}
.btn-remove:hover {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 10%, transparent);
}

.btn-add {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 5px 10px;
  margin-top: 6px;
  transition:
    border-color 0.15s,
    color 0.15s;
  width: 100%;
  text-align: left;
}
.btn-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

textarea.body-input {
  width: 100%;
  min-height: 100px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 16px;
}

#command-preview {
  width: 100%;
  min-height: 140px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 10px;
  resize: vertical;
  outline: none;
  white-space: pre;
  overflow-x: auto;
}

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

.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 16px;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.btn-copy {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-copy:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-copy.copied {
  color: var(--success);
  border-color: var(--success);
}

.hidden {
  display: none !important;
}

/* ── Mode badge and warnings ─────────────────────────────────────────────── */

.mode-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  margin-left: 6px;
  text-transform: none;
  letter-spacing: 0;
}

.warn-note {
  font-size: 12px;
  color: var(--error);
  margin-top: 6px;
  min-height: 1em;
}

/* ── Options panel ─────────────────────────────────────────────────────── */

.opts-search {
  width: 100%;
  margin-bottom: 8px;
  /* search icon — Macchiato Subtext 0 (#a5adcb) */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a5adcb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 9px center;
  padding-left: 30px !important;
}

.opts-search::-webkit-search-cancel-button {
  display: none;
}

@media (prefers-color-scheme: light) {
  /* search icon — Latte Subtext 0 (#6c6f85) */
  .opts-search {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236c6f85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  }
}

.opts-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--bg-secondary);
}

.opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  min-height: 28px;
  transition: background 0.1s;
}
.opt-row:hover {
  background: var(--bg-tertiary);
}
.opt-row.opt-checked {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.opt-row.opt-checked:hover {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.opt-row.opt-dimmed {
  opacity: 0.4;
}
.opt-row.opt-dimmed .opt-label {
  cursor: default;
}

/* Custom checkbox */
.opt-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: var(--bg-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
  position: relative;
  transition:
    background 0.1s,
    border-color 0.1s;
}
.opt-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.opt-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 5px;
  height: 8px;
  border: 1.5px solid var(--bg);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}
.opt-row input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.opt-row.opt-dimmed input[type="checkbox"] {
  cursor: not-allowed;
}

.opt-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
/* The flag is the identifier; the label and argument support it. */
.opt-desc {
  color: var(--text-muted);
}
.opt-arg {
  color: var(--accent);
}
.opt-row.opt-dimmed .opt-desc,
.opt-row.opt-dimmed .opt-arg {
  color: inherit;
}
.opt-value-input {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 6px;
  height: 22px;
  width: 110px;
  flex-shrink: 0;
}

.opt-info-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: help;
  font-size: 11px;
  font-weight: 600;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  flex-shrink: 0;
  line-height: 1;
  opacity: 0.7;
  transition:
    opacity 0.1s,
    color 0.1s,
    border-color 0.1s,
    background 0.1s;
}
.opt-info-btn:hover {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ── Modal ─────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 55%);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

.modal-title {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
}

.modal-protocols {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.modal-help {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  margin-bottom: 12px;
}

.modal-examples {
  margin-top: 10px;
}

.modal-examples-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-example {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  padding: 8px 10px;
  margin-bottom: 6px;
  white-space: pre;
  overflow-x: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius);
  transition: color 0.15s;
}
.modal-close:hover {
  color: var(--text);
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  vertical-align: center;
  font-size: 15px;
  color: var(--text-muted);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover {
  text-decoration: underline;
}
