/* ============================================================================
 * mcp-ui.css — styles for the Permissions page (permissions-ui.js) and the
 * Custom tools / Custom MCP flow (mcp-ui.js). Uses the app's accent tokens
 * (--accent, --accent-soft, …) so it tracks the user's chosen theme, with
 * light motion that respects the reduce-motion preference.
 * ========================================================================== */

/* Shared entrance animation */
@keyframes mcpIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes mcpSpin { to { transform: rotate(360deg); } }
@keyframes mcpPop {
    0%   { transform: scale(0.96); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ══════════════════════════════════════════════════════════════════════════
   PERMISSIONS PAGE
   ══════════════════════════════════════════════════════════════════════════ */
.perm-page { animation: mcpIn 0.28s var(--ui-ease, ease); }
.perm-intro p {
    font-size: 13px;
    line-height: 1.55;
    color: var(--subheading-color, #8a8a8a);
    margin: 2px 2px 14px;
}
.perm-list { display: flex; flex-direction: column; gap: 12px; }

.perm-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: var(--ui-radius, 12px);
    background: var(--secondary-color, rgba(255, 255, 255, 0.02));
    transition: border-color 0.18s var(--ui-ease, ease), transform 0.18s var(--ui-ease, ease), box-shadow 0.18s var(--ui-ease, ease);
}
.perm-card:hover {
    border-color: var(--accent-ring, rgba(99, 102, 241, 0.35));
    transform: translateY(-1px);
    box-shadow: var(--ui-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.18));
}
.perm-ico {
    width: 42px; height: 42px;
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    border-radius: 11px;
    background: var(--accent-soft, rgba(99, 102, 241, 0.14));
    color: var(--accent, #b7795c);
}
.perm-ico .material-symbols-rounded { font-size: 22px; }
.perm-main { flex: 1; min-width: 0; }
.perm-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.perm-main h4 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-color); }
.perm-main p { margin: 4px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--subheading-color, #8a8a8a); }

.perm-status {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 600;
    padding: 2px 9px 2px 7px;
    border-radius: 999px;
    color: var(--subheading-color, #8a8a8a);
    background: rgba(128, 128, 128, 0.12);
}
.perm-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.perm-status.granted { color: #16a34a; background: rgba(22, 163, 74, 0.14); }
.perm-status.denied  { color: #e5484d; background: rgba(229, 72, 77, 0.14); }
.perm-status.prompt  { color: var(--accent, #b7795c); background: var(--accent-soft, rgba(99,102,241,0.14)); }
.perm-status.unsupported { opacity: 0.7; }

.perm-action { flex: 0 0 auto; display: flex; align-items: center; }
.perm-check { color: #16a34a; font-size: 24px; animation: mcpPop 0.3s var(--ui-ease, ease); }

.perm-btn {
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.14));
    background: var(--secondary-color, #2a2a2a);
    color: var(--text-color);
    height: 34px; padding: 0 15px;
    border-radius: 9px;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.14s ease, filter 0.14s ease;
}
.perm-btn:hover { transform: translateY(-1px); }
.perm-btn:active { transform: scale(0.97); }
.perm-btn:disabled { opacity: 0.6; cursor: default; }
.perm-btn.primary { background: var(--accent, #b7795c); border-color: transparent; color: var(--accent-contrast, #fff); }
.perm-btn.primary:hover { filter: brightness(1.06); }
.perm-btn.ghost { background: transparent; }

/* ══════════════════════════════════════════════════════════════════════════
   CUSTOM TOOLS / MCP
   ══════════════════════════════════════════════════════════════════════════ */
.mcp-page, .mcp-form-page { animation: mcpIn 0.28s var(--ui-ease, ease); }

.mcp-search {
    display: flex; align-items: center; gap: 8px;
    padding: 0 12px;
    height: 42px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    border-radius: 11px;
    background: var(--secondary-color, rgba(255, 255, 255, 0.03));
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.mcp-search:focus-within {
    border-color: var(--accent, #b7795c);
    box-shadow: 0 0 0 3px var(--accent-soft, rgba(99, 102, 241, 0.14));
}
.mcp-search .material-symbols-rounded { color: var(--subheading-color, #8a8a8a); font-size: 20px; }
.mcp-search input {
    flex: 1; border: none; background: transparent; outline: none;
    color: var(--text-color); font-size: 14px; font-family: inherit;
}

.mcp-section { margin-top: 22px; }
.mcp-section-label {
    font-size: 12px; font-weight: 600; letter-spacing: 0.05em;
    text-transform: uppercase; color: var(--subheading-color, #8a8a8a);
    margin: 0 2px 10px;
}
.mcp-empty { font-size: 13px; color: var(--subheading-color, #8a8a8a); text-align: center; padding: 18px; }

/* Connected list */
.mcp-conn-list { display: flex; flex-direction: column; gap: 10px; }
.mcp-conn {
    display: flex; align-items: center; gap: 12px;
    padding: 12px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: var(--ui-radius, 12px);
    background: var(--secondary-color, rgba(255, 255, 255, 0.02));
    animation: mcpIn 0.24s var(--ui-ease, ease);
}
.mcp-conn-ico, .mcp-card-ico, .mcp-form-ico {
    width: 40px; height: 40px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    border-radius: 11px;
    color: #fff;
    background: color-mix(in srgb, var(--tile, var(--accent)) 82%, black 6%);
}
/* Fallback for browsers without color-mix */
@supports not (background: color-mix(in srgb, red, blue)) {
    .mcp-conn-ico, .mcp-card-ico, .mcp-form-ico { background: var(--tile, var(--accent, #b7795c)); }
}
.mcp-conn-ico .material-symbols-rounded { font-size: 21px; }
/* Real brand logos rendered inside connector tiles (WhatsApp, Telegram, …). */
.mcp-brand-ico {
    width: 22px; height: 22px;
    border-radius: 6px;
    object-fit: contain;
    background: #fff;
    padding: 2px;
    box-sizing: border-box;
    display: block;
}
.mcp-conn-main { flex: 1; min-width: 0; }
.mcp-conn-name { font-size: 14px; font-weight: 600; color: var(--text-color); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcp-conn-meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.mcp-conn-type { font-size: 11.5px; color: var(--subheading-color, #8a8a8a); }

.mcp-state {
    font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    padding: 2px 8px; border-radius: 999px;
}
.mcp-state.on { color: #16a34a; background: rgba(22, 163, 74, 0.14); }
.mcp-state.off { color: var(--subheading-color, #8a8a8a); background: rgba(128, 128, 128, 0.14); }
.mcp-state.untested { color: #d97706; background: rgba(217, 119, 6, 0.16); }

.mcp-conn-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.mcp-icon-btn {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    border: none; background: transparent; cursor: pointer;
    border-radius: 8px; color: var(--subheading-color, #8a8a8a);
    transition: background 0.14s ease, color 0.14s ease;
}
.mcp-icon-btn:hover { background: var(--highlight-background, rgba(255, 255, 255, 0.08)); color: var(--text-color); }
.mcp-icon-btn.danger:hover { color: #e5484d; background: rgba(229, 72, 77, 0.12); }
.mcp-icon-btn .material-symbols-rounded { font-size: 19px; }

/* Toggle switch (matches scheduler switch) */
.mcp-switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; margin-left: 4px; }
.mcp-switch input { opacity: 0; width: 0; height: 0; }
.mcp-switch span { position: absolute; inset: 0; background: rgba(128, 128, 128, 0.35); border-radius: 22px; transition: 0.2s var(--ui-ease, ease); }
.mcp-switch span::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s var(--ui-ease, ease); }
.mcp-switch input:checked + span { background: var(--accent, #b7795c); }
.mcp-switch input:checked + span::before { transform: translateX(16px); }
.mcp-switch input:disabled + span { opacity: 0.45; cursor: not-allowed; }

/* Gallery — responsive grid that always measures against the full panel
   width. Cards are box-sized so padding never forces a column overflow. */
.mcp-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
    width: 100%;
    min-width: 0;
}
@media (max-width: 560px) {
    .mcp-gallery { grid-template-columns: 1fr; }
}
.mcp-card {
    display: flex;
    align-items: center;
    gap: 13px;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
    padding: 13px 14px;
    border: 1px solid transparent;
    border-radius: var(--ui-radius, 12px);
    background: var(--secondary-color, rgba(255, 255, 255, 0.03));
    cursor: pointer;
    font-family: inherit;
    transition: background 0.16s var(--ui-ease, ease), border-color 0.16s var(--ui-ease, ease);
}
.mcp-card:hover {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.07));
    border-color: var(--accent-ring, rgba(183, 121, 92, 0.35));
}
.mcp-card:active { background: var(--secondary-hover-color, rgba(255, 255, 255, 0.1)); }
.mcp-card-ico { width: 40px; height: 40px; flex: 0 0 auto; }
.mcp-card-ico .material-symbols-rounded { font-size: 21px; }
.mcp-card-body {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.mcp-card-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mcp-card-name {
    font-size: 14px; font-weight: 600; color: var(--text-color);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.mcp-card-tag {
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--accent, #b7795c); background: var(--accent-soft, rgba(183, 121, 92, 0.14));
    padding: 1px 7px; border-radius: 999px;
    flex: 0 0 auto; white-space: nowrap;
}
.mcp-card-blurb {
    font-size: 12px; line-height: 1.45; color: var(--subheading-color, #8a8a8a);
    overflow-wrap: anywhere;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mcp-card-add {
    align-self: center; flex: 0 0 auto; font-size: 20px; color: var(--subheading-color, #8a8a8a);
    opacity: 0; transform: translateX(-4px); transition: opacity 0.16s ease, transform 0.16s ease, color 0.16s ease;
}
.mcp-card:hover .mcp-card-add { opacity: 1; transform: translateX(0); color: var(--accent, #b7795c); }

/* Form view */
.mcp-form-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.mcp-back {
    width: 34px; height: 34px; flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    border: none; background: transparent; cursor: pointer;
    border-radius: 50%; color: var(--subheading-color, #8a8a8a);
    transition: background 0.14s ease;
}
.mcp-back:hover { background: var(--highlight-background, rgba(255, 255, 255, 0.08)); color: var(--text-color); }
.mcp-form-ico { width: 40px; height: 40px; }
.mcp-form-ico .material-symbols-rounded { font-size: 21px; }
.mcp-form-titles { min-width: 0; }
.mcp-form-title { font-size: 16px; font-weight: 600; color: var(--text-color); }
.mcp-form-sub { font-size: 12.5px; color: var(--subheading-color, #8a8a8a); margin-top: 2px; line-height: 1.4; }

.mcp-note {
    display: flex; gap: 10px; align-items: flex-start;
    font-size: 12.5px; line-height: 1.5;
    padding: 11px 13px; border-radius: 11px; margin-bottom: 16px;
    background: var(--accent-soft, rgba(99, 102, 241, 0.12));
    color: var(--text-color);
    border: 1px solid var(--accent-ring, rgba(99, 102, 241, 0.28));
}
.mcp-note.warn { background: rgba(217, 119, 6, 0.12); border-color: rgba(217, 119, 6, 0.3); }
.mcp-note .material-symbols-rounded { font-size: 19px; color: var(--accent, #b7795c); flex: 0 0 auto; margin-top: 1px; }
.mcp-note.warn .material-symbols-rounded { color: #d97706; }

.mcp-form { display: flex; flex-direction: column; gap: 14px; }
.mcp-field { display: flex; flex-direction: column; gap: 6px; }
/* Checkbox row: box on the left, label + hint stacked to its right. */
.mcp-field-check { flex-direction: row; align-items: flex-start; gap: 10px; cursor: pointer; }
.mcp-field-check input[type="checkbox"] { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; accent-color: var(--accent-color, #25D366); cursor: pointer; }
.mcp-field-check .mcp-check-text { display: flex; flex-direction: column; gap: 4px; }
.mcp-field-label { font-size: 12.5px; font-weight: 600; color: var(--text-color); }
.mcp-opt { font-weight: 500; font-size: 11px; color: var(--subheading-color, #8a8a8a); text-transform: none; }
.mcp-field-hint { font-size: 11.5px; color: var(--subheading-color, #8a8a8a); line-height: 1.4; }
.mcp-field input, .mcp-field select, .mcp-field textarea,
.mcp-picker select {
    width: 100%;
    font-size: 14px; font-family: inherit;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.14));
    background: var(--secondary-color, rgba(255, 255, 255, 0.03));
    color: var(--text-color);
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.mcp-field textarea { resize: vertical; min-height: 68px; }
.mcp-field input:focus, .mcp-field select:focus, .mcp-field textarea:focus,
.mcp-picker select:focus {
    outline: none;
    border-color: var(--accent, #b7795c);
    box-shadow: 0 0 0 3px var(--accent-soft, rgba(99, 102, 241, 0.14));
}

.mcp-picker { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.mcp-picker-row { display: flex; gap: 8px; align-items: stretch; }
.mcp-picker-row select { flex: 1; }

.mcp-test-result {
    display: flex; align-items: center; gap: 9px;
    font-size: 12.5px; line-height: 1.45;
    padding: 11px 13px; border-radius: 11px; margin-top: 14px;
    animation: mcpIn 0.2s var(--ui-ease, ease);
}
.mcp-test-result .material-symbols-rounded { font-size: 19px; flex: 0 0 auto; }
.mcp-test-result.pending { background: var(--accent-soft, rgba(99,102,241,0.12)); color: var(--text-color); }
.mcp-test-result.ok { background: rgba(22, 163, 74, 0.14); color: #16a34a; }
.mcp-test-result.fail { background: rgba(229, 72, 77, 0.14); color: #e5484d; }
.mcp-test-result .spin { animation: mcpSpin 0.9s linear infinite; }

.mcp-form-actions {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin-top: 20px; padding-top: 16px;
    border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}
.mcp-form-actions-right { display: flex; gap: 10px; margin-left: auto; }
.mcp-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.14));
    background: var(--secondary-color, #2a2a2a);
    color: var(--text-color);
    height: 38px; padding: 0 16px;
    border-radius: 10px;
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.14s ease, filter 0.14s ease, opacity 0.14s ease;
}
.mcp-btn .material-symbols-rounded { font-size: 18px; }
.mcp-btn:hover { transform: translateY(-1px); }
.mcp-btn:active { transform: scale(0.98); }
.mcp-btn.small { height: 42px; padding: 0 13px; }
.mcp-btn.ghost { background: transparent; }
.mcp-btn.primary { background: var(--accent, #b7795c); border-color: transparent; color: var(--accent-contrast, #fff); }
.mcp-btn.primary:hover { filter: brightness(1.06); }
.mcp-btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.mcp-btn.busy { position: relative; color: transparent; }
.mcp-btn.busy::after {
    content: ""; position: absolute; top: 50%; left: 50%;
    width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px;
    border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; color: var(--accent-contrast, #fff);
    animation: mcpSpin 0.7s linear infinite;
}
.mcp-btn.ghost.busy::after { color: var(--text-color); }

@media (max-width: 640px) {
    .mcp-gallery { grid-template-columns: 1fr; }
    .mcp-form-actions { flex-direction: column-reverse; align-items: stretch; }
    .mcp-form-actions-right { margin-left: 0; }
    .mcp-btn { justify-content: center; width: 100%; }
}

/* ── Legacy modal CSS isolation ──────────────────────────────────────────────
   The older modal stylesheet styles every <button> as a 100px blue control.
   Custom-tool cards and actions must remain independent of that generic rule. */
.data-window .content .mcp-gallery {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
}
.data-window .content button.mcp-card {
    display: flex !important;
    align-items: center !important;
    gap: 13px !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 88px;
    padding: 13px 14px !important;
    text-align: left !important;
    border: 1px solid transparent !important;
    border-radius: var(--ui-radius, 12px) !important;
    background: var(--secondary-color, rgba(255,255,255,0.03)) !important;
    color: var(--text-color) !important;
    box-shadow: none !important;
    transform: none !important;
}
.data-window .content button.mcp-card:hover {
    background: var(--secondary-hover-color, rgba(255,255,255,0.07)) !important;
    border-color: var(--accent-ring, rgba(183,121,92,0.35)) !important;
}
.data-window .content .mcp-card-body { flex: 1 1 auto !important; min-width: 0 !important; }
.data-window .content .mcp-card-top { min-width: 0 !important; }
.data-window .content .mcp-card-name { min-width: 0 !important; color: var(--text-color) !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; }
.data-window .content .mcp-card-blurb { color: var(--subheading-color, #8a8a8a) !important; overflow-wrap: normal !important; word-break: normal !important; }

.data-window .content button.mcp-icon-btn,
.data-window .content button.mcp-back {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 9px !important;
    background: transparent !important;
    color: var(--subheading-color, #8a8a8a) !important;
    box-shadow: none !important;
    transform: none !important;
}
.data-window .content button.mcp-icon-btn:hover,
.data-window .content button.mcp-back:hover { background: var(--secondary-hover-color, rgba(255,255,255,0.07)) !important; color: var(--text-color) !important; }
.data-window .content button.mcp-btn {
    width: auto !important;
    min-width: 0 !important;
    height: 38px !important;
    padding: 0 16px !important;
    border: 1px solid var(--border-color, rgba(255,255,255,0.14)) !important;
    border-radius: 10px !important;
    background: var(--secondary-color, rgba(255,255,255,0.04)) !important;
    color: var(--text-color) !important;
    box-shadow: none !important;
    transform: none !important;
}
.data-window .content button.mcp-btn.ghost { background: transparent !important; }
.data-window .content button.mcp-btn.primary { background: var(--accent, #b7795c) !important; border-color: transparent !important; color: var(--accent-contrast, #fff) !important; }

@media (max-width: 560px) {
    .data-window .content .mcp-gallery { grid-template-columns: 1fr !important; }
}
