/* ===== Custom Workspace Dropdown (top bar) ===== */

.ws-dropdown {
  position: relative;
  display: inline-block;
}

.ws-dropdown-trigger {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}
.ws-dropdown-trigger:hover {
  background: var(--chip-bg);
}
.ws-dropdown-trigger .chevron {
  font-size: 10px;
  color: var(--text-dim);
}
.ws-trigger-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}
.ws-trigger-base {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ws-trigger-name {
  font-size: 13px;
  font-weight: 600;
}

.ws-dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 1000;
  overflow: hidden;
  padding: 4px 0;
}

.ws-dropdown-group + .ws-dropdown-group .ws-dropdown-item:first-child {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 12px;
}

.ws-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s ease;
}
.ws-dropdown-item + .ws-dropdown-item {
  border-top: 1px solid var(--border);
}
.ws-dropdown-item:hover {
  background: var(--chip-bg);
}
.ws-dropdown-item.base {
  font-weight: 600;
  font-size: 13px;
}
.ws-dropdown-item.child {
  justify-content: flex-end;
  padding-left: 36px;
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text);
}
.ws-dropdown-item.selected {
  background: var(--accent-subtle);
  color: var(--accent);
}
.ws-dropdown-item .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ws-dropdown-item .check {
  flex-shrink: 0;
  min-width: 12px;
  text-align: center;
  font-size: 11px;
  color: var(--accent);
  opacity: 0.9;
}
.ws-dropdown-item.base .check {
  margin-left: auto;
}

/* ===== Workspaces page (workspaces.js) =====
 * Colours, radii and shadows come from the shared classes in ui.css
 * (.ui-panel, .badge, .field, the ws-btn-* buttons and .ws-tab) and the
 * tokens in base.css, so both themes apply as is. */

.workspaces-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
/* Width, padding and the title come from page.css (.page, .page-title). */
.ws-page {
  display: flex; flex-direction: column; gap: 16px;
}

/* Heading and the tab's create buttons */
.ws-page-head { margin-bottom: 10px; }
.ws-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Tabs with counts, and the filter */
.ws-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ws-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ws-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  border: none; background: transparent;
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.ws-tab-count { color: var(--text-dim); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ws-tab-count:empty { display: none; }
.ws-tab.active .ws-tab-count { color: inherit; }
.ws-filter { position: relative; flex: 1 1 200px; max-width: 320px; margin-left: auto; }
.ws-filter[hidden] { display: none; }
.ws-filter svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); pointer-events: none;
}
.ws-filter .field { box-sizing: border-box; padding-left: 36px; font-size: 14px; }

