/* Captain Claw — Browser Workflows */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --orange: #f78166;
    --purple: #bc8cff;
    --radius: 8px;
    --radius-sm: 6px;
    --header-height: 48px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ─── Header ──────────────────────────────────────────── */

.bw-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.bw-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bw-header-left h1 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.bw-logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.bw-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bw-nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.bw-nav-link:hover {
    color: var(--accent);
    background: var(--bg-tertiary);
}

/* ─── Layout ──────────────────────────────────────────── */

.bw-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* ─── List Panel ──────────────────────────────────────── */

.bw-list-panel {
    width: 360px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.bw-list-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.bw-search {
    flex: 1;
    padding: 7px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.bw-search:focus { border-color: var(--accent); }
.bw-search::placeholder { color: var(--text-muted); }

.bw-filter-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.bw-count {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 1px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.bw-item-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.bw-item-list::-webkit-scrollbar { width: 6px; }
.bw-item-list::-webkit-scrollbar-track { background: transparent; }
.bw-item-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

.bw-loading {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.bw-list-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.bw-list-empty-sub {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.7;
}

.bw-list-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent;
}

.bw-list-item:hover { background: var(--bg-hover); }

.bw-list-item.selected {
    background: var(--bg-tertiary);
    border-left-color: var(--accent);
}

.bw-list-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bw-list-item-desc {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bw-list-item-badges {
    display: flex;
    gap: 6px;
    margin-top: 2px;
    flex-wrap: wrap;
}

/* ─── Badges ──────────────────────────────────────────── */

.bw-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.bw-badge.app    { background: #58a6ff15; color: var(--accent); border: 1px solid #58a6ff25; }
.bw-badge.steps  { background: #3fb95020; color: var(--green); border: 1px solid #3fb95030; }
.bw-badge.vars   { background: #d2992220; color: var(--yellow); border: 1px solid #d2992230; }
.bw-badge.uses   { background: #bc8cff15; color: var(--purple); border: 1px solid #bc8cff25; }

/* ─── Detail Panel ────────────────────────────────────── */

.bw-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.bw-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
}

.bw-empty-icon { font-size: 48px; opacity: 0.5; }
.bw-empty-text { font-size: 14px; }
.bw-empty-sub  { font-size: 12px; opacity: 0.7; }

.bw-detail-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bw-detail-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-secondary);
    gap: 16px;
}

.bw-detail-header-info {
    flex: 1;
    min-width: 0;
}

.bw-detail-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bw-detail-meta {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.bw-detail-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.bw-detail-content {
    flex: 1;
    overflow-y: auto;
    padding: 4px 20px 20px;
}

.bw-detail-content::-webkit-scrollbar { width: 6px; }
.bw-detail-content::-webkit-scrollbar-track { background: transparent; }
.bw-detail-content::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

/* Sections */
.bw-section {
    margin-top: 16px;
}

.bw-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.bw-section-value {
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-word;
    line-height: 1.6;
}

.bw-section-value.empty {
    color: var(--text-muted);
    font-style: italic;
}

/* Steps table */
.bw-steps-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.bw-steps-table th {
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
}

.bw-steps-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: top;
}

.bw-steps-table tr:hover td {
    background: var(--bg-hover);
}

.bw-step-action {
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.bw-step-selector {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bw-step-value {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--orange);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bw-step-value.is-var {
    color: var(--yellow);
    font-weight: 600;
}

/* Variables table */
.bw-vars-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.bw-vars-table th {
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.bw-vars-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.bw-var-name {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--yellow);
}

/* Field rows */
.bw-field-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.bw-field-label {
    width: 110px;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    padding-top: 2px;
}

.bw-field-value {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-word;
    min-width: 0;
}

.bw-field-value.empty {
    color: var(--text-muted);
    font-style: italic;
}

.bw-field-value a {
    color: var(--accent);
    text-decoration: none;
}

.bw-field-value a:hover {
    text-decoration: underline;
}

/* ─── Buttons ─────────────────────────────────────────── */

.bw-btn {
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.15s;
    white-space: nowrap;
}

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

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

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

.bw-btn.secondary:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.bw-btn.danger {
    background: transparent;
    color: var(--red);
    border-color: var(--border);
}

.bw-btn.danger:hover {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.bw-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.bw-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.bw-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 360px;
    max-width: 480px;
}

.bw-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.bw-modal-body {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

.bw-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Toast ───────────────────────────────────────────── */

.bw-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-primary);
    z-index: 1001;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.bw-toast.show { opacity: 1; transform: translateY(0); }
.bw-toast.success { border-color: var(--green); }
.bw-toast.error   { border-color: var(--red); }

/* ─── Step Editor ─────────────────────────────────────── */

.bw-edit-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    overflow: hidden;
}

.bw-edit-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.bw-edit-card-num {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.bw-edit-card-actions {
    display: flex;
    gap: 4px;
}

.bw-edit-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: var(--font);
}

.bw-edit-action-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.bw-edit-action-btn.remove:hover {
    color: var(--red);
    border-color: var(--red);
}

.bw-edit-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 12px;
}

.bw-edit-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bw-edit-field.full {
    grid-column: 1 / -1;
}

.bw-edit-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
}

.bw-edit-input,
.bw-edit-select {
    padding: 5px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
    width: 100%;
}

.bw-edit-input:focus,
.bw-edit-select:focus {
    border-color: var(--accent);
}

.bw-edit-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.bw-edit-select {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

.bw-add-step {
    width: 100%;
    margin-top: 8px;
    text-align: center;
    border-style: dashed;
    padding: 8px;
    font-size: 12px;
}

/* ─── Responsive ──────────────────────────────────────── */

@media (max-width: 768px) {
    .bw-layout { flex-direction: column; }
    .bw-list-panel {
        width: 100%;
        min-width: unset;
        max-height: 260px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}
