:root {
    --primary-color: #5e7ce2;
    --background-color: #f5f7fa;
    --card-bg: #ffffff;
    --text-main: #333333;
    --text-sub: #999999;
    --border-radius: 16px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --padding-page: 20px;
    --bottom-nav-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-x pan-y; /* 禁止双击和捏合缩放，只保留滚动 */
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior-y: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-main);
    padding-bottom: calc(var(--bottom-nav-height) + 20px);
    user-select: none; /* 防止长按选中文本 */
    -webkit-user-select: none; /* Safari/Chrome */
    overflow-y: auto; /* 允许内部滚动 */
    -webkit-overflow-scrolling: touch; /* 增强 iOS 滚动流畅度 */
}

/* 允许输入框和文本域选中文本，否则无法编辑 */
input, textarea {
    user-select: auto;
    -webkit-user-select: auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px var(--padding-page);
    background-color: var(--background-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 24px;
    font-weight: bold;
}

.add-btn {
    font-size: 24px;
    color: var(--primary-color);
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Room Filter */
.room-tabs {
    display: flex;
    overflow-x: auto;
    padding: 0 var(--padding-page) 10px;
    gap: 15px;
    scrollbar-width: none; /* Firefox */
}

.room-tabs::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.room-tab {
    padding: 8px 16px;
    background: #fff;
    border-radius: 20px;
    font-size: 14px;
    color: var(--text-sub);
    white-space: nowrap;
    transition: all 0.3s;
    cursor: pointer;
}

.room-tab.active {
    background: var(--primary-color);
    color: #fff;
    font-weight: 500;
    box-shadow: 0 4px 8px rgba(94, 124, 226, 0.3);
}

/* 分享设备特殊房间样式 */
.room-tab.share-room-tab {
    background: #fff;
    color: #ff9500;
    border: 1px solid #ff9500;
    margin-right: 25px; /* 进一步增加间隔，与正常房间拉开 */
    position: relative;
}

/* 在分享设备标签右侧增加一条分割线效果（可选，为了视觉上更明显的“拉开”） */
.room-tab.share-room-tab::after {
    content: '';
    position: absolute;
    right: -13px;
    top: 25%;
    height: 50%;
    width: 1px;
    background: #ddd;
}

.room-tab.share-room-tab.active {
    background: #ff9500;
    color: #fff;
    border: none;
    box-shadow: 0 4px 8px rgba(255, 149, 0, 0.3);
}

/* Device Grid */
.device-grid {
    display: grid;
    /* 动态列数：最小宽度140px，自动填充 */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding: 10px var(--padding-page);
}

.device-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    /* 移除固定高度，使用宽高比保持形状 */
    aspect-ratio: 1.1; 
    min-height: 120px; /* 防止内容过多时溢出 */
    position: relative;
    transition: transform 0.2s;
    cursor: pointer;
}

.device-card:active {
    transform: scale(0.98);
}

/* Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.device-card.animate-in, .tweet-card.animate-in, .device-option.animate-in {
    animation: fadeInUp 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.device-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #f5f7fa; /* 使用浅灰色/白色背景，增加辨识度 */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px; /* 适中的图标大小 */
    border: 1px solid rgba(0,0,0,0.02); /* 极细的边框增加层次感 */
}

.device-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e6f7ff;
    color: var(--primary-color);
}

.card-content {
    margin-top: 15px;
}

.device-name {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-status {
    font-size: 12px;
    color: var(--text-sub);
}

/* Add Device Page Layout */
.add-device-container {
    display: flex;
    height: calc(100vh - 80px); /* Subtract header height */
    overflow: hidden;
}

.sidebar {
    width: 100px;
    background: #f5f7fa;
    overflow-y: auto;
    border-right: 1px solid #eee;
}

.sidebar-item {
    padding: 20px 10px;
    text-align: center;
    font-size: 14px;
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.3s;
}

.sidebar-item.active {
    background: #fff;
    color: var(--primary-color);
    font-weight: bold;
    border-left: 3px solid var(--primary-color);
}

.content-area {
    flex: 1;
    background: #fff;
    padding: 20px;
    overflow-y: auto;
}

.category-title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 20px;
}

.device-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 20px;
}

.device-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.device-option-icon {
    width: 60px;
    height: 60px;
    background: #f5f7fa;
    border-radius: 50%; /* 圆形 */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.2s;
}

.device-option:active .device-option-icon {
    background: #e6f7ff;
    color: var(--primary-color);
}

.device-option-name {
    font-size: 12px;
    color: var(--text-main);
    text-align: center;
}

/* Success Modal Styles */
.topic-display {
    background: #f5f7fa;
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
    word-break: break-all;
    font-family: monospace;
    font-size: 16px;
    text-align: center;
    border: 1px dashed #ccc;
}

.copy-hint {
    font-size: 12px;
    color: var(--text-sub);
    text-align: center;
    margin-bottom: 20px;
}
/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottom-nav-height);
    background: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    color: var(--text-sub);
    gap: 4px;
    cursor: pointer;
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-icon {
    font-size: 20px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: flex-end; /* 底部弹出 */
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #fff;
    width: 100%;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 30px 20px;
    transform: translateY(100%);
    transition: transform 0.3s;
}

.modal-overlay.show .modal-content {
    transform: translateY(0);
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-sub);
}

.form-control {
    width: 100%;
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    background: #f9f9f9;
}

.form-control:focus {
    border-color: var(--primary-color);
    background: #fff;
}

/* 自定义下拉框样式 */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 4L6 8L10 4' stroke='%23999999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    padding-right: 35px; /* 给箭头留出空间 */
    background-color: #f9f9f9;
}

select.form-control:focus {
    background-color: #fff;
    border-color: var(--primary-color);
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 25px;
}

.btn {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: none;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

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

/* Toast Notification */
.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.toast {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    margin-bottom: 10px;
    opacity: 0;
    transform: scale(0.9);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
    max-width: 80vw;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: scale(1);
}

/* Share Modal Styles */
.share-list-container {
    margin-top: 20px;
}

.share-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 12px;
    margin-top: 10px;
}

.share-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f5f5f5;
}

.share-item:last-child {
    border-bottom: none;
}

.share-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.share-email {
    font-size: 14px;
    color: var(--text-main);
    word-break: break-all;
}

.share-time {
    font-size: 11px;
    color: var(--text-sub);
}

.delete-share-btn {
    color: #ff4d4f;
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid #ff4d4f;
    border-radius: 4px;
    cursor: pointer;
}

.delete-share-btn:active {
    background: #fff1f0;
}

.action-item:active {
    background: #f9f9f9;
}
