/* 灰豚平台 - 全站响应式适配（手机 / 平板 / 桌面） */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* 触控区域不小于 44px */
button,
.tab,
.page-btn,
.toggle-btn,
.toolbar button,
.search-btn,
.mobile-card-actions button {
    min-height: 44px;
    touch-action: manipulation;
}

input,
select,
.search-input {
    font-size: 16px; /* 避免 iOS 输入时自动放大 */
}

img {
    max-width: 100%;
    height: auto;
}

/* ---------- 管理后台 index / lights ---------- */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-left {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.toolbar-left > select,
.toolbar-left > button,
.toolbar-left > .search-container,
.toolbar-left > #doorButtons,
.toolbar-left > #lightsToolbar {
    margin-left: 0 !important;
}

.door-buttons-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-scroll-hint {
    display: none;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    margin-bottom: 8px;
    padding: 6px 10px;
    background: rgba(99, 102, 241, 0.08);
    border-radius: 8px;
}

/* 移动端卡片列表（表格替代） */
.mobile-list {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.mobile-card {
    background: var(--bg-card, rgba(30, 41, 59, 0.85));
    border: 1px solid var(--border-glass, rgba(255, 255, 255, 0.08));
    border-radius: 16px;
    padding: 14px;
    backdrop-filter: blur(12px);
}

.mobile-card-head {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.mobile-card-head img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 12px;
    flex-shrink: 0;
}

.mobile-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    word-break: break-word;
}

