/* App edit window */
.app-edit-modal {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
    overflow: auto;
}

.app-edit-main {
    display: grid;
    grid-template-columns: 176px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
    /* Keep the icon card inside this row. With flex:1/min-height:0 the row
       shrank after more settings were added and the card overlapped them. */
    flex: 0 0 auto;
}

.app-edit-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.app-edit-meta-section {
    padding-right: 4px;
}

.app-edit-label {
    font-size: 13px;
    color: var(--text-dim);
}

.app-edit-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.app-edit-name,
.app-edit-slug,
.app-edit-icon-prompt,
.app-edit-domain-input {
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.app-edit-name:focus,
.app-edit-slug:focus,
.app-edit-icon-prompt:focus,
.app-edit-domain-input:focus {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.app-edit-icon-prompt {
    min-height: 144px;
    resize: vertical;
    line-height: 1.4;
}

.app-edit-url-preview {
    margin-top: -8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-dim);
}

.app-edit-url-preview span {
    color: var(--text);
}

.app-edit-magic {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.app-edit-magic:hover {
    border-color: var(--border-hover);
    color: var(--text);
    background: var(--bg-secondary);
}

.app-edit-magic:disabled {
    cursor: default;
    opacity: 0.7;
}

.app-edit-magic.is-loading svg {
    opacity: 0;
}

.app-edit-magic.is-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

/* No-auth toggle card — matches the Telegram export card, iOS-style switch */
.app-edit-toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.app-edit-toggle-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .app-edit-toggle-row:hover {
    background: rgba(0, 0, 0, 0.03);
}

.app-edit-toggle-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

[data-theme="light"] .app-edit-toggle-icon {
    background: rgba(0, 0, 0, 0.05);
}

.app-edit-toggle-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-edit-toggle-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.app-edit-toggle-desc {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.app-edit-toggle-warn {
    display: none;
    align-items: flex-start;
    gap: 5px;
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.35;
    color: #e0900a;
}

[data-theme="light"] .app-edit-toggle-warn {
    color: #b26a00;
}

.app-edit-toggle-warn.is-visible {
    display: flex;
}

.app-edit-toggle-warn svg {
    flex-shrink: 0;
    margin-top: 1px;
}

/* iOS-style toggle switch */
.ios-switch {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    position: relative;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
    border-radius: 31px;
    background: #39393d;
    cursor: pointer;
    transition: background 0.25s ease;
}

[data-theme="light"] .ios-switch {
    background: #e9e9ea;
}

.ios-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
    transition: transform 0.25s ease;
}

.ios-switch:checked {
    background: #34c759;
}

.ios-switch:checked::after {
    transform: translateX(20px);
}

.app-edit-icon-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.app-edit-icon-button:hover {
    border-color: var(--border-hover);
    background: var(--bg-secondary);
    transform: translateY(-1px);
}

.app-edit-icon-change {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.app-edit-icon-preview {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.app-edit-icon-preview-main {
    width: 140px;
    height: 140px;
    border-radius: 28px;
}

.app-edit-icon-preview-large {
    width: 220px;
    height: 220px;
    border-radius: 40px;
    justify-self: center;
}

.app-edit-icon-img,
.app-edit-icon-fallback {
    width: 100%;
    height: 100%;
    border-radius: inherit;
}

.app-edit-icon-img {
    object-fit: cover;
    display: block;
}

.app-edit-icon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: 54px;
    font-weight: 700;
}

.app-edit-icon-preview-large .app-edit-icon-fallback {
    font-size: 76px;
}

.app-edit-icon-preview.is-loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    z-index: 1;
}

.app-edit-icon-preview.is-loading::after {
    content: '';
    position: absolute;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.32);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    z-index: 2;
}

.app-edit-icon-editor {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
    height: 100%;
}

.app-edit-icon-header {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.app-edit-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    padding: 0 10px 0 7px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}

.app-edit-back:hover {
    border-color: var(--border-hover);
    background: var(--bg-secondary);
}

.app-edit-icon-heading {
    min-width: 0;
}

.app-edit-icon-title {
    color: var(--text);
    font-size: 16px;
    font-weight: 650;
}

.app-edit-icon-subtitle {
    margin-top: 2px;
    color: var(--text-dim);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-edit-icon-editor-body {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
    min-height: 0;
}

.app-edit-icon-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.app-edit-generate,
.app-edit-icon-save {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}

.app-edit-icon-save {
    border-color: transparent;
    background: var(--accent);
    color: #fff;
}

.app-edit-generate:hover:not(:disabled) {
    border-color: var(--border-hover);
    background: var(--bg-secondary);
}

.app-edit-icon-save:hover:not(:disabled) {
    opacity: 0.9;
}

.app-edit-generate:disabled,
.app-edit-icon-save:disabled {
    opacity: 0.55;
    cursor: default;
}

.app-edit-icon-status {
    min-height: 16px;
    font-size: 12px;
    color: var(--text-dim);
}

.app-edit-icon-status.is-error {
    color: var(--danger, #ff453a);
}

.app-edit-domain-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: 12px;
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.app-edit-domain-entry:hover {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .app-edit-domain-entry:hover {
    background: rgba(0, 0, 0, 0.03);
}

.app-edit-domain-entry-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(70, 130, 255, 0.13);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-edit-domain-entry-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-edit-domain-entry-name {
    font-size: 14px;
    font-weight: 600;
}

.app-edit-domain-entry-desc {
    margin-top: 2px;
    color: var(--text-dim);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-edit-domain-entry-status {
    color: var(--text-dim);
    font-size: 11px;
    white-space: nowrap;
}

.app-edit-domain-entry-status.is-active {
    color: #30d158;
}

.app-edit-domain-editor {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
}

.app-edit-domain-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 610px;
    width: 100%;
    margin: 0 auto;
}

.app-edit-domain-intro,
.app-edit-domain-hint {
    margin: 0;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.45;
}

.app-edit-domain-form {
    display: flex;
    gap: 10px;
}

.app-edit-domain-form-panel {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-tertiary);
}

.app-edit-domain-input {
    min-width: 0;
    height: 40px;
    box-sizing: border-box;
}

.app-edit-domain-attach,
.app-edit-domain-verify {
    border: none;
    border-radius: 10px;
    min-height: 40px;
    padding: 9px 16px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.app-edit-domain-attach:disabled,
.app-edit-domain-verify:disabled {
    cursor: default;
    opacity: 0.55;
}

.app-edit-domain-message {
    min-height: 0;
    color: var(--text-dim);
    font-size: 12px;
}

.app-edit-domain-message:not(:empty) {
    margin-top: 10px;
}

.app-edit-domain-message.is-error,
.app-edit-domain-server-error {
    color: var(--danger, #ff453a);
}

.app-edit-domain-status {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 7px;
    border-radius: 999px;
    padding: 5px 9px;
    background: rgba(255, 159, 10, 0.12);
    color: #ff9f0a;
    font-size: 12px;
    font-weight: 600;
}

.app-edit-domain-status span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.app-edit-domain-status.is-active {
    background: rgba(48, 209, 88, 0.12);
    color: #30d158;
}

.app-edit-domain-status.is-error {
    background: rgba(255, 69, 58, 0.12);
    color: var(--danger, #ff453a);
}

.app-edit-domain-connected-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 15px;
    border: 1px solid rgba(48, 209, 88, 0.2);
    border-radius: 14px;
    background: rgba(48, 209, 88, 0.055);
}

.app-edit-domain-connected-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(48, 209, 88, 0.14);
    color: #30d158;
}

.app-edit-domain-connected-info {
    min-width: 0;
}

.app-edit-domain-connected-name {
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-edit-domain-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    margin-top: 4px;
    overflow: hidden;
    color: var(--accent);
    font-size: 12px;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-edit-domain-link:hover {
    text-decoration: underline;
}

.app-edit-domain-link svg {
    flex-shrink: 0;
}

.app-edit-domain-dns-title {
    margin-top: 2px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.app-edit-domain-record {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
}

.app-edit-domain-record-title {
    margin-bottom: 9px;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.app-edit-domain-record-grid {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 7px 10px;
    padding-right: 62px;
    align-items: baseline;
}

.app-edit-domain-record-grid span {
    color: var(--text-dim);
    font-size: 11px;
}

.app-edit-domain-record-grid code {
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    overflow-wrap: anywhere;
}

.app-edit-domain-copy {
    position: absolute;
    right: 10px;
    top: 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 8px;
    background: var(--bg-secondary);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
}

.app-edit-domain-server-error {
    border-radius: 9px;
    padding: 9px 11px;
    background: rgba(255, 69, 58, 0.09);
    font-size: 12px;
    line-height: 1.4;
}

.app-edit-domain-remove {
    flex-shrink: 0;
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid rgba(255, 69, 58, 0.34);
    border-radius: 10px;
    background: rgba(255, 69, 58, 0.11);
    color: var(--danger, #ff453a);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.app-edit-domain-remove:hover:not(:disabled) {
    border-color: var(--danger, #ff453a);
    background: var(--danger, #ff453a);
    color: #fff;
}

.app-edit-domain-remove:disabled {
    cursor: default;
    opacity: 0.55;
}

.app-edit-domain-danger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 15px;
    border: 1px solid rgba(255, 69, 58, 0.2);
    border-radius: 14px;
    background: rgba(255, 69, 58, 0.045);
}

.app-edit-domain-danger-copy {
    min-width: 0;
}

.app-edit-domain-danger-title {
    color: var(--danger, #ff453a);
    font-size: 13px;
    font-weight: 650;
}

.app-edit-domain-danger-desc {
    max-width: 370px;
    margin-top: 4px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.4;
}

.app-edit-domain-loading {
    padding: 24px 0;
    color: var(--text-dim);
    font-size: 13px;
}

/* Telegram export card — mirrors the .int-item design from the integrations window */
.app-edit-tg-export {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: 12px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.app-edit-tg-export:hover {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .app-edit-tg-export:hover {
    background: rgba(0, 0, 0, 0.03);
}

.app-edit-tg-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: #229ED9;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-edit-tg-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-edit-tg-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.app-edit-tg-desc {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.app-edit-tg-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.5;
}

.app-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 2px;
}

.app-edit-save {
    min-width: 128px;
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s;
}

.app-edit-save:hover:not(:disabled) {
    opacity: 0.9;
}

.app-edit-save:disabled {
    opacity: 0.5;
    cursor: default;
}

.app-edit-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: rgba(30, 30, 30, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 4px;
    z-index: 100;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.app-edit-suggestion-message {
    padding: 8px 10px;
    color: rgba(255, 255, 255, 0.72);
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
}

.app-edit-suggestions.is-error {
    border-color: rgba(255, 69, 58, 0.36);
}

.app-edit-suggestion-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.app-edit-suggestion-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

@media (max-width: 799px) {
    .app-edit-modal {
        padding: 16px;
    }

    .app-edit-main,
    .app-edit-icon-editor-body {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .app-edit-meta-section {
        padding-right: 0;
    }

    .app-edit-icon-button {
        max-width: 180px;
        justify-self: center;
    }

    .app-edit-icon-preview-main {
        width: 132px;
        height: 132px;
        border-radius: 26px;
    }

    .app-edit-icon-preview-large {
        width: 156px;
        height: 156px;
        border-radius: 30px;
    }

    .app-edit-icon-preview-large .app-edit-icon-fallback {
        font-size: 56px;
    }

    .app-edit-actions,
    .app-edit-save {
        width: 100%;
    }

    .app-edit-domain-form {
        flex-direction: column;
    }

    .app-edit-domain-attach {
        width: 100%;
    }

    .app-edit-domain-connected-card {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .app-edit-domain-connected-card .app-edit-domain-status {
        grid-column: 2;
        justify-self: start;
    }

    .app-edit-domain-danger {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .app-edit-domain-danger-desc {
        max-width: none;
    }

    .app-edit-domain-remove {
        width: 100%;
    }

    .app-edit-domain-entry-status {
        display: none;
    }
}
