/* All elements transitions for smooth theme switching */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

/* Smooth transitions for theme switching */
header,
.room-section,
.devices-section,
.queue-section,
.device-card,
.modal-content,
.drop-zone-content,
.toast,
.btn,
input {
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

/* Light theme variables */
:root[data-theme="light"] {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #2196F3;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.1);
    --body-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --modal-bg: rgba(0, 0, 0, 0.5);
    --drop-zone-bg: rgba(0, 0, 0, 0.8);
}

/* Dark theme variables (default) */
:root {
    --primary-color: #66BB6A;
    --primary-dark: #4CAF50;
    --secondary-color: #42A5F5;
    --danger-color: #ef5350;
    --warning-color: #FFA726;
    --bg-color: #2d2d3e;
    --card-bg: #363648;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #484860;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.5);
    --body-gradient: linear-gradient(135deg, #1c0e42 0%, #353557 100%);
    --modal-bg: rgba(20, 20, 30, 0.8);
    --drop-zone-bg: rgba(20, 20, 30, 0.95);
}

/* Common variables */
:root {
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--body-gradient);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning-color);
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--primary-color);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.device-name-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s;
    color: var(--text-primary);
}

.device-name-btn:hover {
    background: var(--bg-color);
    border-color: var(--primary-color);
}

.device-name-btn svg {
    stroke: currentColor;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Theme Switcher */
.theme-switcher {
    position: relative;
    width: 60px;
    height: 30px;
    background: var(--border-color);
    border-radius: 15px;
    cursor: pointer;
    transition: background 0.3s;
    border: 1px solid var(--border-color);
}

.theme-switcher:hover {
    background: var(--bg-color);
}

.theme-switcher-toggle {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: var(--card-bg);
    border-radius: 50%;
    transition: transform 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

[data-theme="dark"] .theme-switcher-toggle {
    transform: translateX(0);
}

[data-theme="light"] .theme-switcher-toggle {
    transform: translateX(30px);
}

.theme-icon {
    width: 14px;
    height: 14px;
    fill: var(--text-primary);
}

.theme-icon.sun {
    display: none;
}

.theme-icon.moon {
    display: block;
}

[data-theme="light"] .theme-icon.sun {
    display: block;
}

[data-theme="light"] .theme-icon.moon {
    display: none;
}

/* Room Section */
.room-section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.room-description {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.room-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    max-width: 400px;
    margin: 0 auto;
}

.room-input-group {
    display: flex;
    gap: 12px;
    width: 100%;
}

.room-input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 2px;
    font-weight: 600;
    background: var(--card-bg);
    color: var(--text-primary);
}

.room-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.room-divider {
    position: relative;
    width: 100%;
    text-align: center;
    margin: 8px 0;
}

.room-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-color);
}

.room-divider span {
    position: relative;
    padding: 0 16px;
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid var(--primary-color);
    border-radius: var(--radius);
}

.room-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.room-code {
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: 1px;
    color: var(--primary-color);
}

.icon-btn {
    padding: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--primary-color);
    transition: opacity 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    opacity: 0.7;
}

/* Devices Section */
.devices-section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: scaleX(0);
    transition: transform 0.3s;
}

.device-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.device-card:hover::before {
    transform: scaleX(1);
}

.device-card.active {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.1), rgba(33, 150, 243, 0.1));
    cursor: pointer;
}

.device-card.active:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.device-card.active::after {
    content: '';
    position: absolute;
    /* top corner: the bottom holds the Verify button */
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    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='white' stroke-width='2'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'%3E%3C/path%3E%3Cpolyline points='17 8 12 3 7 8'%3E%3C/polyline%3E%3Cline x1='12' y1='3' x2='12' y2='15'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
}

.device-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    padding: 12px;
    background: var(--card-bg);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}

.device-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.device-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.locality-badge.remote {
    opacity: 0.8;
}

/* Connected, but files can't go to this device (not local / it refuses) */
.device-status.warning,
.device-card.active .device-status.warning {
    color: var(--warning-color);
}

