:root {
    --bg: #09090b;
    --surface: #111113;
    --card: #18181b;
    --card-hover: #1f1f23;
    --border: #27272a;
    --border-hover: #3f3f46;
    --accent: #3b82f6;
    --accent-hover: #4a8af7;
    --accent-dim: rgba(59,130,246,0.1);
    --text: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --nav-height: 52px;
    --transition: cubic-bezier(0.16,1,0.3,1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app-layout {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 640px;
    margin: 0 auto;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

/* ── Scrollbar ── */
.content::-webkit-scrollbar { width: 4px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9999px; }

/* ── Navbar ── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: var(--nav-height);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
}

.nav-brand svg { color: var(--accent); }

/* ── Status Badge ── */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px 4px 8px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--surface);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: background 0.3s;
}

.status-badge.connected .status-dot { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.4); }
.status-badge.connected { border-color: rgba(34,197,94,0.25); color: var(--success); }
.status-badge.connecting .status-dot { background: var(--warning); animation: pulse 1s infinite; }
.status-badge.connecting { border-color: rgba(245,158,11,0.25); color: var(--warning); }

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

/* ── Section Header ── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0 12px;
    flex-shrink: 0;
}

.section-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.section-desc {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ── Badge ── */
.badge {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 2px 10px;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 600;
}

/* ── Devices Section ── */
.devices-section {
    flex-shrink: 0;
}

.peers-grid {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
}

.peers-grid::-webkit-scrollbar { display: none; }

.peer-card {
    flex-shrink: 0;
    width: 72px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s var(--transition);
    position: relative;
}

.peer-card:hover { border-color: var(--accent); background: var(--card-hover); }
.peer-card:active { transform: scale(0.95); }

.peer-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.peer-name {
    font-size: 0.65rem;
    font-weight: 500;
    text-align: center;
    color: var(--text-tertiary);
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.peer-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--card);
}
.peer-badge.online { background: var(--success); }
.peer-badge.connecting { background: var(--warning); }
.peer-badge.offline { background: var(--text-tertiary); }

/* ── Empty State ── */
.empty-state {
    min-width: 160px;
    text-align: center;
    padding: 20px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.empty-state p {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* ── Activity Feed ── */
.feed-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.activity-feed {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 8px;
}

.activity-feed::-webkit-scrollbar { width: 3px; }
.activity-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 9999px; }

.feed-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feed-placeholder p {
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

/* ── Feed Items ── */
.feed-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    animation: slideIn 0.25s var(--transition);
    transition: background 0.2s;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.feed-item:active { background: var(--card); }

.feed-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.feed-body {
    flex: 1;
    min-width: 0;
}

.feed-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.feed-peer {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.feed-time {
    font-size: 0.6rem;
    color: var(--text-tertiary);
}

.feed-text {
    font-size: 0.85rem;
    color: var(--text);
    word-break: break-word;
    line-height: 1.4;
}

/* Image preview in feed */
.feed-img-wrapper {
    margin-top: 6px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    max-height: 240px;
    background: var(--card);
    cursor: pointer;
}

.feed-img-wrapper img {
    width: 100%;
    height: auto;
    max-height: 240px;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s;
}

/* Image fullscreen overlay */
.img-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(9,9,11,0.95);
    backdrop-filter: blur(16px);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

.img-overlay img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
    object-fit: contain;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* File item in feed */
.feed-file {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    padding: 8px 10px;
    background: var(--card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
}

.feed-file:active { background: var(--card-hover); }

.feed-file-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent);
}

.feed-file-info {
    flex: 1;
    min-width: 0;
}

.feed-file-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-file-size {
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

.feed-file-dl {
    color: var(--accent);
    flex-shrink: 0;
}

/* ── Input Section ── */
.input-section {
    flex-shrink: 0;
    padding: 10px 16px 16px;
    border-top: 1px solid var(--border);
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.input-container textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 100px;
    padding: 4px 6px;
}

.input-container textarea::placeholder {
    color: var(--text-tertiary);
}

.input-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    align-items: flex-end;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.action-btn:hover { background: var(--card); color: var(--text-secondary); }
.action-btn:active { transform: scale(0.9); }

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

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

/* ── Toast ── */
#toast-container,
.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    pointer-events: none;
    max-width: 320px;
    width: calc(100% - 32px);
}

.toast {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.8rem;
    color: var(--text);
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    animation: toastIn 0.3s var(--transition) forwards;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.toast-success { border-color: rgba(34,197,94,0.3); }
.toast.toast-error { border-color: rgba(239,68,68,0.3); }

.toast-icon {
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 700;
}
.toast-success .toast-icon { background: rgba(34,197,94,0.2); color: var(--success); }
.toast-error .toast-icon { background: rgba(239,68,68,0.2); color: var(--error); }

@keyframes toastIn {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Progress Overlay ── */
.upload-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(9,9,11,0.85);
    backdrop-filter: blur(8px);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 280px;
    text-align: center;
}

.progress-card h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
    word-break: break-word;
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: var(--surface);
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 9999px;
    width: 0%;
    transition: width 0.2s var(--transition);
}

.progress-card p { font-size: 0.75rem; color: var(--text-tertiary); }

/* ── Drop Zone ── */
.drop-zone {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(9,9,11,0.92);
    backdrop-filter: blur(12px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px;
    border: 2px dashed var(--accent);
    border-radius: 24px;
}

.drop-content p {
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
}

.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 380px) {
    .peer-card { width: 64px; padding: 10px 6px 8px; }
}