.ws-content { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ws-items { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ws-loading, .ws-no-match { margin: 0; color: var(--text-dim); font-size: 14px; overflow-wrap: anywhere; }
.ws-load-error {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  color: var(--error); font-size: 13px; overflow-wrap: anywhere;
}

/* Cards */
.ws-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.ws-item {
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px 20px;
  border: 1px solid;
  min-width: 0;
}
.ws-item[hidden] { display: none; }
.ws-item-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ws-item-name {
  flex: 1; min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 15px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-item-name.mono, .ws-form-title .mono {
  font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13.5px;
}
.ws-item-type { flex-shrink: 0; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.ws-item-meta { margin: 0; color: var(--text-dim); font-size: 13px; }
.ws-item-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }
.ws-btn-sm.ws-btn-secondary, .ws-btn-sm.ws-btn-danger { padding: 5px 12px; font-size: 13px; }

/* My workspaces: the built-in workspaces, then the user's custom ones. */
.ws-section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.ws-section[hidden] { display: none; }
.ws-section + .ws-section { margin-top: 10px; }
.ws-section-title {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.ws-section-count { color: var(--text-dim); font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
/* A built-in workspace's line is its Home description: two lines at most. */
.ws-builtin-card .ws-item-meta {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; line-height: 1.45;
}
/* The current workspace: the accent border and tint the picker marks it with. */
.ws-item.is-current,
.ws-item.is-current:hover {
  border-color: var(--tone-accent-ring);
  box-shadow: var(--shadow-sm), var(--glass-highlight), inset 0 0 0 1px var(--tone-accent-ring);
}
.ws-item.is-current { background-image: linear-gradient(var(--accent-subtle), var(--accent-subtle)); }
.ws-item.is-current:focus { outline: none; }
.ws-item.is-current:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ws-item-current { flex-shrink: 0; }

/* An empty tab is the shared empty state (page.css .ui-empty, empty-state.js).
 * No custom workspaces yet is its compact form: one row under the built-in
 * cards, icon, text and button side by side. */
.ws-empty-compact.ui-empty {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 16px;
  padding: 16px 20px;
  text-align: left;
}
.ws-empty-compact .ui-empty-icon {
  grid-row: 1 / span 2;
  width: 44px; height: 44px; margin: 0;
  border-radius: var(--radius-lg);
}
.ws-empty-compact .ui-empty-icon svg { width: 22px; height: 22px; }
.ws-empty-compact .ui-empty-title { grid-column: 2; font-size: 15px; font-weight: 700; letter-spacing: 0; }
.ws-empty-compact .ui-empty-text { grid-column: 2; max-width: none; font-size: 13.5px; line-height: 1.45; }
.ws-empty-compact .ui-empty-actions { grid-column: 3; grid-row: 1 / span 2; margin-top: 0; }

/* Buttons keep their size here; their colours come from ui.css. */
.ws-btn-primary,
.ws-btn-secondary,
.ws-btn-danger,
.ws-btn-success {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* Error message */
.ws-error {
  color: var(--error);
  font-size: 15px;
  overflow-wrap: anywhere;
}

/* ===== Create/Edit Form ===== */

.ws-form-back {
  font-size: 15px;
  color: var(--accent);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
  padding: 0;
  margin-bottom: 16px;
}
.ws-form-back:hover {
  text-decoration: underline;
}

.ws-form label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.ws-form input[type="text"],
.ws-form select {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.ws-form input[type="text"]:focus,
.ws-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.ws-form-field {
  margin-bottom: 16px;
}
.ws-form-field:last-of-type {
  margin-bottom: 24px;
}

/* Skill list header — label + Select all / Deselect all */
.ws-skill-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.ws-skill-list-header label {
  margin: 0;
}
.ws-skill-toggle-all {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  font-family: inherit;
}
.ws-skill-toggle-all:hover {
  text-decoration: underline;
}

/* Skill checkbox list — two-column grid to use horizontal space */
.ws-skill-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
}
.ws-skill-item {
  display: flex !important;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: normal;
  color: var(--text);
  border-radius: 4px;
  min-width: 0;
}
.ws-skill-item:hover {
  background: var(--chip-bg);
}
.ws-skill-item input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
}
.ws-skill-item > div {
  min-width: 0;
}
.ws-skill-item .skill-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-skill-item .skill-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ===== CLAUDE.md editor ===== */
.ws-claudemd-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}
.ws-claudemd-toggle input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
}
.ws-claudemd-toggle span {
  margin-left: 2px;
}
.ws-claudemd-body {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: var(--surface);
}
.ws-claudemd-body textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 240px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
  font-size: 14px;
  line-height: 1.5;
}
.ws-claudemd-body textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.ws-claudemd-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.ws-claudemd-actions button {
  font-size: 14px;
  padding: 6px 10px;
}

.ws-form-hint {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}
.ws-form-hint em {
  font-style: italic;
}

.ws-form-actions {
  display: flex;
  gap: 12px;
}

/* ===== Skill editor ===== */

.ws-form-title { margin: 0 0 4px; color: var(--text); font-size: 16px; overflow-wrap: anywhere; }
.ws-skill-editor {
  width: 100%;
  box-sizing: border-box;
  min-height: 320px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid;
  font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13.5px;
  line-height: 1.5;
}
.ws-env-line { margin: 0 0 8px; overflow-wrap: anywhere; }

/* ===== Env config modal ===== */

.env-modal {
  min-width: 460px;
  max-width: 560px;
  padding: 20px 24px;
}
.env-modal h3 {
  margin: 0 0 4px;
  font-size: 18px;
}
.env-intro {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--text-dim);
}
.env-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}
.env-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.env-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
}
.env-label code {
  font-family: var(--mono, monospace);
  font-size: 14px;
  font-weight: 600;
}
.env-desc {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.4;
}
.env-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 15px;
  font-family: var(--mono, monospace);
  color: var(--text);
}
.env-input:focus {
  outline: none;
  border-color: var(--accent, #2563eb);
}

/* ===== MCP picker badge (workspace editor) ===== */

.ws-mcp-type-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 6px;
  vertical-align: middle;
  margin-left: 4px;
}

.ws-mcp-add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.ws-mcp-add-form h4 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}
.ws-mcp-add-form textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 80px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
  font-size: 14px;
  line-height: 1.5;
}
.ws-mcp-add-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.ws-mcp-add-form input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.ws-mcp-add-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.ws-mcp-add-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.ws-mcp-preview {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ws-mcp-preview h4 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.ws-mcp-preview pre {
  margin: 4px 0 0;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
  overflow-x: auto;
  color: var(--text);
}

/* Auth section in MCP preview */
.ws-auth-section {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tone-success-text);
  border-radius: 6px;
}
.ws-auth-section.is-oauth {
  border-left-color: var(--tone-info-text);
}
.ws-auth-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
}
.ws-auth-hint {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 8px;
  line-height: 1.4;
}
.ws-auth-field {
  margin-top: 8px;
}
.ws-auth-field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}
.ws-auth-field .ws-auth-field-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 4px;
}
.ws-auth-field input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
  font-size: 14px;
}
.ws-auth-field input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Upload skill: a label around a hidden file input */
.ws-upload-label input[type="file"] {
  display: none;
}

@media (max-width: 1150px) {
  .ws-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .ws-page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .ws-page-actions > * { flex: 1; }
  .ws-toolbar { flex-direction: column; align-items: stretch; }
  .ws-tabs { justify-content: space-between; gap: 0; }
  .ws-tab { padding: 7px 8px; font-size: 13px; gap: 5px; }
  .ws-filter { max-width: none; margin-left: 0; flex-basis: auto; }
  .ws-cards { grid-template-columns: minmax(0, 1fr); }
  .ws-empty-compact.ui-empty { grid-template-columns: auto minmax(0, 1fr); padding: 14px 16px; }
  .ws-empty-compact .ui-empty-icon { grid-row: 1; width: 36px; height: 36px; }
  .ws-empty-compact .ui-empty-title { grid-row: 1; }
  .ws-empty-compact .ui-empty-text { grid-column: 1 / -1; }
  .ws-empty-compact .ui-empty-actions { grid-column: 1 / -1; grid-row: auto; margin-top: 8px; }
  .ws-empty-compact .ui-empty-actions > * { flex: 1; }
  .ws-skill-list { grid-template-columns: minmax(0, 1fr); }
  .ws-form-actions { flex-wrap: wrap; }
  .env-modal { min-width: 0; width: calc(100vw - 32px); box-sizing: border-box; }
}