.device-card.no-send::after {
    display: none;
}

/* Connection verification */
.verify-btn {
    margin-top: 10px;
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
}
.verify-btn:hover {
    border-color: var(--secondary-color);
}
.verify-btn.verified {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.verify-btn.failed {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.verify-content {
    max-width: 420px;
    text-align: center;
}
.verify-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.verify-content h3 {
    margin-bottom: 0;
}
.verify-peer {
    margin: 8px 0 16px;
    color: var(--text-secondary);
    text-align: left;
}
.verify-code {
    font-family: 'SF Mono', 'Fira Code', Menlo, Consolas, monospace;
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 6px;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--bg-color);
    user-select: text;
}
.verify-text {
    margin: 16px 0 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.verify-mismatch {
    color: var(--danger-color);
}

.no-devices {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px;
    color: var(--text-secondary);
}

.no-devices svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-devices p {
    margin-bottom: 8px;
}

.no-devices small {
    display: block;
    margin-top: 4px;
}

.mobile-hint {
    color: var(--primary-color);
    font-weight: 500;
    margin-top: 12px !important;
}

/* Drop Zone */
.drop-zone {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--drop-zone-bg);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s;
}

.drop-zone.hidden {
    display: none;
}

.drop-zone-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 48px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.drop-zone-content svg {
    margin-bottom: 2px;
    color: var(--primary-color);
}

.drop-zone-content h3 {
    margin-bottom: 8px;
}

.drop-zone-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.preview-area {
    margin: 24px 0;
    max-height: 300px;
    overflow-y: auto;
}

.file-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius);
    margin-bottom: 8px;
    text-align: left;
}

.file-preview img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
}

.file-preview-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    border-radius: 4px;
}

.file-info {
    flex: 1;
}

.file-name {
    font-weight: 500;
    margin-bottom: 4px;
    word-break: break-word;
}

