/* Mobile-first refinements shared by the setup and management screens. */
html {
    -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.btn,
.nav-tab,
.folder-tab,
.page-btn,
.copy-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 1180px) {
    .main-container {
        width: 94%;
        padding-inline: 20px;
    }

    .grid-4,
    .feature-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden !important;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .river-bg {
        opacity: 0.28;
    }

    .navbar {
        position: sticky;
        top: 0;
    }

    .nav-container {
        width: 100%;
        height: auto;
        min-height: 0;
        padding: 10px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
        display: block;
    }

    .nav-brand {
        display: flex;
        align-items: center;
        min-width: 0;
        padding: 0 4px 8px;
        font-size: 1.05rem;
        line-height: 1.25;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-tabs {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: minmax(0, 1fr);
        width: 100%;
        gap: 6px;
        overflow: visible;
        scrollbar-width: none;
        padding: 2px 2px 4px;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tab {
        min-width: 0;
        min-height: 42px;
        padding: 9px 3px;
        overflow: hidden;
        font-size: 0.82rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .theme-toggle {
        flex: 0 0 42px;
        width: 42px;
        height: 42px;
        padding: 0;
        margin-left: 0;
    }

    .main-container {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin: 0;
        padding: 14px max(12px, env(safe-area-inset-right)) 32px max(12px, env(safe-area-inset-left));
    }

    .page,
    .page > div,
    .glass-card,
    .table-container {
        max-width: 100%;
        min-width: 0;
    }

    img,
    iframe,
    video {
        max-width: 100%;
    }

    pre,
    code,
    .email-detail-body,
    #emailDetailBody {
        max-width: 100%;
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #emailDetailBody {
        overflow-x: hidden !important;
    }

    .email-detail-body pre {
        overflow-x: hidden;
        white-space: pre-wrap;
        word-break: break-word;
    }

    .email-detail-body table,
    .data-table {
        width: 100%;
        max-width: 100%;
        table-layout: fixed;
    }

    .data-table th,
    .data-table td,
    .email-detail-body th,
    .email-detail-body td {
        padding: 8px 6px;
        font-size: 0.78rem;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .glass-card {
        margin-bottom: 14px;
        padding: 16px;
        border-radius: 16px;
    }

    .glass-card:hover,
    .feature-card:hover,
    .nav-tab:hover,
    .btn:hover {
        transform: none;
    }

    #dashboardPage > .glass-card:first-child {
        padding: 24px 16px !important;
        text-align: left !important;
    }

    #dashboardPage > .glass-card:first-child h1 {
        font-size: clamp(1.65rem, 8vw, 2.15rem) !important;
        line-height: 1.2;
    }

    #dashboardPage > .glass-card:first-child p {
        font-size: 0.98rem !important;
        line-height: 1.65;
    }

    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .grid-4 .glass-card {
        padding: 18px 10px;
    }

    .stat-number {
        font-size: clamp(2rem, 10vw, 2.6rem);
    }

    .feature-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-top: 20px;
    }

    .feature-card {
        padding: 16px;
    }

    .guide-steps li {
        align-items: flex-start;
        line-height: 1.6;
    }

    .step-number {
        flex: 0 0 28px;
        margin-top: 1px;
    }

    .toolbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 14px;
    }

    .toolbar .btn {
        width: 100%;
        min-height: 44px;
        padding: 10px 8px;
        font-size: 0.82rem;
        line-height: 1.2;
    }

    .toolbar input[type="text"] {
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0 !important;
        min-height: 46px;
        margin-left: 0 !important;
        order: -1;
    }

    .table-container {
        overflow: visible;
        padding: 0 !important;
        background: transparent;
        border: 0;
        box-shadow: none;
        backdrop-filter: none;
    }

    #accountsTable,
    #accountsTable tbody,
    #accountsTable tr,
    #accountsTable td {
        display: block;
        width: 100% !important;
    }

    #accountsTable {
        border-spacing: 0;
        table-layout: auto;
    }

    #accountsTable thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
    }

    #accountsTable tbody tr {
        width: 100%;
        max-width: 100%;
        margin-bottom: 12px;
        padding: 8px 14px 12px;
        overflow: hidden;
        border: 1px solid var(--glass-border);
        border-radius: 16px;
        background: var(--glass-bg);
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
        backdrop-filter: blur(12px);
    }

    #accountsTable td {
        display: grid;
        position: relative;
        grid-template-columns: 5.6rem minmax(0, 1fr);
        align-items: start;
        gap: 10px;
        min-height: 42px;
        padding: 10px 0;
        border-bottom: 1px solid var(--border-color);
        background: transparent;
        font-size: 0.88rem;
        text-align: left;
        overflow: hidden;
    }

    #accountsTable td::before {
        position: static;
        grid-column: 1;
        width: auto;
        color: var(--text-sub);
        font-size: 0.78rem;
        font-weight: 650;
        text-align: left;
    }

    #accountsTable td > * {
        grid-column: 2;
        min-width: 0;
        max-width: 100%;
    }

    #accountsTable td:nth-child(1)::before { content: "选择"; }
    #accountsTable td:nth-child(2)::before { content: "序号"; }
    #accountsTable td:nth-child(3)::before { content: "邮箱地址"; }
    #accountsTable td:nth-child(4)::before { content: "密码"; }
    #accountsTable td:nth-child(5)::before { content: "刷新令牌"; }
    #accountsTable td:nth-child(6)::before { content: "验证状态"; }
    #accountsTable td:nth-child(7)::before { content: "操作"; }

    #accountsTable td:last-child {
        padding-bottom: 2px;
        border-bottom: 0;
    }

    #accountsTable td:nth-child(3),
    #accountsTable td:nth-child(4),
    #accountsTable td:nth-child(5),
    #accountsTable td:nth-child(7) {
        grid-template-columns: minmax(0, 1fr);
        gap: 7px;
    }

    #accountsTable td:nth-child(3)::before,
    #accountsTable td:nth-child(4)::before,
    #accountsTable td:nth-child(5)::before,
    #accountsTable td:nth-child(7)::before,
    #accountsTable td:nth-child(3) > *,
    #accountsTable td:nth-child(4) > *,
    #accountsTable td:nth-child(5) > *,
    #accountsTable td:nth-child(7) > * {
        grid-column: 1;
    }

    #accountsTable .cell-field {
        width: 100%;
        max-width: 100%;
        justify-content: flex-start;
        min-width: 0;
    }

    #accountsTable .cell-text {
        flex: 1 1 auto;
        width: 0;
        max-width: 100%;
        line-height: 1.5;
        overflow: visible;
        text-align: left;
        text-overflow: clip;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-all;
    }

    #accountsTable .copy-btn {
        min-width: 36px;
        min-height: 36px;
    }

    .action-btns {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        max-width: 100%;
        justify-content: stretch;
        min-width: 0;
    }

    .action-btns .btn-sm {
        width: 100%;
        min-width: 0;
        min-height: 40px;
        padding-inline: 8px;
    }

    .pagination-container {
        justify-content: center;
        padding: 14px 8px;
        border-top: 0;
        font-size: 0.85rem;
    }

    #accountsPagination {
        width: 100%;
        justify-content: center;
        order: -1;
    }

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

    #emailDetailView > .glass-card:first-child {
        display: grid !important;
        grid-template-columns: auto 1fr auto;
        gap: 8px;
        padding: 12px !important;
    }

    #emailViewTitle {
        min-width: 0;
        overflow: hidden;
        font-size: 1rem;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .folder-tabs {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .folder-tab {
        min-height: 44px;
        padding: 9px 12px;
    }

    .email-item {
        padding: 14px 2px;
    }

    .email-item:hover {
        padding-left: 2px;
    }

    #emailDetailContainer {
        inset: 0;
        width: 100%;
        min-width: 0;
        max-width: none;
        height: 100dvh;
    }

    #emailDetailContainer > .glass-card {
        min-height: 100dvh;
        padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
    }

    .email-sidebar-header {
        align-items: flex-start;
        gap: 10px;
    }

    .email-sidebar-header > div {
        min-width: 0;
    }

    .email-sidebar-header > div > div {
        flex-direction: column;
        gap: 3px !important;
    }

    .email-sidebar-close {
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding-top: env(safe-area-inset-top);
    }

    .modal {
        width: 100%;
        max-width: none;
        max-height: min(92dvh, 820px);
        padding: 20px 16px max(20px, env(safe-area-inset-bottom));
        border-radius: 22px 22px 0 0;
    }

    .modal-header {
        align-items: center;
    }

    .modal-close {
        width: 44px;
        height: 44px;
    }

    .modal-tabs {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow: hidden;
    }

    .modal-tab {
        width: 100%;
        min-width: 0;
        min-height: 42px;
    }

    .form-input,
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        min-height: 44px;
        font-size: 16px;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        accent-color: var(--primary);
    }

    .modal-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px !important;
    }

    .modal-actions .btn {
        width: 100%;
        min-height: 44px;
    }

    .modal-actions .btn:nth-child(3) {
        grid-column: 1 / -1;
    }

    textarea.form-input {
        min-height: 140px;
    }

    .upload-zone {
        padding: 28px 14px;
    }

    .notification {
        top: auto;
        right: 12px;
        bottom: max(16px, env(safe-area-inset-bottom));
        left: 12px;
        text-align: center;
    }
}

@media (max-width: 390px) {
    .toolbar {
        grid-template-columns: 1fr;
    }

    .grid-4 {
        gap: 8px;
    }

    .grid-4 .glass-card {
        padding-inline: 6px;
    }

    #accountsTable td {
        grid-template-columns: 4.6rem minmax(0, 1fr);
    }
}

@media (hover: none) {
    .glass-card:hover,
    .feature-card:hover,
    .nav-tab:hover,
    .btn:hover,
    .page-btn:hover:not(:disabled) {
        transform: none;
    }
}