.mobile-card-sub {
    font-size: 12px;
    color: var(--text-muted, #64748b);
    margin-top: 4px;
}

.mobile-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.mobile-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.mobile-row:last-child {
    border-bottom: none;
}

.mobile-row span:first-child {
    color: var(--text-secondary, #94a3b8);
    flex-shrink: 0;
}

.mobile-row span:last-child {
    color: var(--text-primary, #f1f5f9);
    text-align: right;
    word-break: break-all;
}

.mobile-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.mobile-card-actions button {
    flex: 1;
    min-width: calc(50% - 4px);
    padding: 10px 12px !important;
    border-radius: 10px !important;
    font-size: 13px !important;
    width: auto !important;
    height: auto !important;
}

/* 灯光 3D 布局 */
.ha-3d-container {
    min-height: 0;
}

@media screen and (max-width: 992px)
{
    .container {
        margin: 16px auto !important;
        padding: 0 12px !important;
    }

    .header {
        padding: 20px 14px !important;
    }

    .header h1 {
        font-size: 22px !important;
        margin-bottom: 16px !important;
    }

    .main-toggle {
        width: 100%;
    }

    .main-toggle .toggle-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 12px !important;
        font-size: 13px !important;
    }

    .toggle-label {
        display: inline;
    }

    #userInfo {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
    }

    #welcomeText {
        margin-right: 0 !important;
        font-size: 13px;
    }

    .tabs {
        width: 100% !important;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    .tab {
        flex: 0 0 auto !important;
        min-width: auto !important;
        white-space: nowrap;
        padding: 10px 16px !important;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }

    .toolbar > div:last-child {
        text-align: center;
        padding-top: 4px;
    }

    .toolbar-left select,
    .toolbar-left .search-input {
        width: 100% !important;
        min-width: 0 !important;
    }

    .search-container {
        width: 100% !important;
        flex-wrap: wrap;
    }

    .search-container .search-input {
        flex: 1 1 100%;
        min-width: 0;
    }

    .toolbar button {
        margin-left: 0 !important;
        width: 100%;
    }

    .ha-3d-container {
        flex-direction: column !important;
        height: auto !important;
        min-height: calc(100vh - 220px);
        max-height: none;
    }

    .ha-sidebar {
        width: 100% !important;
        max-height: 38vh;
        min-height: 120px;
    }

    .ha-main-view,
    .ha-canvas-container {
        min-height: 45vh;
        height: 50vh !important;
    }

    .sync-status {
        left: 12px !important;
        right: 12px;
        bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .view-controls {
        flex-wrap: wrap;
        justify-content: center;
        max-width: calc(100% - 24px);
    }

    .modal {
        max-width: calc(100vw - 24px) !important;
        margin: 12px;
        padding: 20px 16px !important;
        max-height: calc(100vh - 48px);
        overflow-y: auto;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-overlay.show .modal {
        border-radius: 20px 20px 0 0;
        width: 100%;
        max-width: 100% !important;
    }

    .upload-area {
        padding: 32px 16px !important;
    }

    .pagination {
        flex-wrap: wrap;
        margin-top: 24px;
        padding-bottom: 24px;
        gap: 6px;
    }

    .page-btn {
        min-width: 40px;
        padding: 10px 12px;
    }

    /* 窄屏：表格横向滚动 + 卡片列表 */
    .table-scroll-hint {
        display: block;
    }

    .mobile-list {
        display: flex;
    }

    .table-container {
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 680px !important;
    }

    th, td {
        white-space: nowrap;
    }

    td[style*="word-break"] {
        white-space: normal !important;
        max-width: 140px;
    }
}

@media screen and (max-width: 480px)
{
    .stat-card {
        flex: 1 1 calc(50% - 6px);
        min-width: calc(50% - 6px) !important;
    }

    .stats {
        gap: 8px !important;
    }

    .card img {
        height: 160px !important;
    }

    .mobile-card-actions button {
        min-width: 100%;
    }
}

/* ---------- 登录页 ---------- */
@media screen and (max-width: 520px)
{
    html, body.login-page {
        overflow-x: hidden;
        overflow-y: auto !important;
        height: auto !important;
        min-height: 100vh;
        min-height: 100dvh;
    }

    #morph-container.form {
        top: max(12px, env(safe-area-inset-top, 0px)) !important;
        transform: translateX(-50%) !important;
        width: calc(100vw - 24px) !important;
        max-width: 440px;
        height: auto !important;
        max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    body.login-page .login-box {
        overflow: visible !important;
        height: auto !important;
    }

    body.login-page .login-box .actions-row {
        flex-direction: column;
    }

    body.login-page .login-box .btn-secondary {
        width: 100%;
        min-height: 44px;
    }

    #hint {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        font-size: 12px;
        width: 90%;
        text-align: center;
    }
}

/* ---------- 个人中心 / 扫码 / 申请 ---------- */
@media screen and (max-width: 480px)
{
    .uc-container,
    .qrcode-container,
    .apply-container {
        padding: 24px 16px !important;
        margin: 12px;
        border-radius: 16px !important;
    }
}

/* ---------- VR 灯光页 ---------- */
@media screen and (max-width: 768px)
{
    .vr-drawer,
    #drawer {
        max-height: 55vh;
    }
}

/* ---------- 灯光坐标编辑页 ---------- */
@media screen and (max-width: 992px)
{
    #layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: 48px minmax(50vh, 1fr) auto !important;
        height: 100vh;
        height: 100dvh;
    }

    #sidebar {
        max-height: 42vh;
        border-left: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
    }

    #controls-panel {
        width: min(220px, calc(100vw - 24px));
        max-height: 40vh;
    }

    header {
        flex-wrap: wrap;
        min-height: 48px;
        height: auto !important;
        padding: 8px !important;
    }

    header h1 {
        font-size: 12px !important;
        flex: 1 1 100%;
    }
}

/* ---------- 工信部 ICP 备案（全站页脚） ---------- */
.site-beian-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    text-align: center;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
    font-size: 12px;
    line-height: 1.5;
    color: rgba(148, 163, 184, 0.85);
    background: transparent;
    pointer-events: auto;
}

.site-beian-footer a {
    color: inherit;
    text-decoration: none;
}

.site-beian-footer a:hover {
    color: rgba(203, 213, 225, 0.95);
    text-decoration: underline;
}

body.login-page #hint {
    bottom: 88px;
}