.file-size {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.drop-zone-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.drop-zone.drag-active {
    background: rgba(76, 175, 80, 0.9);
}

.drop-zone.drag-active .drop-zone-content {
    border: 2px dashed var(--primary-color);
    transform: scale(1.02);
}

.btn svg {
    margin-right: 8px;
    vertical-align: middle;
}

/* Transfer Queue */
.queue-section {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

.transfer-item {
    background: var(--bg-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.transfer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.transfer-info {
    flex: 1;
}

.transfer-filename {
    font-weight: 600;
    margin-bottom: 4px;
}

.transfer-details {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.transfer-speed {
    font-size: 0.75rem;
    color: var(--primary-color);
    margin-top: 4px;
    font-weight: 500;
}

.transfer-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.transfer-status.sending {
    background: rgba(33, 150, 243, 0.1);
    color: var(--secondary-color);
}

.transfer-status.receiving {
    background: rgba(76, 175, 80, 0.1);
    color: var(--primary-color);
}

.transfer-status.completed {
    background: rgba(76, 175, 80, 0.1);
    color: var(--primary-color);
}

.transfer-status.failed {
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger-color);
}

.transfer-status.paused {
    background: rgba(255, 152, 0, 0.1);
    color: var(--warning-color);
}

.transfer-status.confirming {
    background: rgba(33, 150, 243, 0.1);
    color: var(--secondary-color);
}

.transfer-status.cancelled {
    background: var(--border-color);
    color: var(--text-secondary);
}

/* Long status labels ("waiting for receiver") shouldn't squeeze the file name */
.transfer-status {
    white-space: nowrap;
    flex-shrink: 0;
}

.progress-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 0 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.transfer-actions {
    display: flex;
    gap: 8px;
}

.transfer-actions button {
    padding: 4px 8px;
    font-size: 0.875rem;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.transfer-actions button:hover {
    color: var(--primary-color);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--card-bg);
    border-color: var(--primary-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-bg);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-bottom: 24px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    margin-bottom: 24px;
    background: var(--bg-color);
    color: var(--text-primary);
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary-color);
}

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

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
}

.toast {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--primary-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

.toast.info {
    border-left: 4px solid var(--secondary-color);
}

/* Drag states */
.device-card.drag-over {
    border-color: var(--primary-color);
    background: rgba(76, 175, 80, 0.1);
    transform: scale(1.05);
}

body.dragging .device-card {
    transition: all 0.3s;
}

body.dragging .device-card:not(.drag-over) {
    opacity: 0.5;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .container {
        padding: 12px;
        /* room to scroll the last items out from under the shared-text button */
        padding-bottom: 88px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .devices-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .drop-zone-content {
        padding: 32px 24px;
    }
    
    /* Larger touch targets for mobile */
    .device-card {
        padding: 24px 20px;
        min-height: 140px;
    }
    
    .device-card.active {
        position: relative;
    }
    
    .device-card.active .device-status {
        font-weight: 600;
        color: var(--primary-color);
    }
    
    /* Better file selection on mobile */
    .btn {
        min-height: 44px;
        font-size: 0.95rem;
    }
    
    .drop-zone-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .drop-zone-actions .btn {
        width: 100%;
    }
    
    /* Compact header controls on mobile */
    .status-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    /* Room code gets its own row; LAN only, name and theme share the next one */
    .header-controls {
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 10px;
    }

    .header-controls .room-info {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .header-controls .theme-switcher {
        margin-left: auto;
        flex-shrink: 0;
    }

    .device-name-btn span {
        display: none;
    }
    
    .device-name-btn {
        padding: 8px;
    }
}

/* Phones: device cards become compact full-width rows —
   icon | name + status | Verify. Tall centered tiles waste the screen in
   one column and squeeze the text in two. */
@media (max-width: 480px) {
    .devices-section,
    .queue-section {
        padding: 16px;
    }

    .devices-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .device-card {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "icon name   action"
            "icon status action";
        column-gap: 12px;
        align-items: center;
        text-align: left;
        min-height: 0;
        padding: 12px 14px;
    }

    .device-card:hover,
    .device-card.active:hover {
        transform: none;
    }

    .device-card .device-icon {
        grid-area: icon;
        width: 40px;
        height: 40px;
        padding: 8px;
        margin: 0;
    }

    .device-card .device-icon svg {
        width: 24px;
        height: 24px;
    }

    .device-card .device-name {
        grid-area: name;
        display: flex;
        align-items: center;
        gap: 4px;
        min-width: 0;
        margin: 0;
    }

    .device-name-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .device-card .device-status {
        grid-area: status;
        font-size: 0.8rem;
        line-height: 1.3;
    }

    .device-card .verify-btn {
        grid-area: action;
        margin: 0;
        white-space: nowrap;
    }

    /* The status line already says "Click to send files" */
    .device-card.active::after {
        display: none;
    }
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Version footer */
.app-version {
    text-align: center;
    padding: 16px 0 12px;
    font-size: 0.7em;
    color: var(--text-secondary, #666);
    opacity: 0.5;
    letter-spacing: 0.5px;
}

.app-version a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.app-version a:hover {
    color: var(--primary-color);
    border-bottom-style: solid;
}

/* Locality verification */
.locality-badge {
    font-size: 0.75em;
    margin-left: 4px;
}

.locality-badge.verified {
    color: #4caf50;
}

.locality-badge.confirmed {
    color: #ff9800;
}

.locality-badge.blocked {
    color: #f44336;
}

.locality-dialog {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.locality-dialog-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.locality-dialog-content {
    position: relative;
    background: var(--bg-secondary, #1e1e2e);
    color: var(--text-primary, #fff);
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.locality-dialog-content h3 {
    margin-bottom: 12px;
    color: #ff9800;
}

.locality-dialog-content p {
    margin-bottom: 20px;
    line-height: 1.5;
    font-size: 0.9em;
}

.locality-dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.locality-btn-cancel,
.locality-btn-confirm {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9em;
}

.locality-btn-cancel {
    background: var(--bg-tertiary, #333);
    color: var(--text-primary, #fff);
}

.locality-btn-confirm {
    background: #ff9800;
    color: #000;
}

/* ─────────────────────────────────────────────
   Shared Text (shared clipboard)
   ───────────────────────────────────────────── */

/* Floating action button */
.shared-text-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 1500;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.shared-text-fab:hover {
    background: var(--primary-dark);
    transform: translateY(-2px) scale(1.05);
}
.shared-text-fab:active {
    transform: scale(0.96);
}
/* Subtle dot when other devices are present/typing */
.shared-text-fab.has-activity::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--secondary-color);
    border: 2px solid var(--primary-color);
}

/* Modal layout — wider than the default modal for a code editor */
.text-share-content {
    max-width: 820px;
    width: 92%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px;
}

.ts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.ts-header h3 {
    margin: 0;
    font-size: 1.2rem;
}
.ts-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto; /* title | … | controls | close */
}
.ts-close {
    flex-shrink: 0;
}
.ts-select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}
/* LAN-only switch */
.ts-lan-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.ts-lan-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.ts-lan-slider {
    position: relative;
    width: 34px;
    height: 20px;
    border-radius: 10px;
    background: var(--border-color);
    transition: background 0.2s;
    flex-shrink: 0;
}
.ts-lan-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
}
.ts-lan-toggle input:checked + .ts-lan-slider {
    background: var(--primary-color);
}
.ts-lan-toggle input:checked + .ts-lan-slider::after {
    transform: translateX(14px);
}
.ts-lan-toggle input:checked ~ .ts-lan-label {
    color: var(--primary-color);
}
.ts-lan-toggle input:focus-visible + .ts-lan-slider {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

.ts-hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Editor: transparent textarea overlaid on a highlighted <pre> layer */
.ts-editor {
    position: relative;
    height: 52vh;
    min-height: 240px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--code-bg, #1e1e2e);
}
.ts-highlight,
.ts-editor textarea {
    margin: 0;
    padding: 14px 16px;
    border: 0;
    width: 100%;
    height: 100%;
    font-family: 'SF Mono', 'Fira Code', Menlo, Consolas, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}
.ts-highlight {
    position: absolute;
    inset: 0;
    overflow: auto;
    pointer-events: none;
    background: transparent;
    color: var(--code-fg, #cdd6f4);
}
.ts-highlight code {
    font: inherit;
    background: transparent;
    padding: 0;
    display: block;
    white-space: inherit;
    word-break: inherit;
}
.ts-editor textarea {
    position: absolute;
    inset: 0;
    resize: none;
    background: transparent;
    color: transparent;
    caret-color: var(--code-fg, #cdd6f4);
    overflow: auto;
    outline: none;
}
.ts-editor textarea::placeholder {
    color: var(--text-secondary);
}
.ts-editor textarea::selection {
    background: rgba(120, 150, 255, 0.35);
}

/* Plain mode: for very large text we skip the highlight overlay and show the
   textarea text directly, so the editor stays responsive. */
.ts-editor.plain .ts-highlight {
    display: none;
}
.ts-editor.plain textarea {
    color: var(--code-fg);
    caret-color: var(--code-fg);
}

.ts-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.ts-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.ts-status.saving { color: var(--warning-color); }
.ts-status.synced { color: var(--primary-color); }
.ts-status.remote { color: var(--secondary-color); }
.ts-actions {
    display: flex;
    gap: 10px;
}
.ts-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

@media (max-width: 600px) {
    .text-share-content { padding: 18px; }
    .ts-header { flex-wrap: wrap; }
    /* Toasts above the shared-text button instead of on top of it */
    .toast-container { bottom: 84px; right: 16px; left: 16px; }
    .toast { min-width: 0; }
    .ts-editor { height: 46vh; }
    .shared-text-fab { right: 16px; bottom: 16px; }
}

/* Phones: the shared-text dialog becomes a full-screen sheet. The title and
   close button stay on the first row, the LAN only switch and language on the
   second, the editor takes all remaining height, Copy/Clear span the width. */
@media (max-width: 495px) {
    #textShareModal {
        align-items: stretch;
    }
    .text-share-content {
        width: 100%;
        max-width: none;
        height: 100vh;
        height: 100dvh; /* excludes the mobile browser's toolbars */
        margin: 0;
        border-radius: 0;
        padding: 14px 14px max(14px, env(safe-area-inset-bottom));
        gap: 10px;
    }
    .ts-header {
        flex-wrap: wrap;
        row-gap: 10px;
    }
    .ts-header h3 {
        flex: 1;
        order: 1;
    }
    .ts-close {
        order: 2;
    }
    .ts-controls {
        order: 3;
        flex-basis: 100%;
        margin-left: 0;
        justify-content: space-between;
    }
    .ts-hint {
        font-size: 0.75rem;
    }
    .ts-editor {
        flex: 1;
        height: auto;
        min-height: 160px;
    }
    .ts-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .ts-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* ── Editor surface + syntax token colors (theme-aware, self-contained) ── */
:root {
    --code-bg: #f6f8fa;
    --code-fg: #24292e;
}
[data-theme="dark"] {
    --code-bg: #1e1e2e;
    --code-fg: #cdd6f4;
}

/* Light theme tokens */
.hljs-comment, .hljs-quote { color: #6a737d; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag { color: #d73a49; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #032f62; }
.hljs-number, .hljs-symbol, .hljs-bullet { color: #005cc5; }
.hljs-title, .hljs-section, .hljs-name { color: #6f42c1; }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: #e36209; }
.hljs-type, .hljs-class .hljs-title, .hljs-built_in, .hljs-builtin-name { color: #22863a; }
.hljs-tag { color: #22863a; }
.hljs-deletion { color: #b31d28; }
.hljs-meta { color: #6a737d; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* Dark theme tokens (Catppuccin-ish, matches dark editor surface) */
[data-theme="dark"] .hljs-comment,
[data-theme="dark"] .hljs-quote { color: #9399b2; }
[data-theme="dark"] .hljs-keyword,
[data-theme="dark"] .hljs-selector-tag,
[data-theme="dark"] .hljs-literal,
[data-theme="dark"] .hljs-doctag { color: #cba6f7; }
[data-theme="dark"] .hljs-string,
[data-theme="dark"] .hljs-regexp,
[data-theme="dark"] .hljs-addition { color: #a6e3a1; }
[data-theme="dark"] .hljs-number,
[data-theme="dark"] .hljs-symbol,
[data-theme="dark"] .hljs-bullet { color: #fab387; }
[data-theme="dark"] .hljs-title,
[data-theme="dark"] .hljs-section,
[data-theme="dark"] .hljs-name { color: #89b4fa; }
[data-theme="dark"] .hljs-attr,
[data-theme="dark"] .hljs-attribute,
[data-theme="dark"] .hljs-variable,
[data-theme="dark"] .hljs-template-variable { color: #f9e2af; }
[data-theme="dark"] .hljs-type,
[data-theme="dark"] .hljs-built_in,
[data-theme="dark"] .hljs-builtin-name { color: #94e2d5; }
[data-theme="dark"] .hljs-tag { color: #94e2d5; }
[data-theme="dark"] .hljs-deletion { color: #f38ba8; }
[data-theme="dark"] .hljs-meta { color: #9399b2; }

/* iOS Safari zooms the whole page into any focused field whose text is
   smaller than 16px (and stays zoomed). On phones/tablets every text field
   gets 16px; the editor's highlight layer must match its textarea exactly. */
@media (max-width: 768px), (pointer: coarse) {
    input[type="text"],
    select,
    textarea,
    .ts-select,
    .ts-highlight,
    .ts-editor textarea {
        font-size: 16px;
    }
}
